Add better error reporting for MemoryErrors caused by str->float conversions.
[python.git] / Lib / distutils / tests / test_unixccompiler.py
blob008ae5d03a0331ee4baf8972bc8d39e7dec1f56d
1 """Tests for distutils.unixccompiler."""
2 import sys
3 import unittest
5 from distutils import sysconfig
6 from distutils.unixccompiler import UnixCCompiler
8 class UnixCCompilerTestCase(unittest.TestCase):
10 def setUp(self):
11 self._backup_platform = sys.platform
12 self._backup_get_config_var = sysconfig.get_config_var
13 class CompilerWrapper(UnixCCompiler):
14 def rpath_foo(self):
15 return self.runtime_library_dir_option('/foo')
16 self.cc = CompilerWrapper()
18 def tearDown(self):
19 sys.platform = self._backup_platform
20 sysconfig.get_config_var = self._backup_get_config_var
22 def test_runtime_libdir_option(self):
24 # not tested under windows
25 if sys.platform == 'win32':
26 return
28 # Issue#5900
30 # Ensure RUNPATH is added to extension modules with RPATH if
31 # GNU ld is used
33 # darwin
34 sys.platform = 'darwin'
35 self.assertEqual(self.cc.rpath_foo(), '-L/foo')
37 # hp-ux
38 sys.platform = 'hp-ux'
39 old_gcv = sysconfig.get_config_var
40 def gcv(v):
41 return 'xxx'
42 sysconfig.get_config_var = gcv
43 self.assertEqual(self.cc.rpath_foo(), ['+s', '-L/foo'])
45 def gcv(v):
46 return 'gcc'
47 sysconfig.get_config_var = gcv
48 self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo'])
50 def gcv(v):
51 return 'g++'
52 sysconfig.get_config_var = gcv
53 self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo'])
55 sysconfig.get_config_var = old_gcv
57 # irix646
58 sys.platform = 'irix646'
59 self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo'])
61 # osf1V5
62 sys.platform = 'osf1V5'
63 self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo'])
65 # GCC GNULD
66 sys.platform = 'bar'
67 def gcv(v):
68 if v == 'CC':
69 return 'gcc'
70 elif v == 'GNULD':
71 return 'yes'
72 sysconfig.get_config_var = gcv
73 self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
75 # GCC non-GNULD
76 sys.platform = 'bar'
77 def gcv(v):
78 if v == 'CC':
79 return 'gcc'
80 elif v == 'GNULD':
81 return 'no'
82 sysconfig.get_config_var = gcv
83 self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
85 # GCC GNULD with fully qualified configuration prefix
86 # see #7617
87 sys.platform = 'bar'
88 def gcv(v):
89 if v == 'CC':
90 return 'x86_64-pc-linux-gnu-gcc-4.4.2'
91 elif v == 'GNULD':
92 return 'yes'
93 sysconfig.get_config_var = gcv
94 self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
97 # non-GCC GNULD
98 sys.platform = 'bar'
99 def gcv(v):
100 if v == 'CC':
101 return 'cc'
102 elif v == 'GNULD':
103 return 'yes'
104 sysconfig.get_config_var = gcv
105 self.assertEqual(self.cc.rpath_foo(), '-R/foo')
107 # non-GCC non-GNULD
108 sys.platform = 'bar'
109 def gcv(v):
110 if v == 'CC':
111 return 'cc'
112 elif v == 'GNULD':
113 return 'no'
114 sysconfig.get_config_var = gcv
115 self.assertEqual(self.cc.rpath_foo(), '-R/foo')
117 # AIX C/C++ linker
118 sys.platform = 'aix'
119 def gcv(v):
120 return 'xxx'
121 sysconfig.get_config_var = gcv
122 self.assertEqual(self.cc.rpath_foo(), '-blibpath:/foo')
125 def test_suite():
126 return unittest.makeSuite(UnixCCompilerTestCase)
128 if __name__ == "__main__":
129 unittest.main(defaultTest="test_suite")