diff options
| author | William Deegan <bill@baddogconsulting.com> | 2015-09-21 17:03:12 (GMT) |
|---|---|---|
| committer | William Deegan <bill@baddogconsulting.com> | 2015-09-21 17:03:12 (GMT) |
| commit | 0941093e0e5a030faa49968457638a3a6aee7ad8 (patch) | |
| tree | 6d33513c14eb6eac0531dd050de0ecca4c39bd79 /test/CPPDEFINES | |
| download | SCons-2.4.0.zip SCons-2.4.0.tar.gz SCons-2.4.0.tar.bz2 | |
release 2.4.02.4.0
Diffstat (limited to 'test/CPPDEFINES')
| -rw-r--r-- | test/CPPDEFINES/append.py | 225 | ||||
| -rw-r--r-- | test/CPPDEFINES/basic.py | 70 | ||||
| -rw-r--r-- | test/CPPDEFINES/live.py | 90 | ||||
| -rw-r--r-- | test/CPPDEFINES/pkg-config.py | 103 | ||||
| -rw-r--r-- | test/CPPDEFINES/scan.py | 187 | ||||
| -rw-r--r-- | test/CPPDEFINES/undefined.py | 51 |
6 files changed, 726 insertions, 0 deletions
diff --git a/test/CPPDEFINES/append.py b/test/CPPDEFINES/append.py new file mode 100644 index 0000000..6e69d09 --- /dev/null +++ b/test/CPPDEFINES/append.py @@ -0,0 +1,225 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# 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. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify appending to CPPPDEFINES with various data types. +See also pkg-config.py in this dir. +""" + +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') + +# http://scons.tigris.org/issues/show_bug.cgi?id=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') + +# http://scons.tigris.org/issues/show_bug.cgi?id=1152 +# http://scons.tigris.org/issues/show_bug.cgi?id=2900 +cases=[('string', 'FOO'), + ('list', ['NAME1', 'NAME2']), + ('list-of-2lists', [('NAME1','VAL1'), ['NAME2','VAL2']]), + ('dict', {'NAME1' : 'VAL1', 'NAME2' : 'VAL2', 'NAME3' : None}) + ] + +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) +""") + + +expect_print_output="""\ +-DFOO -Dvalue=1 +-Dfoo -Dbar +-Dfoo -Dbar +==== Testing CPPDEFINES, appending a string to a string + orig = FOO, append = FOO +Append: + result=['FOO', 'FOO'] + final=-DFOO -DFOO +AppendUnique: + result=['FOO'] + final=-DFOO +==== Testing CPPDEFINES, appending a list to a string + orig = FOO, append = ['NAME1', 'NAME2'] +Append: + result=['FOO', 'NAME1', 'NAME2'] + final=-DFOO -DNAME1 -DNAME2 +AppendUnique: + result=[('FOO',), ('NAME1',), ('NAME2',)] + final=-DFOO -DNAME1 -DNAME2 +==== Testing CPPDEFINES, appending a list-of-2lists to a string + orig = FOO, append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Append: + 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 +==== Testing CPPDEFINES, appending a dict to a string + 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', ('NAME1', 'VAL1')] + final=-DFOO -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +==== Testing CPPDEFINES, appending a string to a list + orig = ['NAME1', 'NAME2'], append = FOO +Append: + result=['NAME1', 'NAME2', 'FOO'] + final=-DNAME1 -DNAME2 -DFOO +AppendUnique: + result=[('NAME1',), ('NAME2',), ('FOO',)] + final=-DNAME1 -DNAME2 -DFOO +==== Testing CPPDEFINES, appending a list to a list + orig = ['NAME1', 'NAME2'], append = ['NAME1', 'NAME2'] +Append: + result=['NAME1', 'NAME2', 'NAME1', 'NAME2'] + final=-DNAME1 -DNAME2 -DNAME1 -DNAME2 +AppendUnique: + result=[('NAME1',), ('NAME2',)] + final=-DNAME1 -DNAME2 +==== Testing CPPDEFINES, appending a list-of-2lists to a list + orig = ['NAME1', 'NAME2'], append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] +Append: + result=['NAME1', 'NAME2', ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME1 -DNAME2 -DNAME1=VAL1 -DNAME2=VAL2 +AppendUnique: + result=[('NAME1',), ('NAME2',), ('NAME1', 'VAL1'), ('NAME2', 'VAL2')] + final=-DNAME1 -DNAME2 -DNAME1=VAL1 -DNAME2=VAL2 +==== Testing CPPDEFINES, appending a dict to a list + orig = ['NAME1', 'NAME2'], append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} +Append: + result=['NAME1', 'NAME2', {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}] + final=-DNAME1 -DNAME2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +AppendUnique: + result=[('NAME1',), ('NAME2',), ('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1')] + final=-DNAME1 -DNAME2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +==== Testing CPPDEFINES, appending a string to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = FOO +Append: + 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 +==== Testing CPPDEFINES, appending a list to a list-of-2lists + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = ['NAME1', 'NAME2'] +Append: + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], 'NAME1', 'NAME2'] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1 -DNAME2 +AppendUnique: + result=[('NAME1', 'VAL1'), ('NAME2', 'VAL2'), ('NAME1',), ('NAME2',)] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME1 -DNAME2 +==== 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 +AppendUnique: + 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 +AppendUnique: + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 +==== Testing CPPDEFINES, appending a string to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = FOO +Append: + result={'FOO': None, 'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} + final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 +AppendUnique: + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), 'FOO'] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DFOO +==== Testing CPPDEFINES, appending a list to a dict + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = ['NAME1', 'NAME2'] +Append: + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), 'NAME1', 'NAME2'] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1 -DNAME2 +AppendUnique: + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), ('NAME1',), ('NAME2',)] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1 -DNAME2 +==== 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 +AppendUnique: + result=[('NAME2', 'VAL2'), ('NAME3',), ('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 +AppendUnique: + result={'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 +""" + +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/basic.py b/test/CPPDEFINES/basic.py new file mode 100644 index 0000000..b54a421 --- /dev/null +++ b/test/CPPDEFINES/basic.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# 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. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify basic use of CPPPDEFINES with various data types. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """\ +test_list = [ + 'xyz', + ['x', 'y', 'z'], + ['x', ['y', 123], 'z', ('int', '$INTEGER')], + { 'c' : 3, 'b': None, 'a' : 1 }, +] +for i in test_list: + env = Environment(CPPDEFPREFIX='-D', CPPDEFSUFFIX='', INTEGER=0) + print env.Clone(CPPDEFINES=i).subst('$_CPPDEFFLAGS') +for i in test_list: + env = Environment(CPPDEFPREFIX='|', CPPDEFSUFFIX='|', INTEGER=1) + print env.Clone(CPPDEFINES=i).subst('$_CPPDEFFLAGS') +""") + +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 +|xyz| +|x| |y| |z| +|x| |y=123| |z| |int=1| +|a=1| |b| |c=3| +""") + +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/live.py b/test/CPPDEFINES/live.py new file mode 100644 index 0000000..0c7ad78 --- /dev/null +++ b/test/CPPDEFINES/live.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# 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. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify basic use of CPPDEFINES with live compilation. +""" + +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') +""") + +test.write('prog.c', r""" +#include <stdio.h> +#include <stdlib.h> + +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; +#ifdef FOO + printf("prog.c: FOO %d\n", VAL); +#endif +#ifdef BAR + printf("prog.c: BAR %d\n", VAL); +#endif + exit (0); +} +""") + +test.write('baz.cpp', r"""\ +#include <stdio.h> +#include <stdlib.h> +int +main(int argc, char *argv[]) +{ +#ifdef BAZ + printf("baz.cpp: BAZ %d\n", VAL); +#endif + return(0); +} +""") + + +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() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/CPPDEFINES/pkg-config.py b/test/CPPDEFINES/pkg-config.py new file mode 100644 index 0000000..0656900 --- /dev/null +++ b/test/CPPDEFINES/pkg-config.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# 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. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify merging with MergeFlags to CPPPDEFINES with various data types. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +if not test.where_is('pkg-config'): + test.skip_test("Could not find 'pkg-config' in system PATH, skipping test.\n") + +test.write('bug.pc', """\ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: bug +Description: A test case .pc file +Version: 1.2 +Cflags: -DSOMETHING -DVARIABLE=2 +""") + +test.write('main.c', """\ +int main(int argc, char *argv[]) +{ + return 0; +} +""") + +test.write('SConstruct', """\ +# http://scons.tigris.org/issues/show_bug.cgi?id=2671 +# Passing test cases +env_1 = Environment(CPPDEFINES=[('DEBUG','1'), 'TEST']) +env_1.ParseConfig('PKG_CONFIG_PATH=. pkg-config --cflags bug') +print env_1.subst('$_CPPDEFFLAGS') + +env_2 = Environment(CPPDEFINES=[('DEBUG','1'), 'TEST']) +env_2.MergeFlags('-DSOMETHING -DVARIABLE=2') +print env_2.subst('$_CPPDEFFLAGS') + +# Failing test cases +env_3 = Environment(CPPDEFINES={'DEBUG':1, 'TEST':None}) +env_3.ParseConfig('PKG_CONFIG_PATH=. pkg-config --cflags bug') +print env_3.subst('$_CPPDEFFLAGS') + +env_4 = Environment(CPPDEFINES={'DEBUG':1, 'TEST':None}) +env_4.MergeFlags('-DSOMETHING -DVARIABLE=2') +print env_4.subst('$_CPPDEFFLAGS') + +# http://scons.tigris.org/issues/show_bug.cgi?id=1738 +env_1738_1 = Environment(tools=['default']) +env_1738_1.ParseConfig('PKG_CONFIG_PATH=. pkg-config --cflags --libs bug') +env_1738_1.Append(CPPDEFINES={'value' : '1'}) +print env_1738_1.subst('$_CPPDEFFLAGS') +""") + +expect_print_output="""\ +-DDEBUG=1 -DTEST -DSOMETHING -DVARIABLE=2 +-DDEBUG=1 -DTEST -DSOMETHING -DVARIABLE=2 +-DDEBUG=1 -DTEST -DSOMETHING -DVARIABLE=2 +-DDEBUG=1 -DTEST -DSOMETHING -DVARIABLE=2 +-DSOMETHING -DVARIABLE=2 -Dvalue=1 +""" + +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 new file mode 100644 index 0000000..5318642 --- /dev/null +++ b/test/CPPDEFINES/scan.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# 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. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify that use of the Scanner that evaluates CPP lines works as expected. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +m = 'Scanner evaluation of CPP lines not yet supported; skipping test.\n' +test.skip_test(m) + +f1_exe = 'f1' + TestSCons._exe +f2_exe = 'f2' + TestSCons._exe +f3_exe = 'f3' + TestSCons._exe +f4_exe = 'f4' + TestSCons._exe + +test.write('SConstruct', """\ +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}) + +env.Program('f1', ['prog.c', f1]) +env.Program('f2', ['prog.c', f2]) +env.Program('f3', ['prog.c', f3]) +env.Program('f4', ['prog.c', f4]) +""") + +test.write('f1.h', """ +#define STRING "F1" +""") + +test.write('f2.h', """ +#define STRING "F2" +""") + +test.write('f3.h', """ +#define STRING "F3" +""") + +test.write('f4.h', """ +#define STRING "F4" +""") + +test.write('fff.c', """ +#ifdef F1 +#include <f1.h> +#endif +#if F2 +#include <f2.h> +#endif +#ifdef F3 +#include <f3.h> +#endif +#ifdef F4 +#include <f4.h> +#endif + +char * +foo(void) +{ + return (STRING); +} +""") + + +test.write('prog.c', r""" +#include <stdio.h> +#include <stdlib.h> + +extern char *foo(void); + +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + printf("prog.c: %s\n", foo()); + exit (0); +} +""") + + + +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") +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") +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") +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") +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: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/CPPDEFINES/undefined.py b/test/CPPDEFINES/undefined.py new file mode 100644 index 0000000..47825b6 --- /dev/null +++ b/test/CPPDEFINES/undefined.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# 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. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify that $_CPPDEFFLAGS doesn't barf when CPPDEFINES isn't defined. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """\ +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) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: |
