diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2022-05-09 10:42:04 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2022-05-09 10:42:56 -0400 |
commit | 9116c7eb52504bec77d26881d2c28e427dc52143 (patch) | |
tree | 6becb88401eb15bdff6fc924211894e6d9c277d1 /setuptools/_distutils/tests/test_unixccompiler.py | |
parent | 8d12d6196c369c7cf0164a1202e968dd68a2cb6c (diff) | |
parent | e009a87b5578cb16099b697ba8395c8f6bdd70f3 (diff) | |
download | python-setuptools-git-debt/remove-easy-install.tar.gz |
Merge branch 'main' into debt/remove-easy-installdebt/remove-easy-install
Diffstat (limited to 'setuptools/_distutils/tests/test_unixccompiler.py')
-rw-r--r-- | setuptools/_distutils/tests/test_unixccompiler.py | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/setuptools/_distutils/tests/test_unixccompiler.py b/setuptools/_distutils/tests/test_unixccompiler.py index 63c7dd37..c8b4c149 100644 --- a/setuptools/_distutils/tests/test_unixccompiler.py +++ b/setuptools/_distutils/tests/test_unixccompiler.py @@ -3,6 +3,7 @@ import os import sys import unittest from test.support import run_unittest +from unittest.mock import patch from .py38compat import EnvironmentVarGuard @@ -11,9 +12,12 @@ from distutils.errors import DistutilsPlatformError from distutils.unixccompiler import UnixCCompiler from distutils.util import _clear_cached_macosx_ver -class UnixCCompilerTestCase(unittest.TestCase): +from . import support + +class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase): def setUp(self): + super().setUp() self._backup_platform = sys.platform self._backup_get_config_var = sysconfig.get_config_var self._backup_get_config_vars = sysconfig.get_config_vars @@ -23,6 +27,7 @@ class UnixCCompilerTestCase(unittest.TestCase): self.cc = CompilerWrapper() def tearDown(self): + super().tearDown() sys.platform = self._backup_platform sysconfig.get_config_var = self._backup_get_config_var sysconfig.get_config_vars = self._backup_get_config_vars @@ -211,6 +216,42 @@ class UnixCCompilerTestCase(unittest.TestCase): self.assertEqual(self.cc.linker_so[0], 'my_cc') @unittest.skipIf(sys.platform == 'win32', "can't test on Windows") + def test_cc_overrides_ldshared_for_cxx_correctly(self): + """ + Ensure that setting CC env variable also changes default linker + correctly when building C++ extensions. + + pypa/distutils#126 + """ + def gcv(v): + if v == 'LDSHARED': + return 'gcc-4.2 -bundle -undefined dynamic_lookup ' + elif v == 'CXX': + return 'g++-4.2' + return 'gcc-4.2' + + def gcvs(*args, _orig=sysconfig.get_config_vars): + if args: + return list(map(sysconfig.get_config_var, args)) + return _orig() + + sysconfig.get_config_var = gcv + sysconfig.get_config_vars = gcvs + with patch.object(self.cc, 'spawn', return_value=None) as mock_spawn, \ + patch.object(self.cc, '_need_link', return_value=True), \ + patch.object(self.cc, 'mkpath', return_value=None), \ + EnvironmentVarGuard() as env: + env['CC'] = 'ccache my_cc' + env['CXX'] = 'my_cxx' + del env['LDSHARED'] + sysconfig.customize_compiler(self.cc) + self.assertEqual(self.cc.linker_so[0:2], ['ccache', 'my_cc']) + self.cc.link(None, [], 'a.out', target_lang='c++') + call_args = mock_spawn.call_args[0][0] + expected = ['my_cxx', '-bundle', '-undefined', 'dynamic_lookup'] + assert call_args[:4] == expected + + @unittest.skipIf(sys.platform == 'win32', "can't test on Windows") def test_explicit_ldshared(self): # Issue #18080: # ensure that setting CC env variable does not change @@ -237,11 +278,12 @@ class UnixCCompilerTestCase(unittest.TestCase): # ensure that setting output_dir does not raise # FileNotFoundError: [Errno 2] No such file or directory: 'a.out' self.cc.output_dir = 'scratch' + os.chdir(self.mkdtemp()) self.cc.has_function('abort', includes=['stdlib.h']) def test_suite(): - return unittest.makeSuite(UnixCCompilerTestCase) + return unittest.TestLoader().loadTestsFromTestCase(UnixCCompilerTestCase) if __name__ == "__main__": run_unittest(test_suite()) |