1 """Tests for distutils.ccompiler."""
4 from test.test_support import captured_stdout
6 from distutils.ccompiler import (gen_lib_options, CCompiler,
7 get_default_compiler, customize_compiler)
8 from distutils import debug
9 from distutils.tests import support
11 class FakeCompiler(object):
12 def library_dir_option(self, dir):
15 def runtime_library_dir_option(self, dir):
16 return ["-cool", "-R" + dir]
18 def find_library_file(self, dirs, lib, debug=0):
21 def library_option(self, lib):
24 class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
26 def test_gen_lib_options(self):
27 compiler = FakeCompiler()
28 libdirs = ['lib1', 'lib2']
29 runlibdirs = ['runlib1']
30 libs = [os.path.join('dir', 'name'), 'name2']
32 opts = gen_lib_options(compiler, libdirs, runlibdirs, libs)
33 wanted = ['-Llib1', '-Llib2', '-cool', '-Rrunlib1', 'found',
35 self.assertEqual(opts, wanted)
37 def test_debug_print(self):
39 class MyCCompiler(CCompiler):
42 compiler = MyCCompiler()
43 with captured_stdout() as stdout:
44 compiler.debug_print('xxx')
46 self.assertEqual(stdout.read(), '')
50 with captured_stdout() as stdout:
51 compiler.debug_print('xxx')
53 self.assertEqual(stdout.read(), 'xxx\n')
57 def test_customize_compiler(self):
59 # not testing if default compiler is not unix
60 if get_default_compiler() != 'unix':
63 os.environ['AR'] = 'my_ar'
64 os.environ['ARFLAGS'] = '-arflags'
66 # make sure AR gets caught
68 compiler_type = 'unix'
70 def set_executables(self, **kw):
74 customize_compiler(comp)
75 self.assertEqual(comp.exes['archiver'], 'my_ar -arflags')
78 return unittest.makeSuite(CCompilerTestCase)
80 if __name__ == "__main__":
81 unittest.main(defaultTest="test_suite")