ยปCore Development>Code coverage>Lib/distutils/tests/test_unixccompiler.py

Python code coverage for Lib/distutils/tests/test_unixccompiler.py

#countcontent
1n/a"""Tests for distutils.unixccompiler."""
2n/aimport sys
3n/aimport unittest
4n/afrom test.support import EnvironmentVarGuard, run_unittest
5n/a
6n/afrom distutils import sysconfig
7n/afrom distutils.unixccompiler import UnixCCompiler
8n/a
9n/aclass UnixCCompilerTestCase(unittest.TestCase):
10n/a
11n/a def setUp(self):
12n/a self._backup_platform = sys.platform
13n/a self._backup_get_config_var = sysconfig.get_config_var
14n/a class CompilerWrapper(UnixCCompiler):
15n/a def rpath_foo(self):
16n/a return self.runtime_library_dir_option('/foo')
17n/a self.cc = CompilerWrapper()
18n/a
19n/a def tearDown(self):
20n/a sys.platform = self._backup_platform
21n/a sysconfig.get_config_var = self._backup_get_config_var
22n/a
23n/a @unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
24n/a def test_runtime_libdir_option(self):
25n/a # Issue#5900
26n/a #
27n/a # Ensure RUNPATH is added to extension modules with RPATH if
28n/a # GNU ld is used
29n/a
30n/a # darwin
31n/a sys.platform = 'darwin'
32n/a self.assertEqual(self.cc.rpath_foo(), '-L/foo')
33n/a
34n/a # hp-ux
35n/a sys.platform = 'hp-ux'
36n/a old_gcv = sysconfig.get_config_var
37n/a def gcv(v):
38n/a return 'xxx'
39n/a sysconfig.get_config_var = gcv
40n/a self.assertEqual(self.cc.rpath_foo(), ['+s', '-L/foo'])
41n/a
42n/a def gcv(v):
43n/a return 'gcc'
44n/a sysconfig.get_config_var = gcv
45n/a self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo'])
46n/a
47n/a def gcv(v):
48n/a return 'g++'
49n/a sysconfig.get_config_var = gcv
50n/a self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo'])
51n/a
52n/a sysconfig.get_config_var = old_gcv
53n/a
54n/a # irix646
55n/a sys.platform = 'irix646'
56n/a self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo'])
57n/a
58n/a # osf1V5
59n/a sys.platform = 'osf1V5'
60n/a self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo'])
61n/a
62n/a # GCC GNULD
63n/a sys.platform = 'bar'
64n/a def gcv(v):
65n/a if v == 'CC':
66n/a return 'gcc'
67n/a elif v == 'GNULD':
68n/a return 'yes'
69n/a sysconfig.get_config_var = gcv
70n/a self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
71n/a
72n/a # GCC non-GNULD
73n/a sys.platform = 'bar'
74n/a def gcv(v):
75n/a if v == 'CC':
76n/a return 'gcc'
77n/a elif v == 'GNULD':
78n/a return 'no'
79n/a sysconfig.get_config_var = gcv
80n/a self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
81n/a
82n/a # GCC GNULD with fully qualified configuration prefix
83n/a # see #7617
84n/a sys.platform = 'bar'
85n/a def gcv(v):
86n/a if v == 'CC':
87n/a return 'x86_64-pc-linux-gnu-gcc-4.4.2'
88n/a elif v == 'GNULD':
89n/a return 'yes'
90n/a sysconfig.get_config_var = gcv
91n/a self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
92n/a
93n/a # non-GCC GNULD
94n/a sys.platform = 'bar'
95n/a def gcv(v):
96n/a if v == 'CC':
97n/a return 'cc'
98n/a elif v == 'GNULD':
99n/a return 'yes'
100n/a sysconfig.get_config_var = gcv
101n/a self.assertEqual(self.cc.rpath_foo(), '-R/foo')
102n/a
103n/a # non-GCC non-GNULD
104n/a sys.platform = 'bar'
105n/a def gcv(v):
106n/a if v == 'CC':
107n/a return 'cc'
108n/a elif v == 'GNULD':
109n/a return 'no'
110n/a sysconfig.get_config_var = gcv
111n/a self.assertEqual(self.cc.rpath_foo(), '-R/foo')
112n/a
113n/a @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
114n/a def test_osx_cc_overrides_ldshared(self):
115n/a # Issue #18080:
116n/a # ensure that setting CC env variable also changes default linker
117n/a def gcv(v):
118n/a if v == 'LDSHARED':
119n/a return 'gcc-4.2 -bundle -undefined dynamic_lookup '
120n/a return 'gcc-4.2'
121n/a sysconfig.get_config_var = gcv
122n/a with EnvironmentVarGuard() as env:
123n/a env['CC'] = 'my_cc'
124n/a del env['LDSHARED']
125n/a sysconfig.customize_compiler(self.cc)
126n/a self.assertEqual(self.cc.linker_so[0], 'my_cc')
127n/a
128n/a @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
129n/a def test_osx_explicit_ldshared(self):
130n/a # Issue #18080:
131n/a # ensure that setting CC env variable does not change
132n/a # explicit LDSHARED setting for linker
133n/a def gcv(v):
134n/a if v == 'LDSHARED':
135n/a return 'gcc-4.2 -bundle -undefined dynamic_lookup '
136n/a return 'gcc-4.2'
137n/a sysconfig.get_config_var = gcv
138n/a with EnvironmentVarGuard() as env:
139n/a env['CC'] = 'my_cc'
140n/a env['LDSHARED'] = 'my_ld -bundle -dynamic'
141n/a sysconfig.customize_compiler(self.cc)
142n/a self.assertEqual(self.cc.linker_so[0], 'my_ld')
143n/a
144n/a
145n/adef test_suite():
146n/a return unittest.makeSuite(UnixCCompilerTestCase)
147n/a
148n/aif __name__ == "__main__":
149n/a run_unittest(test_suite())