diff options
Diffstat (limited to 'test')
49 files changed, 1458 insertions, 587 deletions
diff --git a/test/CPPDEFINES/append.py b/test/CPPDEFINES/append.py index 874fceb7d..32917abcb 100644 --- a/test/CPPDEFINES/append.py +++ b/test/CPPDEFINES/append.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify appending to CPPPDEFINES with various data types. @@ -33,203 +32,315 @@ import TestSCons test = TestSCons.TestSCons() -# Note: we explicitly set CPPDEFPREFIX here to simplify testing on -# Windows. - -test.write('SConstruct', """\ -env_1738_2 = Environment(CPPDEFPREFIX='-D') -env_1738_2['CPPDEFINES'] = ['FOO'] -env_1738_2.Append(CPPDEFINES={'value' : '1'}) -print(env_1738_2.subst('$_CPPDEFFLAGS')) -#env_1738_2.Object('test_1738_2', 'main.c') - -# https://github.com/SCons/scons/issues/2300 -env_2300_1 = Environment(CPPDEFINES = 'foo', CPPDEFPREFIX='-D') -env_2300_1.Append(CPPDEFINES='bar') -print(env_2300_1.subst('$_CPPDEFFLAGS')) - -env_2300_2 = Environment(CPPDEFINES = ['foo'], CPPDEFPREFIX='-D') # note the list -env_2300_2.Append(CPPDEFINES='bar') -print(env_2300_2.subst('$_CPPDEFFLAGS')) - -# https://github.com/SCons/scons/issues/1152 -# https://github.com/SCons/scons/issues/2900 -# Python3 dicts dont preserve order. Hence we supply subclass of OrderedDict -# whose __str__ and __repr__ act like a normal dict. -from collections import OrderedDict -class OrderedPrintingDict(OrderedDict): - def __repr__(self): - return '{' + ', '.join(['%r: %r'%(k, v) for (k, v) in self.items()]) + '}' - - __str__ = __repr__ - - # Because dict-like objects (except dict and UserDict) are not deep copied - # directly when constructing Environment(CPPDEFINES = OrderedPrintingDict(...)) - def __semi_deepcopy__(self): - return self.copy() - -cases=[('string', 'FOO'), - ('list', ['NAME1', 'NAME2']), - ('list-of-2lists', [('NAME1','VAL1'), ['NAME2','VAL2']]), - ('dict', OrderedPrintingDict([('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')])) - ] - -for (t1, c1) in cases: - for (t2, c2) in cases: - print("==== Testing CPPDEFINES, appending a %s to a %s"%(t2, t1)) - print(" orig = %s, append = %s"%(c1, c2)) - env=Environment(CPPDEFINES = c1, CPPDEFPREFIX='-D') - env.Append(CPPDEFINES = c2) - final=env.subst('$_CPPDEFFLAGS',source="src", target="tgt") - print('Append:\\n\\tresult=%s\\n\\tfinal=%s'%\\ - (env['CPPDEFINES'], final)) - env=Environment(CPPDEFINES = c1, CPPDEFPREFIX='-D') - env.AppendUnique(CPPDEFINES = c2) - final=env.subst('$_CPPDEFFLAGS',source="src", target="tgt") - print('AppendUnique:\\n\\tresult=%s\\n\\tfinal=%s'%\\ - (env['CPPDEFINES'], final)) -""") +# Note: explicitly set CPPDEFPREFIX here to simplify testing on Windows. +# Link: fixture/SConstruct-Append +test.file_fixture(["fixture", "SConstruct-Append"], "SConstruct") expect_print_output="""\ -DFOO -Dvalue=1 -Dfoo -Dbar -Dfoo -Dbar +-Dfoo -Dbar -Dbaz +-Dfoo bar -Dbaz +-Dfoo -Dbar baz +-Dfoo -Dbar -Dbaz +-DMacro2=Value2 -DMacro4 -DMacro3=Value3 -DMacro1=Value1 +-DMacro1=Value1 +-DMacro1 -DValue1 ==== Testing CPPDEFINES, appending a string to a string - orig = FOO, append = FOO + orig = 'FOO', append = 'FOO' +Append: + result=['FOO', 'FOO'] + final=-DFOO -DFOO +AppendUnique: + result=['FOO'] + final=-DFOO +==== Testing CPPDEFINES, appending a valuestring to a string + orig = 'FOO', append = 'NAME1=VAL1' Append: - result=['FOO', 'FOO'] - final=-DFOO -DFOO + result=['FOO', 'NAME1=VAL1'] + final=-DFOO -DNAME1=VAL1 AppendUnique: - result=['FOO'] - final=-DFOO + result=['FOO', 'NAME1=VAL1'] + final=-DFOO -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a list to a string - orig = FOO, append = ['NAME1', 'NAME2'] + orig = 'FOO', append = ['NAME1', 'NAME2', 'NAME3'] Append: - result=['FOO', 'NAME1', 'NAME2'] - final=-DFOO -DNAME1 -DNAME2 + result=['FOO', 'NAME1', 'NAME2', 'NAME3'] + final=-DFOO -DNAME1 -DNAME2 -DNAME3 AppendUnique: - result=[('FOO',), ('NAME1',), ('NAME2',)] - final=-DFOO -DNAME1 -DNAME2 + result=['FOO', 'NAME1', 'NAME2', 'NAME3'] + final=-DFOO -DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, appending a tuple to a string + orig = 'FOO', append = ('NAME1', 'VAL1') +Append: + result=['FOO', ('NAME1', 'VAL1')] + final=-DFOO -DNAME1=VAL1 +AppendUnique: + result=['FOO', ('NAME1', 'VAL1')] + final=-DFOO -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a list-of-2lists to a string - orig = FOO, append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + orig = 'FOO', append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] Append: - result=['FOO', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] - final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 + result=['FOO', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 AppendUnique: - result=[('FOO',), ('NAME1', 'VAL1'), ('NAME2', 'VAL2')] - final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 + result=['FOO', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 ==== Testing CPPDEFINES, appending a dict to a string - orig = FOO, append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} + orig = 'FOO', append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Append: + result=['FOO', ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DFOO -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +AppendUnique: + result=['FOO', ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DFOO -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +==== Testing CPPDEFINES, appending a string to a valuestring + orig = 'NAME1=VAL1', append = 'FOO' +Append: + result=['NAME1=VAL1', 'FOO'] + final=-DNAME1=VAL1 -DFOO +AppendUnique: + result=['NAME1=VAL1', 'FOO'] + final=-DNAME1=VAL1 -DFOO +==== Testing CPPDEFINES, appending a valuestring to a valuestring + orig = 'NAME1=VAL1', append = 'NAME1=VAL1' +Append: + result=['NAME1=VAL1', 'NAME1=VAL1'] + final=-DNAME1=VAL1 -DNAME1=VAL1 +AppendUnique: + result=['NAME1=VAL1'] + final=-DNAME1=VAL1 +==== Testing CPPDEFINES, appending a list to a valuestring + orig = 'NAME1=VAL1', append = ['NAME1', 'NAME2', 'NAME3'] +Append: + result=['NAME1=VAL1', 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +AppendUnique: + result=['NAME1=VAL1', 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, appending a tuple to a valuestring + orig = 'NAME1=VAL1', append = ('NAME1', 'VAL1') +Append: + result=['NAME1=VAL1', ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME1=VAL1 +AppendUnique: + result=['NAME1=VAL1'] + final=-DNAME1=VAL1 +==== Testing CPPDEFINES, appending a list-of-2lists to a valuestring + orig = 'NAME1=VAL1', append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Append: + result=['NAME1=VAL1', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME1=VAL1 -DNAME2=VAL2 +AppendUnique: + result=['NAME1=VAL1', ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME2=VAL2 +==== Testing CPPDEFINES, appending a dict to a valuestring + orig = 'NAME1=VAL1', append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} Append: - result=['FOO', {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}] - final=-DFOO -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 + result=['NAME1=VAL1', ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 AppendUnique: - result=['FOO', ('NAME2', 'VAL2'), 'NAME3', ('NAME1', 'VAL1')] - final=-DFOO -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 + result=['NAME1=VAL1', ('NAME2', 'VAL2'), ('NAME3', None)] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 ==== Testing CPPDEFINES, appending a string to a list - orig = ['NAME1', 'NAME2'], append = FOO + orig = ['NAME1', 'NAME2', 'NAME3'], append = 'FOO' +Append: + result=['NAME1', 'NAME2', 'NAME3', 'FOO'] + final=-DNAME1 -DNAME2 -DNAME3 -DFOO +AppendUnique: + result=['NAME1', 'NAME2', 'NAME3', 'FOO'] + final=-DNAME1 -DNAME2 -DNAME3 -DFOO +==== Testing CPPDEFINES, appending a valuestring to a list + orig = ['NAME1', 'NAME2', 'NAME3'], append = 'NAME1=VAL1' Append: - result=['NAME1', 'NAME2', 'FOO'] - final=-DNAME1 -DNAME2 -DFOO + result=['NAME1', 'NAME2', 'NAME3', 'NAME1=VAL1'] + final=-DNAME1 -DNAME2 -DNAME3 -DNAME1=VAL1 AppendUnique: - result=[('NAME1',), ('NAME2',), ('FOO',)] - final=-DNAME1 -DNAME2 -DFOO + result=['NAME1', 'NAME2', 'NAME3', 'NAME1=VAL1'] + final=-DNAME1 -DNAME2 -DNAME3 -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a list to a list - orig = ['NAME1', 'NAME2'], append = ['NAME1', 'NAME2'] + orig = ['NAME1', 'NAME2', 'NAME3'], append = ['NAME1', 'NAME2', 'NAME3'] Append: - result=['NAME1', 'NAME2', 'NAME1', 'NAME2'] - final=-DNAME1 -DNAME2 -DNAME1 -DNAME2 + result=['NAME1', 'NAME2', 'NAME3', 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1 -DNAME2 -DNAME3 -DNAME1 -DNAME2 -DNAME3 AppendUnique: - result=[('NAME1',), ('NAME2',)] - final=-DNAME1 -DNAME2 + result=['NAME1', 'NAME2', 'NAME3'] + final=-DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, appending a tuple to a list + orig = ['NAME1', 'NAME2', 'NAME3'], append = ('NAME1', 'VAL1') +Append: + result=['NAME1', 'NAME2', 'NAME3', ('NAME1', 'VAL1')] + final=-DNAME1 -DNAME2 -DNAME3 -DNAME1=VAL1 +AppendUnique: + result=['NAME1', 'NAME2', 'NAME3', ('NAME1', 'VAL1')] + final=-DNAME1 -DNAME2 -DNAME3 -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a list-of-2lists to a list - orig = ['NAME1', 'NAME2'], append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + orig = ['NAME1', 'NAME2', 'NAME3'], append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] Append: - result=['NAME1', 'NAME2', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] - final=-DNAME1 -DNAME2 -DNAME1=VAL1 -DNAME2=VAL2 + result=['NAME1', 'NAME2', 'NAME3', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1 -DNAME2 -DNAME3 -DNAME1=VAL1 -DNAME2=VAL2 AppendUnique: - result=[('NAME1',), ('NAME2',), ('NAME1', 'VAL1'), ('NAME2', 'VAL2')] - final=-DNAME1 -DNAME2 -DNAME1=VAL1 -DNAME2=VAL2 + result=['NAME1', 'NAME2', 'NAME3', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1 -DNAME2 -DNAME3 -DNAME1=VAL1 -DNAME2=VAL2 ==== Testing CPPDEFINES, appending a dict to a list - orig = ['NAME1', 'NAME2'], append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} + orig = ['NAME1', 'NAME2', 'NAME3'], append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Append: + result=['NAME1', 'NAME2', 'NAME3', ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME1 -DNAME2 -DNAME3 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +AppendUnique: + result=['NAME1', 'NAME2', 'NAME3', ('NAME2', 'VAL2'), ('NAME1', 'VAL1')] + final=-DNAME1 -DNAME2 -DNAME3 -DNAME2=VAL2 -DNAME1=VAL1 +==== Testing CPPDEFINES, appending a string to a tuple + orig = ('NAME1', 'VAL1'), append = 'FOO' +Append: + result=[('NAME1', 'VAL1'), 'FOO'] + final=-DNAME1=VAL1 -DFOO +AppendUnique: + result=[('NAME1', 'VAL1'), 'FOO'] + final=-DNAME1=VAL1 -DFOO +==== Testing CPPDEFINES, appending a valuestring to a tuple + orig = ('NAME1', 'VAL1'), append = 'NAME1=VAL1' +Append: + result=[('NAME1', 'VAL1'), 'NAME1=VAL1'] + final=-DNAME1=VAL1 -DNAME1=VAL1 +AppendUnique: + result=[('NAME1', 'VAL1')] + final=-DNAME1=VAL1 +==== Testing CPPDEFINES, appending a list to a tuple + orig = ('NAME1', 'VAL1'), append = ['NAME1', 'NAME2', 'NAME3'] +Append: + result=[('NAME1', 'VAL1'), 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +AppendUnique: + result=[('NAME1', 'VAL1'), 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, appending a tuple to a tuple + orig = ('NAME1', 'VAL1'), append = ('NAME1', 'VAL1') Append: - result=['NAME1', 'NAME2', {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}] - final=-DNAME1 -DNAME2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 + result=[('NAME1', 'VAL1'), ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME1=VAL1 AppendUnique: - result=[('NAME1',), ('NAME2',), ('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1')] - final=-DNAME1 -DNAME2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 + result=[('NAME1', 'VAL1')] + final=-DNAME1=VAL1 +==== Testing CPPDEFINES, appending a list-of-2lists to a tuple + orig = ('NAME1', 'VAL1'), append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Append: + result=[('NAME1', 'VAL1'), ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME1=VAL1 -DNAME2=VAL2 +AppendUnique: + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME2=VAL2 +==== Testing CPPDEFINES, appending a dict to a tuple + orig = ('NAME1', 'VAL1'), append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Append: + result=[('NAME1', 'VAL1'), ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +AppendUnique: + result=[('NAME1', 'VAL1'), ('NAME2', 'VAL2'), ('NAME3', None)] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 ==== Testing CPPDEFINES, appending a string to a list-of-2lists - orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = FOO + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = 'FOO' Append: - result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], 'FOO'] - final=-DNAME1=VAL1 -DNAME2=VAL2 -DFOO + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], 'FOO'] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DFOO AppendUnique: - result=[('NAME1', 'VAL1'), ('NAME2', 'VAL2'), ('FOO',)] - final=-DNAME1=VAL1 -DNAME2=VAL2 -DFOO + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], 'FOO'] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DFOO +==== Testing CPPDEFINES, appending a valuestring to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = 'NAME1=VAL1' +Append: + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], 'NAME1=VAL1'] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1=VAL1 +AppendUnique: + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME2=VAL2 ==== Testing CPPDEFINES, appending a list to a list-of-2lists - orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = ['NAME1', 'NAME2'] + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = ['NAME1', 'NAME2', 'NAME3'] Append: - result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], 'NAME1', 'NAME2'] - final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1 -DNAME2 + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1 -DNAME2 -DNAME3 AppendUnique: - result=[('NAME1', 'VAL1'), ('NAME2', 'VAL2'), ('NAME1',), ('NAME2',)] - final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1 -DNAME2 + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, appending a tuple to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = ('NAME1', 'VAL1') +Append: + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1=VAL1 +AppendUnique: + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME2=VAL2 ==== Testing CPPDEFINES, appending a list-of-2lists to a list-of-2lists orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] Append: - result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] - final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1=VAL1 -DNAME2=VAL2 + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1=VAL1 -DNAME2=VAL2 AppendUnique: - result=[('NAME1', 'VAL1'), ('NAME2', 'VAL2')] - final=-DNAME1=VAL1 -DNAME2=VAL2 + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME2=VAL2 ==== Testing CPPDEFINES, appending a dict to a list-of-2lists orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} Append: - result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}] - final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 AppendUnique: - result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1')] - final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], ('NAME3', None)] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 ==== Testing CPPDEFINES, appending a string to a dict - orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = FOO + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = 'FOO' +Append: + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1'), 'FOO'] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DFOO +AppendUnique: + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1'), 'FOO'] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DFOO +==== Testing CPPDEFINES, appending a valuestring to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = 'NAME1=VAL1' Append: - result={'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1', 'FOO': None} - final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1'), 'NAME1=VAL1'] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1=VAL1 AppendUnique: - result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), 'FOO'] - final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DFOO + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a list to a dict - orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = ['NAME1', 'NAME2'] + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = ['NAME1', 'NAME2', 'NAME3'] Append: - result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), 'NAME1', 'NAME2'] - final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1 -DNAME2 + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1'), 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 AppendUnique: - result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), ('NAME1',), ('NAME2',)] - final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1 -DNAME2 + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1'), 'NAME1', 'NAME2'] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1 -DNAME2 +==== Testing CPPDEFINES, appending a tuple to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = ('NAME1', 'VAL1') +Append: + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1'), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1=VAL1 +AppendUnique: + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a list-of-2lists to a dict orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] Append: - result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] - final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1=VAL1 -DNAME2=VAL2 + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1'), ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1=VAL1 -DNAME2=VAL2 AppendUnique: - result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1')] - final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a dict to a dict orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} Append: - result={'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} - final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1'), ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 AppendUnique: - result={'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} - final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 """ build_output="scons: `.' is up to date.\n" - -expect = test.wrap_stdout(build_str=build_output, - read_str = expect_print_output) -test.run(arguments = '.', stdout=expect) +expect = test.wrap_stdout(build_str=build_output, read_str=expect_print_output) +test.run(arguments='.', stdout=expect) test.pass_test() # Local Variables: diff --git a/test/CPPDEFINES/basic.py b/test/CPPDEFINES/basic.py index 176f543de..b66ea8a87 100755 --- a/test/CPPDEFINES/basic.py +++ b/test/CPPDEFINES/basic.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify basic use of CPPPDEFINES with various data types. @@ -37,7 +36,7 @@ test_list = [ 'xyz', ['x', 'y', 'z'], ['x', ['y', 123], 'z', ('int', '$INTEGER')], - { 'c' : 3, 'b': None, 'a' : 1 }, + {'c': 3, 'b': None, 'a': 1}, "${TESTDEFS}", "${GEN}", ] @@ -48,33 +47,59 @@ def generator(target, source, env, for_signature): return 'TARGET_AND_SOURCE_ARE_MISSING' for i in test_list: - env = Environment(CPPDEFPREFIX='-D', CPPDEFSUFFIX='', INTEGER=0, TESTDEFS=["FOO", "BAR=1"], GEN=generator) + env = Environment( + CPPDEFPREFIX='-D', + CPPDEFSUFFIX='', + INTEGER=0, + TESTDEFS=["FOO", "BAR=1"], + GEN=generator, + ) ttt = env.Entry('#ttt') sss = env.Entry('#sss') - print(env.Clone(CPPDEFINES=i).subst('$_CPPDEFFLAGS', target=[ttt], source=[sss])) + print( + env.Clone(CPPDEFINES=i).subst( + '$_CPPDEFFLAGS', + target=[ttt], + source=[sss], + ) + ) + for i in test_list: - env = Environment(CPPDEFPREFIX='|', CPPDEFSUFFIX='|', INTEGER=1, TESTDEFS=["FOO", "BAR=1"], GEN=generator) + env = Environment( + CPPDEFPREFIX='|', + CPPDEFSUFFIX='|', + INTEGER=1, + TESTDEFS=["FOO", "BAR=1"], + GEN=generator, + ) ttt = env.Entry('#ttt') sss = env.Entry('#sss') - print(env.Clone(CPPDEFINES=i).subst('$_CPPDEFFLAGS', target=[ttt], source=[sss])) + print( + env.Clone(CPPDEFINES=i).subst( + '$_CPPDEFFLAGS', + target=[ttt], + source=[sss], + ) + ) """) -expect = test.wrap_stdout(build_str="scons: `.' is up to date.\n", - read_str = """\ +expect = test.wrap_stdout( + build_str="scons: `.' is up to date.\n", + read_str="""\ -Dxyz -Dx -Dy -Dz -Dx -Dy=123 -Dz -Dint=0 --Da=1 -Db -Dc=3 +-Dc=3 -Db -Da=1 -DFOO -DBAR=1 -Dttt_GENERATED_sss |xyz| |x| |y| |z| |x| |y=123| |z| |int=1| -|a=1| |b| |c=3| +|c=3| |b| |a=1| |FOO| |BAR=1| |ttt_GENERATED_sss| -""") - +""", +) test.run(arguments = '.', stdout=expect) test.pass_test() diff --git a/test/CPPDEFINES/fixture/SConstruct-Append b/test/CPPDEFINES/fixture/SConstruct-Append new file mode 100644 index 000000000..8c26270f3 --- /dev/null +++ b/test/CPPDEFINES/fixture/SConstruct-Append @@ -0,0 +1,133 @@ +# SPDX-License-Identifier: MIT +# +# Copyright The SCons Foundation + +"""Append/AppendUnique tests""" + +DefaultEnvironment(tools=[]) + +# Special cases: +# https://github.com/SCons/scons/issues/1738 +env_1738_2 = Environment(CPPDEFPREFIX='-D') +env_1738_2['CPPDEFINES'] = ['FOO'] +env_1738_2.Append(CPPDEFINES={'value': '1'}) +print(env_1738_2.subst('$_CPPDEFFLAGS')) +# env_1738_2.Object('test_1738_2', 'main.c') + +# https://github.com/SCons/scons/issues/2300 +env_2300_1 = Environment(CPPDEFINES='foo', CPPDEFPREFIX='-D') +env_2300_1.Append(CPPDEFINES='bar') +print(env_2300_1.subst('$_CPPDEFFLAGS')) + +env_2300_2 = Environment(CPPDEFINES=['foo'], CPPDEFPREFIX='-D') # note the list +env_2300_2.Append(CPPDEFINES='bar') +print(env_2300_2.subst('$_CPPDEFFLAGS')) + +# An initial space-separated string will be split, but not a string in a list. +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi['CPPDEFINES'] = "foo bar" +env_multi.Append(CPPDEFINES="baz") +print(env_multi.subst('$_CPPDEFFLAGS')) + +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi['CPPDEFINES'] = ["foo bar"] +env_multi.Append(CPPDEFINES="baz") +print(env_multi.subst('$_CPPDEFFLAGS')) + +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi['CPPDEFINES'] = "foo" +env_multi.Append(CPPDEFINES=["bar baz"]) +print(env_multi.subst('$_CPPDEFFLAGS')) + +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi['CPPDEFINES'] = "foo" +env_multi.Append(CPPDEFINES="bar baz") +print(env_multi.subst('$_CPPDEFFLAGS')) + +# Check that AppendUnique(..., delete_existing=True) works as expected. +# Each addition is in different but matching form, and different order +# so we expect a reordered list, but with the same macro defines. +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi.Append(CPPDEFINES=["Macro1=Value1", ("Macro2", "Value2"), {"Macro3": "Value3"}, "Macro4"]) +try: + env_multi.AppendUnique(CPPDEFINES="Macro2=Value2", delete_existing=True) + env_multi.AppendUnique(CPPDEFINES=[("Macro4", None)], delete_existing=True) + env_multi.AppendUnique(CPPDEFINES=[("Macro3", "Value3")], delete_existing=True) + env_multi.AppendUnique(CPPDEFINES={"Macro1": "Value1"}, delete_existing=True) +except Exception as t: + print(f"Prepend FAILED: {t}") +else: + print(env_multi.subst('$_CPPDEFFLAGS')) + +# A lone tuple handled differently than a lone list. +env_multi = Environment(CPPDEFPREFIX='-D', CPPDEFINES=("Macro1", "Value1")) +print(env_multi.subst('$_CPPDEFFLAGS')) +env_multi = Environment(CPPDEFPREFIX='-D', CPPDEFINES=["Macro1", "Value1"]) +print(env_multi.subst('$_CPPDEFFLAGS')) + +# https://github.com/SCons/scons/issues/1152 +# https://github.com/SCons/scons/issues/2900 +# Python3 dicts dont preserve order. Hence we supply subclass of OrderedDict +# whose __str__ and __repr__ act like a normal dict. +from collections import OrderedDict + +class OrderedPrintingDict(OrderedDict): + def __repr__(self): + return '{' + ', '.join([f'{k!r}: {v!r}' for (k, v) in self.items()]) + '}' + + __str__ = __repr__ + + # Because dict-like objects (except dict and UserDict) are not deep copied + # directly when constructing Environment(CPPDEFINES=OrderedPrintingDict(...)) + def __semi_deepcopy__(self): + return self.copy() + + +# each of these types will be appended to each of the others +# the first item in each tuple is a label for the output +cases = [ + ('string', 'FOO'), + ('valuestring', 'NAME1=VAL1'), + ('list', ['NAME1', 'NAME2', 'NAME3']), + ('tuple', ('NAME1', 'VAL1')), + ('list-of-2lists', [('NAME1', 'VAL1'), ['NAME2', 'VAL2']]), + ( + 'dict', # intentionally not sorted by key + OrderedPrintingDict([('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')]), + ), +] + + +def dlist(coll): + # if it's a deque, turn it into a list for display purposes + from collections import deque + + if isinstance(coll, deque): + return list(coll) + return coll + + +for (t1, c1) in cases: + for (t2, c2) in cases: + print(f"==== Testing CPPDEFINES, appending a {t2} to a {t1}") + # string-like appearance if the value is a string + orig = f"{c1!r}" if isinstance(c1, str) else c1 + app = f"{c2!r}" if isinstance(c2, str) else c2 + print(f" orig = {orig}, append = {app}") + env = Environment(CPPDEFINES=c1, CPPDEFPREFIX='-D') + try: + env.Append(CPPDEFINES=c2) + final = env.subst('$_CPPDEFFLAGS', source="src", target="tgt") + print(f"Append:\n result={dlist(env['CPPDEFINES'])}\n final={final}") + except Exception as t: + print(f"Append:\n FAILED: {t}") + + env = Environment(CPPDEFINES=c1, CPPDEFPREFIX='-D') + try: + env.AppendUnique(CPPDEFINES=c2) + final = env.subst('$_CPPDEFFLAGS', source="src", target="tgt") + print( + f"AppendUnique:\n result={dlist(env['CPPDEFINES'])}\n final={final}" + ) + except Exception as t: + print(f"AppendUnique:\n FAILED: {t}") diff --git a/test/CPPDEFINES/fixture/SConstruct-Prepend b/test/CPPDEFINES/fixture/SConstruct-Prepend new file mode 100644 index 000000000..26546f113 --- /dev/null +++ b/test/CPPDEFINES/fixture/SConstruct-Prepend @@ -0,0 +1,134 @@ +# SPDX-License-Identifier: MIT +# +# Copyright The SCons Foundation + +"""Prepend/PrependUnique tests""" + +DefaultEnvironment(tools=[]) + +# Special cases: +# https://github.com/SCons/scons/issues/1738 +env_1738_2 = Environment(CPPDEFPREFIX='-D') +env_1738_2['CPPDEFINES'] = ['FOO'] +env_1738_2.Prepend(CPPDEFINES={'value': '1'}) +print(env_1738_2.subst('$_CPPDEFFLAGS')) +# env_1738_2.Object('test_1738_2', 'main.c') + +# https://github.com/SCons/scons/issues/2300 +env_2300_1 = Environment(CPPDEFINES='foo', CPPDEFPREFIX='-D') +env_2300_1.Prepend(CPPDEFINES='bar') +print(env_2300_1.subst('$_CPPDEFFLAGS')) + +env_2300_2 = Environment(CPPDEFINES=['foo'], CPPDEFPREFIX='-D') # note the list +env_2300_2.Prepend(CPPDEFINES='bar') +print(env_2300_2.subst('$_CPPDEFFLAGS')) + +# An initial space-separated string will be split, but not a string in a list. +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi['CPPDEFINES'] = "foo bar" +env_multi.Prepend(CPPDEFINES="baz") +print(env_multi.subst('$_CPPDEFFLAGS')) + +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi['CPPDEFINES'] = ["foo bar"] +env_multi.Prepend(CPPDEFINES="baz") +print(env_multi.subst('$_CPPDEFFLAGS')) + +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi['CPPDEFINES'] = "foo" +env_multi.Prepend(CPPDEFINES=["bar baz"]) +print(env_multi.subst('$_CPPDEFFLAGS')) + +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi['CPPDEFINES'] = "foo" +env_multi.Prepend(CPPDEFINES="bar baz") +print(env_multi.subst('$_CPPDEFFLAGS')) + +# Check that PrependUnique(..., delete_existing=True) works as expected. +# Each addition is in different but matching form, and different order +# so we expect a reordered list, but with the same macro defines. +env_multi = Environment(CPPDEFPREFIX='-D') +env_multi.Prepend(CPPDEFINES=["Macro1=Value1", ("Macro2", "Value2"), {"Macro3": "Value3"}]) +try: + env_multi.PrependUnique(CPPDEFINES="Macro2=Value2", delete_existing=True) + env_multi.PrependUnique(CPPDEFINES=[("Macro4", None)], delete_existing=True) + env_multi.PrependUnique(CPPDEFINES=[("Macro3", "Value3")], delete_existing=True) + env_multi.PrependUnique(CPPDEFINES={"Macro1": "Value1"}, delete_existing=True) +except Exception as t: + print(f"Prepend FAILED: {t}") +else: + print(env_multi.subst('$_CPPDEFFLAGS')) + +# A lone tuple handled differently than a lone list. +env_tuple = Environment(CPPDEFPREFIX='-D', CPPDEFINES=("Macro1", "Value1")) +print(env_tuple.subst('$_CPPDEFFLAGS')) +env_multi = Environment(CPPDEFPREFIX='-D', CPPDEFINES=["Macro1", "Value1"]) +print(env_multi.subst('$_CPPDEFFLAGS')) + +# https://github.com/SCons/scons/issues/1152 +# https://github.com/SCons/scons/issues/2900 +# Python3 dicts dont preserve order. Hence we supply subclass of OrderedDict +# whose __str__ and __repr__ act like a normal dict. +from collections import OrderedDict + + +class OrderedPrintingDict(OrderedDict): + def __repr__(self): + return '{' + ', '.join([f'{k!r}: {v!r}' for (k, v) in self.items()]) + '}' + + __str__ = __repr__ + + # Because dict-like objects (except dict and UserDict) are not deep copied + # directly when constructing Environment(CPPDEFINES=OrderedPrintingDict(...)) + def __semi_deepcopy__(self): + return self.copy() + + +# each of these types will be prepended to each of the others +# the first item in each tuple is a label for the output +cases = [ + ('string', 'FOO'), + ('valuestring', 'NAME1=VAL1'), + ('list', ['NAME1', 'NAME2', 'NAME3']), + ('tuple', ('NAME1', 'VAL1')), + ('list-of-2lists', [('NAME1', 'VAL1'), ['NAME2', 'VAL2']]), + ( + 'dict', # intentionally not sorted by key + OrderedPrintingDict([('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')]), + ), +] + + +def dlist(coll): + # if it's a deque, turn it into a list for display purposes + from collections import deque + + if isinstance(coll, deque): + return list(coll) + return coll + + +for (t1, c1) in cases: + for (t2, c2) in cases: + print(f"==== Testing CPPDEFINES, prepending a {t2} to a {t1}") + # string-like appearance if the value is a string + orig = f"{c1!r}" if isinstance(c1, str) else c1 + pre = f"{c2!r}" if isinstance(c2, str) else c2 + print(f" orig = {orig}, prepend = {pre}") + env = Environment(CPPDEFINES=c1, CPPDEFPREFIX='-D') + try: + env.Prepend(CPPDEFINES=c2) + final = env.subst('$_CPPDEFFLAGS', source="src", target="tgt") + print(f"Prepend:\n result={dlist(env['CPPDEFINES'])}\n final={final}") + except Exception as t: + print(f"Prepend:\n FAILED: {t}") + + env = Environment(CPPDEFINES=c1, CPPDEFPREFIX='-D') + try: + env.PrependUnique(CPPDEFINES=c2) + final = env.subst('$_CPPDEFFLAGS', source="src", target="tgt") + print( + f"PrependUnique:\n result={dlist(env['CPPDEFINES'])}\n final={final}" + ) + except Exception as t: + print(f"PrependUnique:\n FAILED: {t}") diff --git a/test/CPPDEFINES/live.py b/test/CPPDEFINES/live.py index 0c7ad7874..97e0e1323 100644 --- a/test/CPPDEFINES/live.py +++ b/test/CPPDEFINES/live.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify basic use of CPPDEFINES with live compilation. @@ -33,14 +32,14 @@ import TestSCons test = TestSCons.TestSCons() test.write('SConstruct', """\ -foo = Environment(CPPDEFINES = ['FOO', ('VAL', '$VALUE')], VALUE=7) -bar = Environment(CPPDEFINES = {'BAR':None, 'VAL':8}) -baz = Environment(CPPDEFINES = ['BAZ', ('VAL', 9)]) -f = foo.Object(target = 'foo', source = 'prog.c') -b = bar.Object(target = 'bar', source = 'prog.c') -foo.Program(target = 'foo', source = f) -bar.Program(target = 'bar', source = b) -baz.Program(target = 'baz', source = 'baz.cpp') +foo = Environment(CPPDEFINES=['FOO', ('VAL', '$VALUE')], VALUE=7) +bar = Environment(CPPDEFINES={'BAR': None, 'VAL': 8}) +baz = Environment(CPPDEFINES=['BAZ', ('VAL', 9)]) +f = foo.Object(target='foo', source='prog.c') +b = bar.Object(target='bar', source='prog.c') +foo.Program(target='foo', source=f) +bar.Program(target='bar', source=b) +baz.Program(target='baz', source='baz.cpp') """) test.write('prog.c', r""" @@ -74,12 +73,10 @@ main(int argc, char *argv[]) } """) - -test.run(arguments = '.') - -test.run(program = test.workpath('foo'), stdout = "prog.c: FOO 7\n") -test.run(program = test.workpath('bar'), stdout = "prog.c: BAR 8\n") -test.run(program = test.workpath('baz'), stdout = "baz.cpp: BAZ 9\n") +test.run(arguments='.') +test.run(program=test.workpath('foo'), stdout="prog.c: FOO 7\n") +test.run(program=test.workpath('bar'), stdout="prog.c: BAR 8\n") +test.run(program=test.workpath('baz'), stdout="baz.cpp: BAZ 9\n") test.pass_test() diff --git a/test/CPPDEFINES/pkg-config.py b/test/CPPDEFINES/pkg-config.py index 65210cec7..cd8c9dc7b 100644 --- a/test/CPPDEFINES/pkg-config.py +++ b/test/CPPDEFINES/pkg-config.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify merging with MergeFlags to CPPPDEFINES with various data types. @@ -69,12 +68,14 @@ else: test.write('SConstruct', """\ import os import sys + # Python3 dicts dont preserve order. Hence we supply subclass of OrderedDict # whose __str__ and __repr__ act like a normal dict. from collections import OrderedDict + class OrderedPrintingDict(OrderedDict): def __repr__(self): - return '{' + ', '.join(['%r: %r'%(k, v) for (k, v) in self.items()]) + '}' + return '{' + ', '.join(['%r: %r' % (k, v) for (k, v) in self.items()]) + '}' __str__ = __repr__ @@ -85,29 +86,41 @@ class OrderedPrintingDict(OrderedDict): """ + """ # https://github.com/SCons/scons/issues/2671 # Passing test cases -env_1 = Environment(CPPDEFINES=[('DEBUG','1'), 'TEST'], tools = ['%(pkg_config_tools)s']) +env_1 = Environment(CPPDEFINES=[('DEBUG', '1'), 'TEST'], tools=['%(pkg_config_tools)s']) if sys.platform == 'win32': - os.environ['PKG_CONFIG_PATH'] = env_1.Dir('.').abspath.replace("\\\\" , "/") -env_1.ParseConfig('%(pkg_config_cl_path)s "%(pkg_config_path)s" --cflags %(pkg_config_file)s') + os.environ['PKG_CONFIG_PATH'] = env_1.Dir('.').abspath.replace("\\\\", "/") +env_1.ParseConfig( + '%(pkg_config_cl_path)s "%(pkg_config_path)s" --cflags %(pkg_config_file)s' +) print(env_1.subst('$_CPPDEFFLAGS')) -env_2 = Environment(CPPDEFINES=[('DEBUG','1'), 'TEST'], tools = ['%(pkg_config_tools)s']) +env_2 = Environment(CPPDEFINES=[('DEBUG', '1'), 'TEST'], tools=['%(pkg_config_tools)s']) env_2.MergeFlags('-DSOMETHING -DVARIABLE=2') print(env_2.subst('$_CPPDEFFLAGS')) # Failing test cases -env_3 = Environment(CPPDEFINES=OrderedPrintingDict([('DEBUG', 1), ('TEST', None)]), tools = ['%(pkg_config_tools)s']) -env_3.ParseConfig('%(pkg_config_cl_path)s "%(pkg_config_path)s" --cflags %(pkg_config_file)s') +env_3 = Environment( + CPPDEFINES=OrderedPrintingDict([('DEBUG', 1), ('TEST', None)]), + tools=['%(pkg_config_tools)s'], +) +env_3.ParseConfig( + '%(pkg_config_cl_path)s "%(pkg_config_path)s" --cflags %(pkg_config_file)s' +) print(env_3.subst('$_CPPDEFFLAGS')) -env_4 = Environment(CPPDEFINES=OrderedPrintingDict([('DEBUG', 1), ('TEST', None)]), tools = ['%(pkg_config_tools)s']) +env_4 = Environment( + CPPDEFINES=OrderedPrintingDict([('DEBUG', 1), ('TEST', None)]), + tools=['%(pkg_config_tools)s'], +) env_4.MergeFlags('-DSOMETHING -DVARIABLE=2') print(env_4.subst('$_CPPDEFFLAGS')) # https://github.com/SCons/scons/issues/1738 -env_1738_1 = Environment(tools = ['%(pkg_config_tools)s']) -env_1738_1.ParseConfig('%(pkg_config_cl_path)s "%(pkg_config_path)s" --cflags --libs %(pkg_config_file)s') -env_1738_1.Append(CPPDEFINES={'value' : '1'}) +env_1738_1 = Environment(tools=['%(pkg_config_tools)s']) +env_1738_1.ParseConfig( + '%(pkg_config_cl_path)s "%(pkg_config_path)s" --cflags --libs %(pkg_config_file)s' +) +env_1738_1.Append(CPPDEFINES={'value': '1'}) print(env_1738_1.subst('$_CPPDEFFLAGS')) """%locals() ) @@ -119,11 +132,10 @@ expect_print_output="""\ -DSOMETHING -DVARIABLE=2 -Dvalue=1 """ -build_output="scons: `.' is up to date.\n" +build_output = "scons: `.' is up to date.\n" +expect = test.wrap_stdout(build_str=build_output, read_str=expect_print_output) +test.run(arguments='.', stdout=expect) -expect = test.wrap_stdout(build_str=build_output, - read_str = expect_print_output) -test.run(arguments = '.', stdout=expect) test.pass_test() # Local Variables: diff --git a/test/CPPDEFINES/prepend.py b/test/CPPDEFINES/prepend.py new file mode 100644 index 000000000..fb61678a8 --- /dev/null +++ b/test/CPPDEFINES/prepend.py @@ -0,0 +1,349 @@ +#!/usr/bin/env python +# +# MIT License +# +# Copyright The SCons Foundation +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" +Verify prepending to CPPPDEFINES with various data types. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +# Note: explicitly set CPPDEFPREFIX here to simplify testing on Windows. + +# Link: fixture/SConstruct-Prepend +test.file_fixture(["fixture", "SConstruct-Prepend"], "SConstruct") + +expect_print_output="""\ +-Dvalue=1 -DFOO +-Dbar -Dfoo +-Dbar -Dfoo +-Dbaz -Dfoo -Dbar +-Dbaz -Dfoo bar +-Dbar baz -Dfoo +-Dbaz -Dbar -Dfoo +-DMacro1=Value1 -DMacro3=Value3 -DMacro4 -DMacro2=Value2 +-DMacro1=Value1 +-DMacro1 -DValue1 +==== Testing CPPDEFINES, prepending a string to a string + orig = 'FOO', prepend = 'FOO' +Prepend: + result=['FOO', 'FOO'] + final=-DFOO -DFOO +PrependUnique: + result=['FOO'] + final=-DFOO +==== Testing CPPDEFINES, prepending a valuestring to a string + orig = 'FOO', prepend = 'NAME1=VAL1' +Prepend: + result=['NAME1=VAL1', 'FOO'] + final=-DNAME1=VAL1 -DFOO +PrependUnique: + result=['NAME1=VAL1', 'FOO'] + final=-DNAME1=VAL1 -DFOO +==== Testing CPPDEFINES, prepending a list to a string + orig = 'FOO', prepend = ['NAME1', 'NAME2', 'NAME3'] +Prepend: + result=['NAME3', 'NAME2', 'NAME1', 'FOO'] + final=-DNAME3 -DNAME2 -DNAME1 -DFOO +PrependUnique: + result=['NAME3', 'NAME2', 'NAME1', 'FOO'] + final=-DNAME3 -DNAME2 -DNAME1 -DFOO +==== Testing CPPDEFINES, prepending a tuple to a string + orig = 'FOO', prepend = ('NAME1', 'VAL1') +Prepend: + result=[('NAME1', 'VAL1'), 'FOO'] + final=-DNAME1=VAL1 -DFOO +PrependUnique: + result=[('NAME1', 'VAL1'), 'FOO'] + final=-DNAME1=VAL1 -DFOO +==== Testing CPPDEFINES, prepending a list-of-2lists to a string + orig = 'FOO', prepend = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Prepend: + result=[['NAME2', 'VAL2'], ('NAME1', 'VAL1'), 'FOO'] + final=-DNAME2=VAL2 -DNAME1=VAL1 -DFOO +PrependUnique: + result=[['NAME2', 'VAL2'], ('NAME1', 'VAL1'), 'FOO'] + final=-DNAME2=VAL2 -DNAME1=VAL1 -DFOO +==== Testing CPPDEFINES, prepending a dict to a string + orig = 'FOO', prepend = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Prepend: + result=[('NAME1', 'VAL1'), ('NAME3', None), ('NAME2', 'VAL2'), 'FOO'] + final=-DNAME1=VAL1 -DNAME3 -DNAME2=VAL2 -DFOO +PrependUnique: + result=[('NAME1', 'VAL1'), ('NAME3', None), ('NAME2', 'VAL2'), 'FOO'] + final=-DNAME1=VAL1 -DNAME3 -DNAME2=VAL2 -DFOO +==== Testing CPPDEFINES, prepending a string to a valuestring + orig = 'NAME1=VAL1', prepend = 'FOO' +Prepend: + result=['FOO', 'NAME1=VAL1'] + final=-DFOO -DNAME1=VAL1 +PrependUnique: + result=['FOO', 'NAME1=VAL1'] + final=-DFOO -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a valuestring to a valuestring + orig = 'NAME1=VAL1', prepend = 'NAME1=VAL1' +Prepend: + result=['NAME1=VAL1', 'NAME1=VAL1'] + final=-DNAME1=VAL1 -DNAME1=VAL1 +PrependUnique: + result=['NAME1=VAL1'] + final=-DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a list to a valuestring + orig = 'NAME1=VAL1', prepend = ['NAME1', 'NAME2', 'NAME3'] +Prepend: + result=['NAME3', 'NAME2', 'NAME1', 'NAME1=VAL1'] + final=-DNAME3 -DNAME2 -DNAME1 -DNAME1=VAL1 +PrependUnique: + result=['NAME3', 'NAME2', 'NAME1', 'NAME1=VAL1'] + final=-DNAME3 -DNAME2 -DNAME1 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a tuple to a valuestring + orig = 'NAME1=VAL1', prepend = ('NAME1', 'VAL1') +Prepend: + result=[('NAME1', 'VAL1'), 'NAME1=VAL1'] + final=-DNAME1=VAL1 -DNAME1=VAL1 +PrependUnique: + result=['NAME1=VAL1'] + final=-DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a list-of-2lists to a valuestring + orig = 'NAME1=VAL1', prepend = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Prepend: + result=[['NAME2', 'VAL2'], ('NAME1', 'VAL1'), 'NAME1=VAL1'] + final=-DNAME2=VAL2 -DNAME1=VAL1 -DNAME1=VAL1 +PrependUnique: + result=[['NAME2', 'VAL2'], 'NAME1=VAL1'] + final=-DNAME2=VAL2 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a dict to a valuestring + orig = 'NAME1=VAL1', prepend = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Prepend: + result=[('NAME1', 'VAL1'), ('NAME3', None), ('NAME2', 'VAL2'), 'NAME1=VAL1'] + final=-DNAME1=VAL1 -DNAME3 -DNAME2=VAL2 -DNAME1=VAL1 +PrependUnique: + result=[('NAME3', None), ('NAME2', 'VAL2'), 'NAME1=VAL1'] + final=-DNAME3 -DNAME2=VAL2 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a string to a list + orig = ['NAME1', 'NAME2', 'NAME3'], prepend = 'FOO' +Prepend: + result=['FOO', 'NAME1', 'NAME2', 'NAME3'] + final=-DFOO -DNAME1 -DNAME2 -DNAME3 +PrependUnique: + result=['FOO', 'NAME1', 'NAME2', 'NAME3'] + final=-DFOO -DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, prepending a valuestring to a list + orig = ['NAME1', 'NAME2', 'NAME3'], prepend = 'NAME1=VAL1' +Prepend: + result=['NAME1=VAL1', 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +PrependUnique: + result=['NAME1=VAL1', 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, prepending a list to a list + orig = ['NAME1', 'NAME2', 'NAME3'], prepend = ['NAME1', 'NAME2', 'NAME3'] +Prepend: + result=['NAME3', 'NAME2', 'NAME1', 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME3 -DNAME2 -DNAME1 -DNAME1 -DNAME2 -DNAME3 +PrependUnique: + result=['NAME1', 'NAME2', 'NAME3'] + final=-DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, prepending a tuple to a list + orig = ['NAME1', 'NAME2', 'NAME3'], prepend = ('NAME1', 'VAL1') +Prepend: + result=[('NAME1', 'VAL1'), 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +PrependUnique: + result=[('NAME1', 'VAL1'), 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, prepending a list-of-2lists to a list + orig = ['NAME1', 'NAME2', 'NAME3'], prepend = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Prepend: + result=[['NAME2', 'VAL2'], ('NAME1', 'VAL1'), 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME2=VAL2 -DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +PrependUnique: + result=[['NAME2', 'VAL2'], ('NAME1', 'VAL1'), 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME2=VAL2 -DNAME1=VAL1 -DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, prepending a dict to a list + orig = ['NAME1', 'NAME2', 'NAME3'], prepend = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Prepend: + result=[('NAME1', 'VAL1'), ('NAME3', None), ('NAME2', 'VAL2'), 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME3 -DNAME2=VAL2 -DNAME1 -DNAME2 -DNAME3 +PrependUnique: + result=[('NAME1', 'VAL1'), ('NAME2', 'VAL2'), 'NAME1', 'NAME2', 'NAME3'] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1 -DNAME2 -DNAME3 +==== Testing CPPDEFINES, prepending a string to a tuple + orig = ('NAME1', 'VAL1'), prepend = 'FOO' +Prepend: + result=['FOO', ('NAME1', 'VAL1')] + final=-DFOO -DNAME1=VAL1 +PrependUnique: + result=['FOO', ('NAME1', 'VAL1')] + final=-DFOO -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a valuestring to a tuple + orig = ('NAME1', 'VAL1'), prepend = 'NAME1=VAL1' +Prepend: + result=['NAME1=VAL1', ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME1=VAL1 +PrependUnique: + result=[('NAME1', 'VAL1')] + final=-DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a list to a tuple + orig = ('NAME1', 'VAL1'), prepend = ['NAME1', 'NAME2', 'NAME3'] +Prepend: + result=['NAME3', 'NAME2', 'NAME1', ('NAME1', 'VAL1')] + final=-DNAME3 -DNAME2 -DNAME1 -DNAME1=VAL1 +PrependUnique: + result=['NAME3', 'NAME2', 'NAME1', ('NAME1', 'VAL1')] + final=-DNAME3 -DNAME2 -DNAME1 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a tuple to a tuple + orig = ('NAME1', 'VAL1'), prepend = ('NAME1', 'VAL1') +Prepend: + result=[('NAME1', 'VAL1'), ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME1=VAL1 +PrependUnique: + result=[('NAME1', 'VAL1')] + final=-DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a list-of-2lists to a tuple + orig = ('NAME1', 'VAL1'), prepend = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Prepend: + result=[['NAME2', 'VAL2'], ('NAME1', 'VAL1'), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME1=VAL1 -DNAME1=VAL1 +PrependUnique: + result=[['NAME2', 'VAL2'], ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a dict to a tuple + orig = ('NAME1', 'VAL1'), prepend = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Prepend: + result=[('NAME1', 'VAL1'), ('NAME3', None), ('NAME2', 'VAL2'), ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME3 -DNAME2=VAL2 -DNAME1=VAL1 +PrependUnique: + result=[('NAME3', None), ('NAME2', 'VAL2'), ('NAME1', 'VAL1')] + final=-DNAME3 -DNAME2=VAL2 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a string to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], prepend = 'FOO' +Prepend: + result=['FOO', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 +PrependUnique: + result=['FOO', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 +==== Testing CPPDEFINES, prepending a valuestring to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], prepend = 'NAME1=VAL1' +Prepend: + result=['NAME1=VAL1', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME1=VAL1 -DNAME2=VAL2 +PrependUnique: + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME2=VAL2 +==== Testing CPPDEFINES, prepending a list to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], prepend = ['NAME1', 'NAME2', 'NAME3'] +Prepend: + result=['NAME3', 'NAME2', 'NAME1', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME3 -DNAME2 -DNAME1 -DNAME1=VAL1 -DNAME2=VAL2 +PrependUnique: + result=['NAME3', 'NAME2', 'NAME1', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME3 -DNAME2 -DNAME1 -DNAME1=VAL1 -DNAME2=VAL2 +==== Testing CPPDEFINES, prepending a tuple to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], prepend = ('NAME1', 'VAL1') +Prepend: + result=[('NAME1', 'VAL1'), ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME1=VAL1 -DNAME2=VAL2 +PrependUnique: + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME2=VAL2 +==== Testing CPPDEFINES, prepending a list-of-2lists to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], prepend = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Prepend: + result=[['NAME2', 'VAL2'], ('NAME1', 'VAL1'), ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME2=VAL2 -DNAME1=VAL1 -DNAME1=VAL1 -DNAME2=VAL2 +PrependUnique: + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME2=VAL2 +==== Testing CPPDEFINES, prepending a dict to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], prepend = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Prepend: + result=[('NAME1', 'VAL1'), ('NAME3', None), ('NAME2', 'VAL2'), ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1=VAL1 -DNAME3 -DNAME2=VAL2 -DNAME1=VAL1 -DNAME2=VAL2 +PrependUnique: + result=[('NAME3', None), ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME3 -DNAME1=VAL1 -DNAME2=VAL2 +==== Testing CPPDEFINES, prepending a string to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, prepend = 'FOO' +Prepend: + result=['FOO', ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DFOO -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +PrependUnique: + result=['FOO', ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DFOO -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a valuestring to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, prepend = 'NAME1=VAL1' +Prepend: + result=['NAME1=VAL1', ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +PrependUnique: + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a list to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, prepend = ['NAME1', 'NAME2', 'NAME3'] +Prepend: + result=['NAME3', 'NAME2', 'NAME1', ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME3 -DNAME2 -DNAME1 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +PrependUnique: + result=['NAME2', 'NAME1', ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2 -DNAME1 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a tuple to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, prepend = ('NAME1', 'VAL1') +Prepend: + result=[('NAME1', 'VAL1'), ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +PrependUnique: + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a list-of-2lists to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, prepend = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Prepend: + result=[['NAME2', 'VAL2'], ('NAME1', 'VAL1'), ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +PrependUnique: + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +==== Testing CPPDEFINES, prepending a dict to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, prepend = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Prepend: + result=[('NAME1', 'VAL1'), ('NAME3', None), ('NAME2', 'VAL2'), ('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME1=VAL1 -DNAME3 -DNAME2=VAL2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +PrependUnique: + result=[('NAME2', 'VAL2'), ('NAME3', None), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +""" + +build_output="scons: `.' is up to date.\n" +expect = test.wrap_stdout(build_str=build_output, read_str=expect_print_output) +test.run(arguments='.', stdout=expect) +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/CPPDEFINES/scan.py b/test/CPPDEFINES/scan.py index 53186425a..49cbec240 100644 --- a/test/CPPDEFINES/scan.py +++ b/test/CPPDEFINES/scan.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify that use of the Scanner that evaluates CPP lines works as expected. @@ -41,12 +40,12 @@ f3_exe = 'f3' + TestSCons._exe f4_exe = 'f4' + TestSCons._exe test.write('SConstruct', """\ -env = Environment(CPPPATH = ['.']) +env = Environment(CPPPATH=['.']) -f1 = env.Object('f1', 'fff.c', CPPDEFINES = ['F1']) -f2 = env.Object('f2', 'fff.c', CPPDEFINES = [('F2', 1)]) -f3 = env.Object('f3', 'fff.c', CPPDEFINES = {'F3':None}) -f4 = env.Object('f4', 'fff.c', CPPDEFINES = {'F4':1}) +f1 = env.Object('f1', 'fff.c', CPPDEFINES=['F1']) +f2 = env.Object('f2', 'fff.c', CPPDEFINES=[('F2', 1)]) +f3 = env.Object('f3', 'fff.c', CPPDEFINES={'F3': None}) +f4 = env.Object('f4', 'fff.c', CPPDEFINES={'F4': 1}) env.Program('f1', ['prog.c', f1]) env.Program('f2', ['prog.c', f2]) @@ -110,20 +109,16 @@ main(int argc, char *argv[]) test.run(arguments = '.') - test.run(program = test.workpath('f1'), stdout = "prog.c: F1\n") test.run(program = test.workpath('f2'), stdout = "prog.c: F2\n") test.run(program = test.workpath('f3'), stdout = "prog.c: F3\n") test.run(program = test.workpath('f4'), stdout = "prog.c: F4\n") - - test.write('f1.h', """ #define STRING "F1 again" """) test.up_to_date(arguments = '%(f2_exe)s %(f3_exe)s %(f4_exe)s' % locals()) - test.not_up_to_date(arguments = '.') test.run(program = test.workpath('f1'), stdout = "prog.c: F1 again\n") @@ -131,14 +126,11 @@ test.run(program = test.workpath('f2'), stdout = "prog.c: F2\n") test.run(program = test.workpath('f3'), stdout = "prog.c: F3\n") test.run(program = test.workpath('f4'), stdout = "prog.c: F4\n") - - test.write('f2.h', """ #define STRING "F2 again" """) test.up_to_date(arguments = '%(f1_exe)s %(f3_exe)s %(f4_exe)s' % locals()) - test.not_up_to_date(arguments = '.') test.run(program = test.workpath('f1'), stdout = "prog.c: F1 again\n") @@ -146,14 +138,11 @@ test.run(program = test.workpath('f2'), stdout = "prog.c: F2 again\n") test.run(program = test.workpath('f3'), stdout = "prog.c: F3\n") test.run(program = test.workpath('f4'), stdout = "prog.c: F4\n") - - test.write('f3.h', """ #define STRING "F3 again" """) test.up_to_date(arguments = '%(f1_exe)s %(f2_exe)s %(f4_exe)s' % locals()) - test.not_up_to_date(arguments = '.') test.run(program = test.workpath('f1'), stdout = "prog.c: F1 again\n") @@ -161,14 +150,11 @@ test.run(program = test.workpath('f2'), stdout = "prog.c: F2 again\n") test.run(program = test.workpath('f3'), stdout = "prog.c: F3 again\n") test.run(program = test.workpath('f4'), stdout = "prog.c: F4\n") - - test.write('f4.h', """ #define STRING "F4 again" """) test.up_to_date(arguments = '%(f1_exe)s %(f2_exe)s %(f3_exe)s' % locals()) - test.not_up_to_date(arguments = '.') test.run(program = test.workpath('f1'), stdout = "prog.c: F1 again\n") @@ -176,8 +162,6 @@ test.run(program = test.workpath('f2'), stdout = "prog.c: F2 again\n") test.run(program = test.workpath('f3'), stdout = "prog.c: F3 again\n") test.run(program = test.workpath('f4'), stdout = "prog.c: F4 again\n") - - test.pass_test() # Local Variables: diff --git a/test/CPPDEFINES/undefined.py b/test/CPPDEFINES/undefined.py index b26b05a32..31568ea4b 100644 --- a/test/CPPDEFINES/undefined.py +++ b/test/CPPDEFINES/undefined.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify that $_CPPDEFFLAGS doesn't barf when CPPDEFINES isn't defined. @@ -37,10 +36,8 @@ env = Environment() print(env.subst('$_CPPDEFFLAGS')) """) -expect = test.wrap_stdout(build_str="scons: `.' is up to date.\n", - read_str = "\n") - -test.run(arguments = '.', stdout=expect) +expect = test.wrap_stdout(build_str="scons: `.' is up to date.\n", read_str="\n") +test.run(arguments='.', stdout=expect) test.pass_test() diff --git a/test/ParseConfig.py b/test/ParseConfig.py index efb3a75f1..109a3a76c 100644 --- a/test/ParseConfig.py +++ b/test/ParseConfig.py @@ -33,6 +33,7 @@ test = TestSCons.TestSCons() test_config1 = test.workpath('test-config1') test_config2 = test.workpath('test-config2') test_config3 = test.workpath('test-config3') +test_config4 = test.workpath('test-config4') # 'abc' is supposed to be a static lib; it is included in LIBS as a # File node. @@ -51,6 +52,10 @@ test.write(test_config3, """\ print("-L foo -L lib_dir -isysroot /tmp -arch ppc -arch i386") """) +test.write(test_config4, """\ +print("-D_REENTRANT -lpulse -pthread") +""") + test.write('SConstruct1', """ env = Environment(CPPPATH = [], LIBPATH = [], LIBS = [], CCFLAGS = '-pipe -Wall') @@ -85,6 +90,23 @@ print([str(x) for x in env['LIBS']]) print(env['CCFLAGS']) """ % locals()) +# issue #4321: if CPPDEFINES has been promoted to deque, adding would fail +test.write('SConstruct4', f"""\ +env = Environment( + CPPDEFINES="_REENTRANT", + LIBS=[], + CCFLAGS=[], + LINKFLAGS=[], + PYTHON=r'{_python_}', +) +env.Append(CPPDEFINES="TOOLS_ENABLED") +env.ParseConfig(r"$PYTHON {test_config4} --libs --cflags") +print([str(x) for x in env['CPPDEFINES']]) +print([str(x) for x in env['LIBS']]) +print(env['CCFLAGS']) +print(env['LINKFLAGS']) +""") + good_stdout = """\ ['/usr/include/fum', 'bar'] ['/usr/fax', 'foo', 'lib_dir'] @@ -99,12 +121,21 @@ stdout3 = """\ ['-pipe', '-Wall', ('-isysroot', '/tmp'), ('-arch', 'ppc'), ('-arch', 'i386')] """ +stdout4 = """\ +['TOOLS_ENABLED', '_REENTRANT'] +['pulse'] +['-pthread'] +['-pthread'] +""" + test.run(arguments = "-q -Q -f SConstruct1 .", stdout = good_stdout) test.run(arguments = "-q -Q -f SConstruct2 .", stdout = good_stdout) test.run(arguments = "-q -Q -f SConstruct3 .", stdout = stdout3) +test.run(arguments = "-q -Q -f SConstruct4 .", stdout = stdout4) + test.pass_test() # Local Variables: diff --git a/test/QT/CPPPATH-appended.py b/test/QT/qt3/CPPPATH-appended.py index ee1808faf..ee1808faf 100644 --- a/test/QT/CPPPATH-appended.py +++ b/test/QT/qt3/CPPPATH-appended.py diff --git a/test/QT/CPPPATH.py b/test/QT/qt3/CPPPATH.py index b56efad44..b56efad44 100644 --- a/test/QT/CPPPATH.py +++ b/test/QT/qt3/CPPPATH.py diff --git a/test/QT/QTFLAGS.py b/test/QT/qt3/QTFLAGS.py index c759c2a4a..56536845f 100644 --- a/test/QT/QTFLAGS.py +++ b/test/QT/qt3/QTFLAGS.py @@ -24,7 +24,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -Testing the configuration mechanisms of the 'qt' tool. +Testing the configuration mechanisms of the 'qt3' tool. """ import TestSCons @@ -39,24 +39,24 @@ test.subdir('work1', 'work2') test.run( chdir=test.workpath('qt', 'lib'), - arguments="--warn=no-tool-qt-deprecated .", + arguments=".", stderr=TestSCons.noisy_ar, match=TestSCons.match_re_dotall, ) -QT = test.workpath('qt') -QT_LIB = 'myqt' -QT_MOC = '%s %s' % (_python_, test.workpath('qt', 'bin', 'mymoc.py')) -QT_UIC = '%s %s' % (_python_, test.workpath('qt', 'bin', 'myuic.py')) +QT3 = test.workpath('qt') +QT3_LIB = 'myqt' +QT3_MOC = '%s %s' % (_python_, test.workpath('qt', 'bin', 'mymoc.py')) +QT3_UIC = '%s %s' % (_python_, test.workpath('qt', 'bin', 'myuic.py')) def createSConstruct(test, place, overrides): test.write(place, """\ env = Environment( - tools=['default','qt'], - QTDIR = r'%s', - QT_LIB = r'%s', - QT_MOC = r'%s', - QT_UIC = r'%s', + tools=['default','qt3'], + QT3DIR = r'%s', + QT3_LIB = r'%s', + QT3_MOC = r'%s', + QT3_UIC = r'%s', %s # last because 'overrides' may add comma ) if ARGUMENTS.get('variant_dir', 0): @@ -70,23 +70,23 @@ else: sconscript = File('SConscript') Export("env") SConscript(sconscript) -""" % (QT, QT_LIB, QT_MOC, QT_UIC, overrides)) +""" % (QT3, QT3_LIB, QT3_MOC, QT3_UIC, overrides)) createSConstruct(test, ['work1', 'SConstruct'], - """QT_UICIMPLFLAGS='-x', - QT_UICDECLFLAGS='-y', - QT_MOCFROMHFLAGS='-z', - QT_MOCFROMCXXFLAGS='-i -w', - QT_UICDECLPREFIX='uic-', - QT_UICDECLSUFFIX='.hpp', - QT_UICIMPLPREFIX='', - QT_UICIMPLSUFFIX='.cxx', - QT_MOCHPREFIX='mmm', - QT_MOCHSUFFIX='.cxx', - QT_MOCCXXPREFIX='moc', - QT_MOCCXXSUFFIX='.inl', - QT_UISUFFIX='.myui',""") + """QT3_UICIMPLFLAGS='-x', + QT3_UICDECLFLAGS='-y', + QT3_MOCFROMHFLAGS='-z', + QT3_MOCFROMCXXFLAGS='-i -w', + QT3_UICDECLPREFIX='uic-', + QT3_UICDECLSUFFIX='.hpp', + QT3_UICIMPLPREFIX='', + QT3_UICIMPLSUFFIX='.cxx', + QT3_MOCHPREFIX='mmm', + QT3_MOCHSUFFIX='.cxx', + QT3_MOCCXXPREFIX='moc', + QT3_MOCCXXSUFFIX='.inl', + QT3_UISUFFIX='.myui',""") test.write(['work1', 'SConscript'],""" Import("env") env.Program('mytest', ['mocFromH.cpp', @@ -137,7 +137,7 @@ int main(void) { } """) -test.run(chdir='work1', arguments="--warn=no-tool-qt-deprecated mytest" + _exe) +test.run(chdir='work1', arguments="mytest" + _exe) test.must_exist( ['work1', 'mmmmocFromH.cxx'], @@ -173,32 +173,32 @@ test.write(['work2', 'SConstruct'], """ import os.path env1 = Environment( - tools=['qt'], - QTDIR=r'%(QTDIR)s', - QT_BINPATH='$QTDIR/bin64', - QT_LIBPATH='$QTDIR/lib64', - QT_CPPPATH='$QTDIR/h64', + tools=['qt3'], + QT3DIR=r'%(QT3DIR)s', + QT3_BINPATH='$QT3DIR/bin64', + QT3_LIBPATH='$QT3DIR/lib64', + QT3_CPPPATH='$QT3DIR/h64', ) cpppath = env1.subst('$CPPPATH') -if os.path.normpath(cpppath) != os.path.join(r'%(QTDIR)s', 'h64'): +if os.path.normpath(cpppath) != os.path.join(r'%(QT3DIR)s', 'h64'): print(cpppath) Exit(1) libpath = env1.subst('$LIBPATH') -if os.path.normpath(libpath) != os.path.join(r'%(QTDIR)s', 'lib64'): +if os.path.normpath(libpath) != os.path.join(r'%(QT3DIR)s', 'lib64'): print(libpath) Exit(2) -qt_moc = env1.subst('$QT_MOC') -if os.path.normpath(qt_moc) != os.path.join(r'%(QTDIR)s', 'bin64', 'moc'): +qt_moc = env1.subst('$QT3_MOC') +if os.path.normpath(qt_moc) != os.path.join(r'%(QT3DIR)s', 'bin64', 'moc'): print(qt_moc) Exit(3) env2 = Environment( - tools=['default', 'qt'], QTDIR=None, QT_LIB=None, QT_CPPPATH=None, QT_LIBPATH=None + tools=['default', 'qt3'], QT3DIR=None, QT3_LIB=None, QT3_CPPPATH=None, QT3_LIBPATH=None ) env2.Program('main.cpp') -""" % {'QTDIR':QT}) +""" % {'QT3DIR':QT3}) test.write(['work2', 'main.cpp'], """ int main(void) { return 0; } @@ -206,7 +206,7 @@ int main(void) { return 0; } # Ignore stderr, because if Qt is not installed, # there may be a warning about an empty QTDIR on stderr. -test.run(arguments="--warn=no-tool-qt-deprecated", chdir='work2', stderr=None) +test.run(chdir='work2', stderr=None) test.must_exist(['work2', 'main' + _exe]) diff --git a/test/QT/Tool.py b/test/QT/qt3/Tool.py index 122e7f413..1b34ea2ab 100644 --- a/test/QT/Tool.py +++ b/test/QT/qt3/Tool.py @@ -24,7 +24,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -Verify that applying env.Tool('qt') after running Configure checks +Verify that applying env.Tool('qt3') after running Configure checks works properly. This was broken in 0.96.95. The configuration here is a moderately stripped-down version of the @@ -90,7 +90,7 @@ def CheckForQt(context): ] if 'QTDIR' in os.environ: - potential_qt_dirs.insert(0, os.environ[ 'QTDIR' ]) + potential_qt_dirs.insert(0, os.environ['QTDIR']) if env[ 'qt_directory' ] != "/": uic_path = os.path.join(env['qt_directory'], 'bin', 'uic') @@ -101,7 +101,7 @@ def CheckForQt(context): return 0 for i in potential_qt_dirs: - context.env.Replace(QTDIR = i) + context.env.Replace(QT3DIR = i) if CheckForQtAt(context, i): # additional checks to validate QT installation if not os.path.isfile(os.path.join(i, 'bin', 'uic')): @@ -133,7 +133,7 @@ opts = Variables('lprof.conf') opts.Add(PathVariable("qt_directory", "Path to Qt directory", "/")) opts.Update(env) -env['QT_LIB'] = 'qt-mt' +env['QT3_LIB'] = 'qt-mt' config = env.Configure(custom_tests = { 'CheckForQt' : CheckForQt, }) @@ -142,10 +142,10 @@ if not config.CheckForQt(): print("Failed to find valid QT environment.") Exit(1) -env.Tool('qt', ['$TOOL_PATH']) +env.Tool('qt3', ['$TOOL_PATH']) """) -test.run(arguments='--warn=no-tool-qt-deprecated .') +test.run(arguments='.') test.pass_test() diff --git a/test/QT/copied-env.py b/test/QT/qt3/copied-env.py index 74f59b7fc..9bcb95b68 100644 --- a/test/QT/copied-env.py +++ b/test/QT/qt3/copied-env.py @@ -33,7 +33,7 @@ test = TestSCons.TestSCons() test.Qt_dummy_installation() -test.Qt_create_SConstruct('SConstruct') +test.Qt_create_SConstruct('SConstruct', qt_tool='qt3') test.write('SConscript', """\ Import("env") @@ -63,7 +63,7 @@ test.write('MyForm.ui', r""" void aaa(void) """) -test.run(arguments="--warn=no-tool-qt-deprecated") +test.run() moc_MyForm = [x for x in test.stdout().split('\n') if x.find('moc_MyForm') != -1] diff --git a/test/QT/empty-env.py b/test/QT/qt3/empty-env.py index e9dfc81b1..cd1434080 100644 --- a/test/QT/empty-env.py +++ b/test/QT/qt3/empty-env.py @@ -35,11 +35,11 @@ test.Qt_dummy_installation('qt') test.write('SConstruct', """\ orig = Environment() -env = orig.Clone(QTDIR = r'%s', - QT_LIB = r'%s', - QT_MOC = r'%s', - QT_UIC = r'%s', - tools=['qt']) +env = orig.Clone(QT3DIR = r'%s', + QT3_LIB = r'%s', + QT3_MOC = r'%s', + QT3_UIC = r'%s', + tools=['qt3']) env.Program('main', 'main.cpp', CPPDEFINES=['FOO'], LIBS=[]) """ % (test.QT, test.QT_LIB, test.QT_MOC, test.QT_UIC)) @@ -61,11 +61,10 @@ foo6(void) # we can receive warnings about a non detected qt (empty QTDIR) # these are not critical, but may be annoying. -test.run(stderr=None, arguments='--warn=no-tool-qt-deprecated') +test.run(stderr=None) test.run( program=test.workpath('main' + TestSCons._exe), - arguments='--warn=no-tool-qt-deprecated', stderr=None, stdout='qt/include/foo6.h\n', ) diff --git a/test/QT/generated-ui.py b/test/QT/qt3/generated-ui.py index fd368b34d..d43b21b00 100644 --- a/test/QT/generated-ui.py +++ b/test/QT/qt3/generated-ui.py @@ -45,7 +45,7 @@ test.write(['SConstruct'], """\ import os aa=os.getcwd() -env=Environment(tools=['default','expheaders','qt'],toolpath=[aa]) +env=Environment(tools=['default','expheaders','qt3'],toolpath=[aa]) if 'HOME' in os.environ: env['ENV']['HOME'] = os.environ['HOME'] env["EXP_HEADER_ABS"]=os.path.join(os.getcwd(),'include') @@ -120,12 +120,11 @@ test.write(['layer', 'aclock', 'qt_bug', 'migraform.ui'], """\ """) test.run( - arguments='--warn=no-tool-qt-deprecated', stderr=TestSCons.noisy_ar, match=TestSCons.match_re_dotall, ) -test.up_to_date(options="--warn=no-tool-qt-deprecated", arguments=".") +test.up_to_date(arguments=".") test.pass_test() diff --git a/test/QT/installed.py b/test/QT/qt3/installed.py index 9e8693e3f..71ff98fb7 100644 --- a/test/QT/installed.py +++ b/test/QT/qt3/installed.py @@ -24,7 +24,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -Look if qt is installed, and try out all builders. +Look if qt3 is installed, and try out all builders. """ import os @@ -56,7 +56,7 @@ try: except KeyError: ENV_PATH=ENV.get('PATH', '') -env = Environment(tools=['default','qt'], +env = Environment(tools=['default','qt3'], ENV={'PATH':ENV_PATH, 'PATHEXT':os.environ.get('PATHEXT'), 'HOME':os.getcwd(), @@ -65,9 +65,9 @@ env = Environment(tools=['default','qt'], CXXFILESUFFIX=".cpp") conf = env.Configure() -if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0): - conf.env['QT_LIB'] = 'qt-mt' - if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0): +if not conf.CheckLib(env.subst("$QT3_LIB"), autoadd=0): + conf.env['QT3_LIB'] = 'qt-mt' + if not conf.CheckLib(env.subst("$QT3_LIB"), autoadd=0): Exit(0) env = conf.Finish() VariantDir('bld', '.') @@ -196,18 +196,18 @@ if test.stdout() != "Hello World\n" or test.stderr() != '' or test.status: sys.stdout.write('test_realqt returned status %s\n' % test.status) test.fail_test() -QTDIR = os.environ['QTDIR'] +QT3DIR = os.environ['QTDIR'] PATH = os.environ['PATH'] os.environ['QTDIR'] = '' os.environ['PATH'] = '.' test.run( stderr=None, - arguments="--warn=no-tool-qt-deprecated -c bld/test_realqt" + TestSCons._exe, + arguments="-c bld/test_realqt" + TestSCons._exe, ) -expect1 = "scons: warning: Could not detect qt, using empty QTDIR" -expect2 = "scons: warning: Could not detect qt, using moc executable as a hint" +expect1 = "scons: warning: Could not detect qt3, using empty QT3DIR" +expect2 = "scons: warning: Could not detect qt3, using moc executable as a hint" test.fail_test(expect1 not in test.stderr() and expect2 not in test.stderr()) diff --git a/test/QT/manual.py b/test/QT/qt3/manual.py index 84c6df8e0..f467b5ae2 100644 --- a/test/QT/manual.py +++ b/test/QT/qt3/manual.py @@ -24,7 +24,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -Test the manual QT builder calls. +Test the manual QT3 builder calls. """ import TestSCons @@ -51,7 +51,7 @@ sources.extend(env.Uic('ui/ccc.ui')[1:]) # manual target specification sources.append(env.Moc('moc-ddd.cpp', 'include/ddd.h', - QT_MOCHPREFIX='')) # Watch out ! + QT3_MOCHPREFIX='')) # Watch out ! moc = env.Moc('moc_eee.cpp', 'eee.cpp') env.Ignore( moc, moc ) sources.extend(env.Uic(['include/uic_fff.hpp', 'fff.cpp', 'fff.moc.cpp'], @@ -61,7 +61,7 @@ print(list(map(str,sources))) env.Program(target='aaa', source=sources, CPPPATH=['$CPPPATH', './include'], - QT_AUTOSCAN=0) + QT3_AUTOSCAN=0) """) test.write('aaa.cpp', r""" @@ -123,7 +123,7 @@ int main(void) { } """) -test.run(arguments="--warn=no-tool-qt-deprecated " + aaa_exe) +test.run(arguments=aaa_exe) # normal invocation test.must_exist(test.workpath('include', 'moc_aaa.cc')) diff --git a/test/QT/moc-from-cpp.py b/test/QT/qt3/moc-from-cpp.py index bbab8cab8..bbab8cab8 100644 --- a/test/QT/moc-from-cpp.py +++ b/test/QT/qt3/moc-from-cpp.py diff --git a/test/QT/moc-from-header.py b/test/QT/qt3/moc-from-header.py index 65a12e1ed..65a12e1ed 100644 --- a/test/QT/moc-from-header.py +++ b/test/QT/qt3/moc-from-header.py diff --git a/test/QT/qt_warnings.py b/test/QT/qt3/qt_warnings.py index fb23a7151..1cbf2b013 100644 --- a/test/QT/qt_warnings.py +++ b/test/QT/qt3/qt_warnings.py @@ -51,7 +51,7 @@ import os env.StaticLibrary('aaa.cpp') """) -test.run(arguments="--warn=no-tool-qt-deprecated", stderr=None) +test.run(stderr=None) match12 = r""" scons: warning: Generated moc file 'aaa.moc' is not included by 'aaa.cpp' @@ -64,7 +64,7 @@ if not re.search(match12, test.stderr()): os.environ['QTDIR'] = test.QT -test.run(arguments='--warn=no-tool-qt-deprecated -n noqtdir=1') +test.run(arguments='-n noqtdir=1') # We'd like to eliminate $QTDIR from the environment as follows: # del os.environ['QTDIR'] @@ -74,7 +74,7 @@ test.run(arguments='--warn=no-tool-qt-deprecated -n noqtdir=1') # environment, so it only gets removed from the Python dictionary. # Consequently, we need to just wipe out its value as follows> os.environ['QTDIR'] = '' -test.run(stderr=None, arguments='--warn=no-tool-qt-deprecated -n noqtdir=1') +test.run(stderr=None, arguments='-n noqtdir=1') moc = test.where_is('moc') if moc: @@ -83,13 +83,13 @@ if moc: qtdir = qtdir.replace('\\', '\\\\' ) expect = r""" -scons: warning: Could not detect qt, using moc executable as a hint \(QTDIR=%s\) +scons: warning: Could not detect qt3, using moc executable as a hint \(QT3DIR=%s\) File "%s", line \d+, in (\?|<module>) """ % (qtdir, re.escape(SConstruct_path)) else: expect = r""" -scons: warning: Could not detect qt, using empty QTDIR +scons: warning: Could not detect qt3, using empty QT3DIR File "%s", line \d+, in (\?|<module>) """ % re.escape(SConstruct_path) diff --git a/test/QT/reentrant.py b/test/QT/qt3/reentrant.py index 40fb1f19a..be6d8a62f 100644 --- a/test/QT/reentrant.py +++ b/test/QT/qt3/reentrant.py @@ -49,7 +49,7 @@ test.Qt_create_SConstruct('SConstruct') test.write('SConscript', """\ Import("env") -env = env.Clone(tools=['qt']) +env = env.Clone(tools=['qt3']) env.Program('main', 'main.cpp', CPPDEFINES=['FOO'], LIBS=[]) """) diff --git a/test/QT/source-from-ui.py b/test/QT/qt3/source-from-ui.py index 569fbab2c..1404f7532 100644 --- a/test/QT/source-from-ui.py +++ b/test/QT/qt3/source-from-ui.py @@ -67,9 +67,9 @@ void useit() { } """) -test.run(arguments="--warn=no-tool-qt-deprecated " + aaa_dll) +test.run(arguments=aaa_dll) -test.up_to_date(options='--warn=no-tool-qt-deprecated -n', arguments=aaa_dll) +test.up_to_date(options='-n', arguments=aaa_dll) test.write('aaa.ui', r""" /* a change */ @@ -81,11 +81,11 @@ test.write('aaa.ui', r""" DLLEXPORT void aaa(void) """) -test.not_up_to_date(options='--warn=no-tool-qt-deprecated -n', arguments=moc) -test.not_up_to_date(options='--warn=no-tool-qt-deprecated -n', arguments=cpp) -test.not_up_to_date(options='--warn=no-tool-qt-deprecated -n', arguments=h) +test.not_up_to_date(options='-n', arguments=moc) +test.not_up_to_date(options='-n', arguments=cpp) +test.not_up_to_date(options='-n', arguments=h) -test.run(arguments="--warn=no-tool-qt-deprecated " + aaa_dll) +test.run(arguments=" " + aaa_dll) test.write('aaa.ui', r""" void aaa(void) @@ -93,28 +93,28 @@ void aaa(void) """) # test that non-existant ui.h files are ignored (as uic does) -test.run(arguments="--warn=no-tool-qt-deprecated " + aaa_dll) +test.run(arguments=" " + aaa_dll) test.write('aaa.ui.h', r""" /* test dependency to .ui.h */ """) -test.run(arguments="--warn=no-tool-qt-deprecated " + aaa_dll) +test.run(arguments=" " + aaa_dll) test.write('aaa.ui.h', r""" /* changed */ """) -test.not_up_to_date(options='--warn=no-tool-qt-deprecated -n', arguments=obj) -test.not_up_to_date(options='--warn=no-tool-qt-deprecated -n', arguments=cpp) -test.not_up_to_date(options='--warn=no-tool-qt-deprecated -n', arguments=h) -test.not_up_to_date(options='--warn=no-tool-qt-deprecated -n', arguments=moc) +test.not_up_to_date(options='-n', arguments=obj) +test.not_up_to_date(options='-n', arguments=cpp) +test.not_up_to_date(options='-n', arguments=h) +test.not_up_to_date(options='-n', arguments=moc) # clean up -test.run(arguments="--warn=no-tool-qt-deprecated -c " + aaa_dll) +test.run(arguments=" -c " + aaa_dll) test.run( - arguments="--warn=no-tool-qt-deprecated variant_dir=1 " + arguments="variant_dir=1 " + test.workpath('build', aaa_dll) ) @@ -129,7 +129,7 @@ cppContents = test.read(test.workpath('build', cpp), mode='r') test.fail_test(cppContents.find('#include "aaa.ui.h"') == -1) test.run( - arguments="--warn=no-tool-qt-deprecated variant_dir=1 chdir=1 " + arguments="variant_dir=1 chdir=1 " + test.workpath('build', aaa_dll) ) @@ -141,7 +141,7 @@ test.must_not_exist(test.workpath(cpp)) test.must_not_exist(test.workpath(h)) test.run( - arguments="--warn=no-tool-qt-deprecated variant_dir=1 chdir=1 dup=0 " + arguments=" variant_dir=1 chdir=1 dup=0 " + test.workpath('build_dup0', aaa_dll) ) diff --git a/test/QT/up-to-date.py b/test/QT/qt3/up-to-date.py index 06fb5590e..ec5123827 100644 --- a/test/QT/up-to-date.py +++ b/test/QT/qt3/up-to-date.py @@ -53,7 +53,7 @@ test.write('SConstruct', """\ import os aa=os.getcwd() -env=Environment(tools=['default','expheaders','qt'],toolpath=[aa]) +env=Environment(tools=['default','expheaders','qt3'],toolpath=[aa]) env["EXP_HEADER_ABS"]=os.path.join(os.getcwd(),'include') if not os.access(env["EXP_HEADER_ABS"],os.F_OK): os.mkdir (env["EXP_HEADER_ABS"]) diff --git a/test/TEX/newglossary.py b/test/TEX/newglossary.py index 70296cfcb..e6a8c4b90 100644 --- a/test/TEX/newglossary.py +++ b/test/TEX/newglossary.py @@ -87,12 +87,12 @@ Acronyms \gls{gnu} and glossary entries \gls{nix}. a definition \gls{defPower} -\glossarystyle{index} +\setglossarystyle{index} \printglossary[type=symbol] \printglossary[type=acronym] \printglossary[type=main] \printglossary[type=definition] -\glossarystyle{super} +\setglossarystyle{super} \end{document}""") diff --git a/test/ValidateOptions.py b/test/ValidateOptions.py index 9b53c0949..5dff386e2 100644 --- a/test/ValidateOptions.py +++ b/test/ValidateOptions.py @@ -28,38 +28,60 @@ Test ValidateOptions(). import TestSCons test = TestSCons.TestSCons() +# ref: test/fixture/SConstruct-check-valid-options test.file_fixture('fixture/SConstruct-check-valid-options', 'SConstruct') -# Should see "This is in SConstruct" because all options specified (none) are valid and -# so ValidatedOptions() won't exit before it's printed. +# Should see "This is in SConstruct" because all options specified (none) +# are valid and so ValidatedOptions() won't exit before it's printed. test.run() test.must_contain_single_instance_of(test.stdout(), ["This is in SConstruct"]) -# Should see "This is in SConstruct" because all options specified (--testing=abc) are valid and -# so ValidatedOptions() won't exit before it's printed. +# Should see "This is in SConstruct" because all options specified +# (--testing=abc) are valid and so ValidatedOptions() won't exit before +# it's printed. test.run(arguments="--testing=abc") test.must_contain_single_instance_of(test.stdout(), ["This is in SConstruct"]) -# Should not see "This is in SConstruct" because the option specified (--garbage=xyz) is invalid and -# so ValidatedOptions() will exit before it's printed. -test.run(arguments="--garbage=xyz", status=2, stderr=".*SCons Error: no such option: --garbage.*", - match=TestSCons.match_re_dotall) -test.fail_test(("This is in SConstruct" in test.stdout()), - message='"This is in SConstruct" should not be output. This means ValidateOptions() did not error out before this was printed') +# Should not see "This is in SConstruct" because the option specified +# (--garbage=xyz) is invalid and so ValidatedOptions() will exit +# before it's printed. +test.run( + arguments="--garbage=xyz", + status=2, + stderr=".*SCons Error: no such option: --garbage.*", + match=TestSCons.match_re_dotall, +) +test.fail_test( + ("This is in SConstruct" in test.stdout()), + message='"This is in SConstruct" should not be output. This means ValidateOptions() did not error out before this was printed', +) # Now we'll test having ValidateOptions raise a SConsBadOptionError exception -test.run(arguments="--garbage=xyz raise=1", status=2, - stderr=".*SConsBadOptionError: no such option: no such option: --garbage.*", - match=TestSCons.match_re_dotall) -test.fail_test(("This is in SConstruct" in test.stdout()), - message='"This is in SConstruct" should not be output. This means ValidateOptions() did not error out before this was printed') +test.run( + arguments="--garbage=xyz raise=1", + status=2, + stderr=".*SConsBadOptionError: no such option: no such option: --garbage.*", + match=TestSCons.match_re_dotall, +) +test.fail_test( + ("This is in SConstruct" in test.stdout()), + message='"This is in SConstruct" should not be output. This means ValidateOptions() did not error out before this was printed', +) -# Now we'll test having ValidateOptions raise a SConsBadOptionError exception and catching that exception -test.run(arguments="--garbage=xyz raise=2", status=3, - stdout=".*Parser is SConsOptionParser:True.*Message is .no such option. --garbage.*", - match=TestSCons.match_re_dotall) -test.fail_test(("This is in SConstruct" in test.stdout()), - message='"This is in SConstruct" should not be output. This means ValidateOptions() did not error out before this was printed') +# Now we'll test having ValidateOptions raise a SConsBadOptionError +# exception and catching that exception +test.run( + arguments="--garbage=xyz raise=2", + status=3, + stdout=".*Parser is SConsOptionParser: True.*Message is. no such option. --garbage.*", + match=TestSCons.match_re_dotall, +) +test.fail_test( + ("This is in SConstruct" in test.stdout()), + message='"This is in SConstruct" should not be output. This means ValidateOptions() did not error out before this was printed', +) + +test.pass_test() # Local Variables: # tab-width:4 diff --git a/test/fixture/SConstruct-check-valid-options b/test/fixture/SConstruct-check-valid-options index 2c935a23c..53bdf89d3 100644 --- a/test/fixture/SConstruct-check-valid-options +++ b/test/fixture/SConstruct-check-valid-options @@ -1,3 +1,7 @@ +# SPDX-License-Identifier: MIT +# +# Copyright The SCons Foundation + import sys from SCons.Script.SConsOptions import SConsOptionParser, SConsBadOptionError @@ -12,8 +16,10 @@ elif ARGUMENTS.get('raise', 0) == '2': try: ValidateOptions(throw_exception=True) except SConsBadOptionError as e: - print("Parser is SConsOptionParser:%s" % (isinstance(e.parser, SConsOptionParser))) - print("Message is :%s" % e.opt_str) + print( + f"Parser is SConsOptionParser: {isinstance(e.parser, SConsOptionParser)}" + ) + print(f"Message is: {e.opt_str}") Exit(3) else: ValidateOptions() diff --git a/test/import.py b/test/import.py index 55a40cc43..50d7b2178 100644 --- a/test/import.py +++ b/test/import.py @@ -128,23 +128,26 @@ if moc: import os.path qtdir = os.path.dirname(os.path.dirname(moc)) - - qt_err = r""" -scons: warning: Could not detect qt, using moc executable as a hint \(QTDIR=%(qtdir)s\) -""" % locals() - + qt3_err = fr""" +scons: warning: Could not detect qt3, using moc executable as a hint \(QT3DIR={qtdir}\) +""" else: + qt3_err = r""" +scons: warning: Could not detect qt3, using empty QT3DIR +""" - qt_err = """ -scons: warning: Could not detect qt, using empty QTDIR +qt_moved = r""" +scons: \*\*\* Deprecated tool 'qt' renamed to 'qt3'. Please update your build accordingly. 'qt3' will be removed entirely in a future release. """ -qt_warnings = [ re.compile(qt_err + TestSCons.file_expr) ] +qt3_warnings = [re.compile(qt3_err + TestSCons.file_expr)] +qt_error = [re.compile(qt_moved + TestSCons.file_expr)] error_output = { - 'icl' : intel_warnings, - 'intelc' : intel_warnings, - 'qt' : qt_warnings, + 'icl': intel_warnings, + 'intelc': intel_warnings, + 'qt3': qt3_warnings, + 'qt': qt_error, } # An SConstruct for importing Tool names that have illegal characters @@ -178,16 +181,16 @@ for tool in tools: test.write('SConstruct', indirect_import % locals()) else: test.write('SConstruct', direct_import % locals()) - test.run(stderr=None) + test.run(stderr=None, status=None) stderr = test.stderr() - if stderr: + if stderr or test.status: matched = None for expression in error_output.get(tool, []): if expression.match(stderr): matched = 1 break if not matched: - print("Failed importing '%s', stderr:" % tool) + print(f"Failed importing '{tool}', stderr:") print(stderr) failures.append(tool) diff --git a/test/runtest/SCons.py b/test/runtest/SCons.py index 20c4c6418..fc4c3e06c 100644 --- a/test/runtest/SCons.py +++ b/test/runtest/SCons.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Verify that we find tests under the SCons/ tree only if they end @@ -46,17 +45,17 @@ test.write_passing_test(['SCons', 'passTests.py']) test.write_passing_test(['SCons', 'suite', 'pass.py']) test.write_passing_test(['SCons', 'suite', 'passTests.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(src_passTests_py)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {src_passTests_py} PASSING TEST STDOUT -%(pythonstring)s%(pythonflags)s %(src_suite_passTests_py)s +{pythonstring}{pythonflags} {src_suite_passTests_py} PASSING TEST STDOUT -""" % locals() +""" expect_stderr = """\ PASSING TEST STDERR PASSING TEST STDERR -""" % locals() +""" test.run(arguments='-k SCons', stdout=expect_stdout, stderr=expect_stderr) diff --git a/test/runtest/baseline/combined.py b/test/runtest/baseline/combined.py index 228d42d1a..00ce85bdf 100644 --- a/test/runtest/baseline/combined.py +++ b/test/runtest/baseline/combined.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test a combination of a passing test, failing test, and no-result @@ -42,27 +41,24 @@ test_pass_py = os.path.join('test', 'pass.py') test = TestRuntest.TestRuntest() test.subdir('test') - test.write_failing_test(['test', 'fail.py']) - test.write_no_result_test(['test', 'no_result.py']) - test.write_passing_test(['test', 'pass.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(test_fail_py)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_fail_py} FAILING TEST STDOUT -%(pythonstring)s%(pythonflags)s %(test_no_result_py)s +{pythonstring}{pythonflags} {test_no_result_py} NO RESULT TEST STDOUT -%(pythonstring)s%(pythonflags)s %(test_pass_py)s +{pythonstring}{pythonflags} {test_pass_py} PASSING TEST STDOUT Failed the following test: -\t%(test_fail_py)s +\t{test_fail_py} NO RESULT from the following test: -\t%(test_no_result_py)s -""" % locals() +\t{test_no_result_py} +""" expect_stderr = """\ FAILING TEST STDERR @@ -70,10 +66,7 @@ NO RESULT TEST STDERR PASSING TEST STDERR """ -test.run(arguments='-k -b . test', - status=1, - stdout=expect_stdout, - stderr=expect_stderr) +test.run(arguments='-k -b . test', status=1, stdout=expect_stdout, stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/baseline/fail.py b/test/runtest/baseline/fail.py index e2aff4a22..2268dce84 100644 --- a/test/runtest/baseline/fail.py +++ b/test/runtest/baseline/fail.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,38 +22,39 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test how we handle a failing test specified on the command line. """ +import os + import TestRuntest pythonstring = TestRuntest.pythonstring pythonflags = TestRuntest.pythonflags +test_fail_py = os.path.join('test', 'fail.py') test = TestRuntest.TestRuntest() test.subdir('test') - test.write_failing_test(['test', 'fail.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s test/fail.py +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_fail_py} FAILING TEST STDOUT -""" % locals() +""" expect_stderr = """\ FAILING TEST STDERR """ -test.run(arguments='-k -b . test/fail.py', - status=1, - stdout=expect_stdout, - stderr=expect_stderr) +test.run( + arguments='-k -b . test/fail.py', + status=1, + stdout=expect_stdout, + stderr=expect_stderr, +) test.pass_test() diff --git a/test/runtest/baseline/no_result.py b/test/runtest/baseline/no_result.py index d00f5364f..ce6f20cbb 100644 --- a/test/runtest/baseline/no_result.py +++ b/test/runtest/baseline/no_result.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,43 +22,45 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test how we handle a no-results test specified on the command line. """ +import os + import TestRuntest pythonstring = TestRuntest.pythonstring pythonflags = TestRuntest.pythonflags +test_no_result_py = os.path.join('test', 'no_result.py') test = TestRuntest.TestRuntest() - test.subdir('test') - test.write_no_result_test(['test', 'no_result.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s test/no_result.py +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_no_result_py} NO RESULT TEST STDOUT -""" % locals() +""" expect_stderr = """\ NO RESULT TEST STDERR """ -test.run(arguments='--no-ignore-skips -k -b . test/no_result.py', - status=2, - stdout=expect_stdout, - stderr=expect_stderr) +test.run( + arguments='--no-ignore-skips -k -b . test/no_result.py', + status=2, + stdout=expect_stdout, + stderr=expect_stderr, +) -test.run(arguments='-k -b . test/no_result.py', - status=0, - stdout=expect_stdout, - stderr=expect_stderr) +test.run( + arguments='-k -b . test/no_result.py', + status=0, + stdout=expect_stdout, + stderr=expect_stderr, +) test.pass_test() diff --git a/test/runtest/baseline/pass.py b/test/runtest/baseline/pass.py index 481fc9791..c31a6d6a8 100644 --- a/test/runtest/baseline/pass.py +++ b/test/runtest/baseline/pass.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test how we handle a passing test specified on the command line. @@ -42,18 +41,16 @@ test.subdir('test') test.write_passing_test(['test', 'pass.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(test_pass_py)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_pass_py} PASSING TEST STDOUT -""" % locals() +""" expect_stderr = """\ PASSING TEST STDERR """ -test.run(arguments='-k -b . test', - stdout=expect_stdout, - stderr=expect_stderr) +test.run(arguments='-k -b . test', stdout=expect_stdout, stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/faillog.py b/test/runtest/faillog.py index e2ca67e63..f23b90bc7 100644 --- a/test/runtest/faillog.py +++ b/test/runtest/faillog.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test a list of tests in failed_tests.log to run with the --retry option @@ -42,15 +41,15 @@ test.subdir('test') test.write_failing_test(test_fail_py) test.write_passing_test(test_pass_py) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(test_fail_py)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_fail_py} FAILING TEST STDOUT -%(pythonstring)s%(pythonflags)s %(test_pass_py)s +{pythonstring}{pythonflags} {test_pass_py} PASSING TEST STDOUT Failed the following test: -\t%(test_fail_py)s -""" % locals() +\t{test_fail_py} +""" expect_stderr = """\ FAILING TEST STDERR diff --git a/test/runtest/no_faillog.py b/test/runtest/no_faillog.py index db17c8edf..174ab48c9 100644 --- a/test/runtest/no_faillog.py +++ b/test/runtest/no_faillog.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test a list of tests in failed_tests.log to run with the --retry option @@ -42,19 +41,22 @@ test.subdir('test') test.write_failing_test(test_fail_py) test.write_passing_test(test_pass_py) -test.write('failed_tests.log', """\ -%(test_fail_py)s -""" % locals()) +test.write( + 'failed_tests.log', + f"""\ +{test_fail_py} +""", +) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(test_fail_py)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_fail_py} FAILING TEST STDOUT -%(pythonstring)s%(pythonflags)s %(test_pass_py)s +{pythonstring}{pythonflags} {test_pass_py} PASSING TEST STDOUT Failed the following test: -\t%(test_fail_py)s -""" % locals() +\t{test_fail_py} +""" expect_stderr = """\ FAILING TEST STDERR diff --git a/test/runtest/pathseps.py b/test/runtest/pathseps.py new file mode 100644 index 000000000..10d86b22e --- /dev/null +++ b/test/runtest/pathseps.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# +# MIT License +# +# Copyright The SCons Foundation +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" +Make sure different path separators don't break things. +Backslashes should be okay on POSIX, forwards slashes on win32, +and combinations should cause no problems. +""" + +import os.path + +import TestRuntest + +# the "expected" paths are generated os-native +test_one_py = os.path.join('test', 'subdir', 'test1.py') +test_two_py = os.path.join('test', 'subdir', 'test2.py') +test_three_py = os.path.join('test', 'subdir', 'test3.py') +test_four_py = os.path.join('test', 'subdir', 'test4.py') + +test = TestRuntest.TestRuntest() +# create files for discovery +testdir = "test/subdir".split("/") +test.subdir(testdir[0], testdir) +test.write_passing_test(testdir + ['test1.py']) +test.write_passing_test(testdir + ['test2.py']) +test.write_passing_test(testdir + ['test3.py']) +test.write_passing_test(testdir + ['test4.py']) + +# discover tests using testlist file with various combinations of slashes +test.write( + 'testlist.txt', + r""" +test/subdir/test1.py +test\subdir/test2.py +test/subdir\test3.py +test\subdir\test4.py +""", +) + +# expect the discovered files to all be os-native +expect_stdout = f"""\ +{test_one_py} +{test_two_py} +{test_three_py} +{test_four_py} +""" + +test.run(arguments="-k -l -f testlist.txt", stdout=expect_stdout, stderr=None) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/runtest/print_time.py b/test/runtest/print_time.py index 834d2ae45..3d49a9702 100644 --- a/test/runtest/print_time.py +++ b/test/runtest/print_time.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test a combination of a passing test, failing test, and no-result @@ -41,30 +40,30 @@ test_fail_py = re.escape(os.path.join('test', 'fail.py')) test_no_result_py = re.escape(os.path.join('test', 'no_result.py')) test_pass_py = re.escape(os.path.join('test', 'pass.py')) -test = TestRuntest.TestRuntest(match = TestCmd.match_re) +test = TestRuntest.TestRuntest(match=TestCmd.match_re) test.subdir('test') test.write_failing_test(['test', 'fail.py']) test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(test_fail_py)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_fail_py} FAILING TEST STDOUT Test execution time: \\d+.\\d seconds -%(pythonstring)s%(pythonflags)s %(test_no_result_py)s +{pythonstring}{pythonflags} {test_no_result_py} NO RESULT TEST STDOUT Test execution time: \\d+.\\d seconds -%(pythonstring)s%(pythonflags)s %(test_pass_py)s +{pythonstring}{pythonflags} {test_pass_py} PASSING TEST STDOUT Test execution time: \\d+.\\d seconds Total execution time for all tests: \\d+.\\d seconds Failed the following test: -\t%(test_fail_py)s +\t{test_fail_py} NO RESULT from the following test: -\t%(test_no_result_py)s -""" % locals() +\t{test_no_result_py} +""" expect_stderr = """\ FAILING TEST STDERR @@ -72,10 +71,7 @@ NO RESULT TEST STDERR PASSING TEST STDERR """ -test.run(arguments='-k -t test', - status=1, - stdout=expect_stdout, - stderr=expect_stderr) +test.run(arguments='-k -t test', status=1, stdout=expect_stdout, stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/python.py b/test/runtest/python.py index abd4f0cba..dbb24ca1a 100644 --- a/test/runtest/python.py +++ b/test/runtest/python.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test that the -P option lets us specify a Python version to use. @@ -46,26 +45,26 @@ head, dir = os.path.split(head) # python version then in use, which could be different pythonflags = TestRuntest.pythonflags -# We have to normalize the python path here, because some installations don't like -# getting called with "/bin/../bin/python" as first argument, e.g. Fedora 17 Desktop. +# We have to normalize the python path here, because some installations +# don't like getting called with "/bin/../bin/python" as first argument, +# e.g. Fedora 17 Desktop. mypython = os.path.normpath(os.path.join(head, dir, os.path.pardir, dir, python)) test.subdir('test') - test.write_passing_test(['test', 'pass.py']) -expect_stdout = """\ -%(mypython)s%(pythonflags)s %(test_pass_py)s +expect_stdout = f"""\ +{mypython}{pythonflags} {test_pass_py} PASSING TEST STDOUT -""" % locals() +""" expect_stderr = """\ PASSING TEST STDERR """ -test.run(arguments=['-k','-P', mypython, 'test'], - stdout=expect_stdout, - stderr=expect_stderr) +test.run( + arguments=['-k', '-P', mypython, 'test'], stdout=expect_stdout, stderr=expect_stderr +) test.pass_test() diff --git a/test/runtest/retry.py b/test/runtest/retry.py index 4280152db..0c5beb694 100644 --- a/test/runtest/retry.py +++ b/test/runtest/retry.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test a list of tests in failed_tests.log to run with the --retry option @@ -45,14 +44,17 @@ test.write_failing_test(['test', 'fail.py']) test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) -test.write('failed_tests.log', """\ -%(test_fail_py)s -""" % locals()) +test.write( + 'failed_tests.log', + f"""\ +{test_fail_py} +""", +) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(test_fail_py)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_fail_py} FAILING TEST STDOUT -""" % locals() +""" expect_stderr = """\ FAILING TEST STDERR diff --git a/test/runtest/simple/combined.py b/test/runtest/simple/combined.py index a54e57c12..e594c5048 100644 --- a/test/runtest/simple/combined.py +++ b/test/runtest/simple/combined.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test a combination of a passing test, failing test, and no-result @@ -45,20 +44,20 @@ test.write_failing_test(test_fail_py) test.write_no_result_test(test_no_result_py) test.write_passing_test(test_pass_py) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(test_fail_py)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_fail_py} FAILING TEST STDOUT -%(pythonstring)s%(pythonflags)s %(test_no_result_py)s +{pythonstring}{pythonflags} {test_no_result_py} NO RESULT TEST STDOUT -%(pythonstring)s%(pythonflags)s %(test_pass_py)s +{pythonstring}{pythonflags} {test_pass_py} PASSING TEST STDOUT Failed the following test: -\t%(test_fail_py)s +\t{test_fail_py} NO RESULT from the following test: -\t%(test_no_result_py)s -""" % locals() +\t{test_no_result_py} +""" expect_stderr = """\ FAILING TEST STDERR @@ -66,12 +65,7 @@ NO RESULT TEST STDERR PASSING TEST STDERR """ -test.run( - arguments='-k test', - status=1, - stdout=expect_stdout, - stderr=expect_stderr -) +test.run(arguments='-k test', status=1, stdout=expect_stdout, stderr=expect_stderr) test.must_exist('failed_tests.log') test.must_contain('failed_tests.log', test_fail_py) diff --git a/test/runtest/simple/fail.py b/test/runtest/simple/fail.py index f26f00e9a..5e1979a1b 100644 --- a/test/runtest/simple/fail.py +++ b/test/runtest/simple/fail.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,38 +22,35 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test how we handle a failing test specified on the command line. """ +import os + import TestRuntest pythonstring = TestRuntest.pythonstring pythonflags = TestRuntest.pythonflags +test_fail_py = os.path.join('test', 'fail.py') test = TestRuntest.TestRuntest() - test.subdir('test') - test.write_failing_test(['test', 'fail.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s test/fail.py +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_fail_py} FAILING TEST STDOUT -""" % locals() +""" expect_stderr = """\ FAILING TEST STDERR """ -test.run(arguments='-k test/fail.py', - status=1, - stdout=expect_stdout, - stderr=expect_stderr) +test.run( + arguments='-k test/fail.py', status=1, stdout=expect_stdout, stderr=expect_stderr +) test.pass_test() diff --git a/test/runtest/simple/no_result.py b/test/runtest/simple/no_result.py index 33f28e4a9..beb82b01c 100644 --- a/test/runtest/simple/no_result.py +++ b/test/runtest/simple/no_result.py @@ -27,35 +27,40 @@ Test how we handle a no-results test specified on the command line. """ +import os + import TestRuntest pythonstring = TestRuntest.pythonstring pythonflags = TestRuntest.pythonflags +test_no_result_py = os.path.join('test', 'no_result.py') test = TestRuntest.TestRuntest() - test.subdir('test') - test.write_no_result_test(['test', 'no_result.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s test/no_result.py +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_no_result_py} NO RESULT TEST STDOUT -""" % locals() +""" expect_stderr = """\ NO RESULT TEST STDERR """ -test.run(arguments='--no-ignore-skips -k test/no_result.py', - status=2, - stdout=expect_stdout, - stderr=expect_stderr) +test.run( + arguments='--no-ignore-skips -k test/no_result.py', + status=2, + stdout=expect_stdout, + stderr=expect_stderr, +) -test.run(arguments='-k test/no_result.py', - status=0, - stdout=expect_stdout, - stderr=expect_stderr) +test.run( + arguments='-k test/no_result.py', + status=0, + stdout=expect_stdout, + stderr=expect_stderr, +) test.pass_test() diff --git a/test/runtest/simple/pass.py b/test/runtest/simple/pass.py index 7ceb9a054..408ef4c28 100644 --- a/test/runtest/simple/pass.py +++ b/test/runtest/simple/pass.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,29 +22,27 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test how we handle a passing test specified on the command line. """ +import os + import TestRuntest pythonstring = TestRuntest.pythonstring pythonflags = TestRuntest.pythonflags +test_pass_py = os.path.join('test', 'pass.py') test = TestRuntest.TestRuntest() - test.subdir('test') - test.write_passing_test(['test', 'pass.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s test/pass.py +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_pass_py} PASSING TEST STDOUT -""" % locals() +""" expect_stderr = """\ PASSING TEST STDERR diff --git a/test/runtest/testargv.py b/test/runtest/testargv.py index 22e57e83b..20dcdc848 100644 --- a/test/runtest/testargv.py +++ b/test/runtest/testargv.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test subdir args for runtest.py, for example: @@ -38,34 +37,35 @@ import TestRuntest test = TestRuntest.TestRuntest() test.subdir('test', ['test', 'subdir']) -files = {} -files['pythonstring'] = TestRuntest.pythonstring -files['pythonflags'] = TestRuntest.pythonflags +pythonstring = TestRuntest.pythonstring +pythonflags = TestRuntest.pythonflags -files['one'] = os.path.join('test/subdir', 'test_one.py') -files['two'] = os.path.join('test/subdir', 'two.py') -files['three'] = os.path.join('test', 'test_three.py') +one = os.path.join('test', 'subdir', 'test_one.py') +two = os.path.join('test', 'subdir', 'two.py') +three = os.path.join('test', 'test_three.py') -test.write_passing_test(files['one']) -test.write_passing_test(files['two']) -test.write_passing_test(files['three']) +test.write_passing_test(['test', 'subdir', 'test_one.py']) +test.write_passing_test(['test', 'subdir', 'two.py']) +test.write_passing_test(['test', 'test_three.py']) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(one)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {one} PASSING TEST STDOUT -%(pythonstring)s%(pythonflags)s %(two)s +{pythonstring}{pythonflags} {two} PASSING TEST STDOUT -""" % files +""" expect_stderr = """\ PASSING TEST STDERR PASSING TEST STDERR """ -test.run(arguments = '--no-progress test/subdir', - status = 0, - stdout = expect_stdout, - stderr = expect_stderr) +test.run( + arguments='--no-progress test/subdir', + status=0, + stdout=expect_stdout, + stderr=expect_stderr, +) test.pass_test() diff --git a/test/runtest/testlistfile.py b/test/runtest/testlistfile.py index 5c956b8e3..e5d85b8dc 100644 --- a/test/runtest/testlistfile.py +++ b/test/runtest/testlistfile.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test a list of tests to run in a file specified with the -f option. @@ -46,15 +45,18 @@ test.write_failing_test(['test', 'fail.py']) test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) -test.write('t.txt', """\ -#%(test_fail_py)s -%(test_pass_py)s -""" % locals()) +test.write( + 't.txt', + f"""\ +#{test_fail_py} +{test_pass_py} +""", +) -expect_stdout = """\ -%(pythonstring)s%(pythonflags)s %(test_pass_py)s +expect_stdout = f"""\ +{pythonstring}{pythonflags} {test_pass_py} PASSING TEST STDOUT -""" % locals() +""" expect_stderr = """\ PASSING TEST STDERR diff --git a/test/runtest/xml/output.py b/test/runtest/xml/output.py index cd20dbdf9..66ec6562b 100644 --- a/test/runtest/xml/output.py +++ b/test/runtest/xml/output.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ Test writing XML output to a file. @@ -34,8 +33,7 @@ import re import TestCmd import TestRuntest -test = TestRuntest.TestRuntest(match = TestCmd.match_re, - diff = TestCmd.diff_re) +test = TestRuntest.TestRuntest(match=TestCmd.match_re, diff=TestCmd.diff_re) pythonstring = re.escape(TestRuntest.pythonstring) pythonflags = TestRuntest.pythonflags @@ -44,22 +42,18 @@ test_no_result_py = re.escape(os.path.join('test', 'no_result.py')) test_pass_py = re.escape(os.path.join('test', 'pass.py')) test.subdir('test') - test.write_fake_scons_source_tree() - test.write_failing_test(['test', 'fail.py']) - test.write_no_result_test(['test', 'no_result.py']) - test.write_passing_test(['test', 'pass.py']) -test.run(arguments = '--xml xml.out test', status=1) +test.run(arguments='--xml xml.out test', status=1) -expect = """\ +expect = f"""\ <results> <test> - <file_name>%(test_fail_py)s</file_name> - <command_line>%(pythonstring)s%(pythonflags)s %(test_fail_py)s</command_line> + <file_name>{test_fail_py}</file_name> + <command_line>{pythonstring}{pythonflags} {test_fail_py}</command_line> <exit_status>1</exit_status> <stdout>FAILING TEST STDOUT </stdout> @@ -68,8 +62,8 @@ expect = """\ <time>\\d+\\.\\d</time> </test> <test> - <file_name>%(test_no_result_py)s</file_name> - <command_line>%(pythonstring)s%(pythonflags)s %(test_no_result_py)s</command_line> + <file_name>{test_no_result_py}</file_name> + <command_line>{pythonstring}{pythonflags} {test_no_result_py}</command_line> <exit_status>2</exit_status> <stdout>NO RESULT TEST STDOUT </stdout> @@ -78,8 +72,8 @@ expect = """\ <time>\\d+\\.\\d</time> </test> <test> - <file_name>%(test_pass_py)s</file_name> - <command_line>%(pythonstring)s%(pythonflags)s %(test_pass_py)s</command_line> + <file_name>{test_pass_py}</file_name> + <command_line>{pythonstring}{pythonflags} {test_pass_py}</command_line> <exit_status>0</exit_status> <stdout>PASSING TEST STDOUT </stdout> @@ -89,7 +83,7 @@ expect = """\ </test> <time>\\d+\\.\\d</time> </results> -""" % locals() +""" # Just strip carriage returns so the regular expression matching works. contents = test.read('xml.out') diff --git a/test/textfile/fixture/SConstruct b/test/textfile/fixture/SConstruct index 60e7225a0..b2466870f 100644 --- a/test/textfile/fixture/SConstruct +++ b/test/textfile/fixture/SConstruct @@ -2,7 +2,8 @@ DefaultEnvironment(tools=[]) env = Environment(tools=['textfile']) data0 = ['Goethe', 'Schiller'] -data = ['lalala', 42, data0, 'tanteratei'] +data = ['lalala', 42, data0, 'tanteratei', + '×'] # <-- this is unicode /xd7 symbol env.Textfile('foo1', data) env.Textfile('foo2', data, LINESEPARATOR='|*') diff --git a/test/textfile/textfile.py b/test/textfile/textfile.py index a2d005cfb..d7d19e5e2 100644 --- a/test/textfile/textfile.py +++ b/test/textfile/textfile.py @@ -34,7 +34,8 @@ test = TestSCons.TestSCons() # foo1a = test.workpath('foo1a.txt') # foo2a = test.workpath('foo2a.txt') -match_mode = 'r' +# Must be read binary as now we're including unicode characters in our textparts +match_mode = 'rb' test.file_fixture('fixture/SConstruct', 'SConstruct') @@ -44,7 +45,8 @@ linesep = '\n' textparts = ['lalala', '42', 'Goethe', 'Schiller', - 'tanteratei'] + 'tanteratei', + '×'] # <-- this is unicode /xd7 symbol foo1Text = linesep.join(textparts) foo2Text = '|*'.join(textparts) foo1aText = foo1Text + linesep |