Skip to content

Commit c0d6d71

Browse files
committed
Add test for argument parsing for CXX targets on UNIX
Signed-off-by: Vincent Fazio <[email protected]>
1 parent b8c06ff commit c0d6d71

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

distutils/compilers/C/tests/test_unix.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,60 @@ def gcvs(*args, _orig=sysconfig.get_config_vars):
244244
sysconfig.customize_compiler(self.cc)
245245
assert self.cc.linker_so[0] == 'my_cc'
246246

247+
@pytest.mark.skipif('platform.system == "Windows"')
248+
def test_cxx_commands_used_are_correct(self):
249+
def gcv(v):
250+
if v == 'LDSHARED':
251+
return 'ccache gcc-4.2 -bundle -undefined dynamic_lookup'
252+
elif v == 'LDCXXSHARED':
253+
return 'ccache g++-4.2 -bundle -undefined dynamic_lookup'
254+
elif v == 'CXX':
255+
return 'ccache g++-4.2'
256+
elif v == 'CC':
257+
return 'ccache gcc-4.2'
258+
return ''
259+
260+
def gcvs(*args, _orig=sysconfig.get_config_vars):
261+
if args:
262+
return list(map(sysconfig.get_config_var, args))
263+
return _orig()
264+
265+
sysconfig.get_config_var = gcv
266+
sysconfig.get_config_vars = gcvs
267+
with (
268+
mock.patch.object(self.cc, 'spawn', return_value=None) as mock_spawn,
269+
mock.patch.object(self.cc, '_need_link', return_value=True),
270+
mock.patch.object(self.cc, 'mkpath', return_value=None),
271+
EnvironmentVarGuard() as env,
272+
):
273+
sysconfig.customize_compiler(self.cc)
274+
assert self.cc.linker_so_cxx[0:2] == ['ccache', 'g++-4.2']
275+
assert self.cc.linker_exe_cxx[0:2] == ['ccache', 'g++-4.2']
276+
self.cc.link(None, [], 'a.out', target_lang='c++')
277+
call_args = mock_spawn.call_args[0][0]
278+
expected = ['ccache', 'g++-4.2', '-bundle', '-undefined', 'dynamic_lookup']
279+
assert call_args[:5] == expected
280+
281+
self.cc.link_executable([], 'a.out', target_lang='c++')
282+
call_args = mock_spawn.call_args[0][0]
283+
expected = ['ccache', 'g++-4.2', '-o', 'a.out']
284+
assert call_args[:4] == expected
285+
286+
env['LDCXXSHARED'] = 'wrapper g++-4.2 -bundle -undefined dynamic_lookup'
287+
env['CXX'] = 'wrapper g++-4.2'
288+
sysconfig.customize_compiler(self.cc)
289+
assert self.cc.linker_so_cxx[0:2] == ['wrapper', 'g++-4.2']
290+
assert self.cc.linker_exe_cxx[0:2] == ['wrapper', 'g++-4.2']
291+
self.cc.link(None, [], 'a.out', target_lang='c++')
292+
call_args = mock_spawn.call_args[0][0]
293+
expected = ['wrapper', 'g++-4.2', '-bundle', '-undefined', 'dynamic_lookup']
294+
assert call_args[:5] == expected
295+
296+
self.cc.link_executable([], 'a.out', target_lang='c++')
297+
call_args = mock_spawn.call_args[0][0]
298+
expected = ['wrapper', 'g++-4.2', '-o', 'a.out']
299+
assert call_args[:4] == expected
300+
247301
@pytest.mark.skipif('platform.system == "Windows"')
248302
@pytest.mark.usefixtures('disable_macos_customization')
249303
def test_cc_overrides_ldshared_for_cxx_correctly(self):

0 commit comments

Comments
 (0)