11"""Tests for distutils.unixccompiler."""
2+ import os
23import sys
34import unittest
4- from test .support import run_unittest
5+ from test .support import EnvironmentVarGuard , run_unittest
56
67from distutils import sysconfig
78from distutils .unixccompiler import UnixCCompiler
@@ -94,7 +95,6 @@ def gcv(v):
9495 sysconfig .get_config_var = gcv
9596 self .assertEqual (self .cc .rpath_foo (), '-Wl,--enable-new-dtags,-R/foo' )
9697
97-
9898 # non-GCC GNULD
9999 sys .platform = 'bar'
100100 def gcv (v ):
@@ -115,6 +115,38 @@ def gcv(v):
115115 sysconfig .get_config_var = gcv
116116 self .assertEqual (self .cc .rpath_foo (), '-R/foo' )
117117
118+ @unittest .skipUnless (sys .platform == 'darwin' , 'test only relevant for OS X' )
119+ def test_osx_cc_overrides_ldshared (self ):
120+ # Issue #18080:
121+ # ensure that setting CC env variable also changes default linker
122+ def gcv (v ):
123+ if v == 'LDSHARED' :
124+ return 'gcc-4.2 -bundle -undefined dynamic_lookup '
125+ return 'gcc-4.2'
126+ sysconfig .get_config_var = gcv
127+ with EnvironmentVarGuard () as env :
128+ env ['CC' ] = 'my_cc'
129+ del env ['LDSHARED' ]
130+ sysconfig .customize_compiler (self .cc )
131+ self .assertEqual (self .cc .linker_so [0 ], 'my_cc' )
132+
133+ @unittest .skipUnless (sys .platform == 'darwin' , 'test only relevant for OS X' )
134+ def test_osx_explict_ldshared (self ):
135+ # Issue #18080:
136+ # ensure that setting CC env variable does not change
137+ # explicit LDSHARED setting for linker
138+ def gcv (v ):
139+ if v == 'LDSHARED' :
140+ return 'gcc-4.2 -bundle -undefined dynamic_lookup '
141+ return 'gcc-4.2'
142+ sysconfig .get_config_var = gcv
143+ with EnvironmentVarGuard () as env :
144+ env ['CC' ] = 'my_cc'
145+ env ['LDSHARED' ] = 'my_ld -bundle -dynamic'
146+ sysconfig .customize_compiler (self .cc )
147+ self .assertEqual (self .cc .linker_so [0 ], 'my_ld' )
148+
149+
118150def test_suite ():
119151 return unittest .makeSuite (UnixCCompilerTestCase )
120152
0 commit comments