+++ /dev/null
-"""Tests for distutils.ccompiler."""\r
-import os\r
-import unittest\r
-from test.test_support import captured_stdout\r
-\r
-from distutils.ccompiler import (gen_lib_options, CCompiler,\r
- get_default_compiler, customize_compiler)\r
-from distutils import debug\r
-from distutils.tests import support\r
-\r
-class FakeCompiler(object):\r
- def library_dir_option(self, dir):\r
- return "-L" + dir\r
-\r
- def runtime_library_dir_option(self, dir):\r
- return ["-cool", "-R" + dir]\r
-\r
- def find_library_file(self, dirs, lib, debug=0):\r
- return 'found'\r
-\r
- def library_option(self, lib):\r
- return "-l" + lib\r
-\r
-class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):\r
-\r
- def test_gen_lib_options(self):\r
- compiler = FakeCompiler()\r
- libdirs = ['lib1', 'lib2']\r
- runlibdirs = ['runlib1']\r
- libs = [os.path.join('dir', 'name'), 'name2']\r
-\r
- opts = gen_lib_options(compiler, libdirs, runlibdirs, libs)\r
- wanted = ['-Llib1', '-Llib2', '-cool', '-Rrunlib1', 'found',\r
- '-lname2']\r
- self.assertEqual(opts, wanted)\r
-\r
- def test_debug_print(self):\r
-\r
- class MyCCompiler(CCompiler):\r
- executables = {}\r
-\r
- compiler = MyCCompiler()\r
- with captured_stdout() as stdout:\r
- compiler.debug_print('xxx')\r
- stdout.seek(0)\r
- self.assertEqual(stdout.read(), '')\r
-\r
- debug.DEBUG = True\r
- try:\r
- with captured_stdout() as stdout:\r
- compiler.debug_print('xxx')\r
- stdout.seek(0)\r
- self.assertEqual(stdout.read(), 'xxx\n')\r
- finally:\r
- debug.DEBUG = False\r
-\r
- def test_customize_compiler(self):\r
-\r
- # not testing if default compiler is not unix\r
- if get_default_compiler() != 'unix':\r
- return\r
-\r
- os.environ['AR'] = 'my_ar'\r
- os.environ['ARFLAGS'] = '-arflags'\r
-\r
- # make sure AR gets caught\r
- class compiler:\r
- compiler_type = 'unix'\r
-\r
- def set_executables(self, **kw):\r
- self.exes = kw\r
-\r
- comp = compiler()\r
- customize_compiler(comp)\r
- self.assertEqual(comp.exes['archiver'], 'my_ar -arflags')\r
-\r
-def test_suite():\r
- return unittest.makeSuite(CCompilerTestCase)\r
-\r
-if __name__ == "__main__":\r
- unittest.main(defaultTest="test_suite")\r