source: python/trunk/Lib/distutils/tests/test_unixccompiler.py

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

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