diff options
Diffstat (limited to 'test/SConscript')
-rw-r--r-- | test/SConscript/SConscript.py | 219 | ||||
-rw-r--r-- | test/SConscript/SConscriptChdir.py | 85 | ||||
-rw-r--r-- | test/SConscript/env.py | 90 | ||||
-rw-r--r-- | test/SConscript/src_dir.py | 97 | ||||
-rw-r--r-- | test/SConscript/variables.py | 169 | ||||
-rw-r--r-- | test/SConscript/white-space.py | 50 |
6 files changed, 710 insertions, 0 deletions
diff --git a/test/SConscript/SConscript.py b/test/SConscript/SConscript.py new file mode 100644 index 0000000..268c48e --- /dev/null +++ b/test/SConscript/SConscript.py @@ -0,0 +1,219 @@ +#!/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__" + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('foo.py', "foo = 4\n") + + +test.write('SConstruct', """\ +import os +import foo + +assert foo.foo == 4 + +print "SConstruct", os.getcwd() +SConscript('SConscript') + +x1 = "SConstruct x1" +x2 = "SConstruct x2" +x3,x4 = SConscript('SConscript1', "x1 x2") +assert x3 == "SConscript1 x3", x3 +assert x4 == "SConscript1 x4", x4 + +(x3,x4) = SConscript('SConscript2', ["x1","x2"]) +assert x3 == "SConscript2 x3", x3 +assert x4 == "SConscript2 x4", x4 + +Export("x1 x2") +SConscript('SConscript3') +Import("x1 x2") +assert x1 == "SConscript3 x1", x1 +assert x2 == "SConscript3 x2", x2 + +x1 = "SConstruct x1" +x2 = "SConstruct x2" +Export("x1","x2") +SConscript('SConscript4') +Import("x1"," x2") +assert x1 == "SConscript4 x1", x1 +assert x2 == "SConscript4 x2", x2 + +subdir = Dir('subdir') +script = File('SConscript', subdir) +foo = SConscript(script) +assert foo == "subdir/SConscript foo" + +SConscript('SConscript5') + +import UserList +x7 = "SConstruct x7" +x8 = "SConstruct x8" +x9 = SConscript('SConscript6', UserList.UserList(["x7", "x8"])) +assert x9 == "SConscript6 x9", x9 + +SConscript('SConscript7') +""") + + +test.write('SConscript', """\ +# os should not be automajically imported: +assert not globals().has_key("os") + +import os +print "SConscript " + os.getcwd() +""") + +test.write('SConscript1', """ +Import("x1 x2") +assert x1 == "SConstruct x1", x1 +assert x2 == "SConstruct x2", x2 + +x3 = "SConscript1 x3" +x4 = "SConscript1 x4" +Return("x3 x4") +""") + + +test.write('SConscript2', """\ +Import("x1","x2") +assert x1 == "SConstruct x1", x1 +assert x2 == "SConstruct x2", x2 +x3 = "SConscript2 x3" +x4 = "SConscript2 x4" +Return("x3","x4") +""") + + +test.write('SConscript3', """\ +Import("x1 x2") +assert x1 == "SConstruct x1", x1 +assert x2 == "SConstruct x2", x2 +x1 = "SConscript3 x1" +x2 = "SConscript3 x2" + +x5 = SConscript('SConscript31', "x1") +Import("x6") +assert x5 == "SConscript31 x5", x5 +assert x6 == "SConscript31 x6", x6 + +Export("x1 x2") +""") + + +test.write('SConscript31', """\ +Import("x1 x2") +assert x1 == "SConscript3 x1", x1 +assert x2 == "SConstruct x2", x2 +x5 = "SConscript31 x5" +x6 = "SConscript31 x6" +Export("x6") +Return("x5") +""") + + +test.write('SConscript4', """\ +Import("x1", "x2") +assert x1 == "SConstruct x1", x1 +assert x2 == "SConstruct x2", x2 +x1 = "SConscript4 x1" +x2 = "SConscript4 x2" +Export("x1", "x2") +""") + + +test.subdir('subdir') +test.write(['subdir', 'SConscript'], """\ +foo = 'subdir/SConscript foo' +Return('foo') +""") + + +test.write('SConscript5', """\ +B = Builder(action = 'B') +def scan(): + pass +S = Scanner(function = scan) +A = Action("A") +""") + + +test.write('SConscript6', """\ +Import("x7 x8") +assert x7 == "SConstruct x7", x7 +assert x8 == "SConstruct x8", x8 +x9 = "SConscript6 x9" +Return("x9") +""") + + +test.write('SConscript7', """\ +result1 = ((1, 3), -4) +result2 = ((2, 3), -4) +assert result1 == SConscript(Split('foo/SConscript bar/SConscript')) +assert result1 == SConscript(['foo/SConscript', 'bar/SConscript']) +assert result1 == SConscript([File('foo/SConscript'), File('bar/SConscript')]) +assert result1 == SConscript(dirs = Split('foo bar')) +assert result1 == SConscript(dirs = ['foo', 'bar']) +assert result2 == SConscript(dirs = Split('foo bar'), name = 'subscript') +assert result2 == SConscript(dirs = ['foo', 'bar'], name = 'subscript') +assert result1 == SConscript(dirs = ['foo', Dir('bar')]) +assert result2 == SConscript(dirs = [Dir('foo'), 'bar'], name = 'subscript') +assert 5 == SConscript('w s/SConscript') +assert (-4, 5) == SConscript(['bar/SConscript', 'w s/SConscript']) + +x1 = 3 +x2 = 2 +assert (3, 2) == SConscript(dirs = 'baz', exports = "x1 x2") +assert (3, 2) == SConscript('baz/SConscript', 'x1', exports = 'x2') +assert (3, 2) == SConscript('baz/SConscript', exports = 'x1 x2') +""") + +fooscript = "x = %d; y = 3; Return('x y')\n" +barscript = "x = -4; Return('x')\n" + +test.subdir('foo', 'bar', 'baz', 'w s') +test.write(['foo', 'SConscript'], fooscript % 1) +test.write(['foo', 'subscript'], fooscript % 2) +test.write(['bar', 'SConscript'], barscript) +test.write(['bar', 'subscript'], barscript) +test.write(['baz', 'SConscript'], """\ +Import("x1 x2") +result = (x1, x2) +Return("result") +""") +test.write(['w s', 'SConscript'], "x = 5; Return('x')\n") + + +wpath = test.workpath() + +test.run(arguments = ".", + stdout = test.wrap_stdout(read_str = 'SConstruct %s\nSConscript %s\n' % (wpath, wpath), + build_str = "scons: `.' is up to date.\n")) + +test.pass_test() diff --git a/test/SConscript/SConscriptChdir.py b/test/SConscript/SConscriptChdir.py new file mode 100644 index 0000000..3763378 --- /dev/null +++ b/test/SConscript/SConscriptChdir.py @@ -0,0 +1,85 @@ +#!/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__" + +import sys +import TestSCons + +test = TestSCons.TestSCons() + +test.subdir('dir1', 'dir2', 'dir3', 'dir4', 'dir5') + +test.write('SConstruct', """ +env = Environment() +SConscript('dir1/SConscript') +SConscriptChdir(1) +SConscript('dir2/SConscript') +SConscriptChdir(0) +SConscript('dir3/SConscript') +env.SConscriptChdir(1) +SConscript('dir4/SConscript') +env.SConscriptChdir(0) +SConscript('dir5/SConscript') +""") + +test.write(['dir1', 'SConscript'], """ +execfile("create_test.py") +""") + +test.write(['dir2', 'SConscript'], """ +execfile("create_test.py") +""") + +test.write(['dir3', 'SConscript'], """ +import os.path +name = os.path.join('dir3', 'create_test.py') +execfile(name) +""") + +test.write(['dir4', 'SConscript'], """ +execfile("create_test.py") +""") + +test.write(['dir5', 'SConscript'], """ +import os.path +name = os.path.join('dir5', 'create_test.py') +execfile(name) +""") + +for dir in ['dir1', 'dir2', 'dir3','dir4', 'dir5']: + test.write([dir, 'create_test.py'], r""" +f = open("test.txt", "ab") +f.write("This is the %s test.\n") +f.close() +""" % dir) + +test.run(arguments=".", stderr=None) + +test.fail_test(test.read(['dir1', 'test.txt']) != "This is the dir1 test.\n") +test.fail_test(test.read(['dir2', 'test.txt']) != "This is the dir2 test.\n") +test.fail_test(test.read('test.txt') != "This is the dir3 test.\nThis is the dir5 test.\n") +test.fail_test(test.read(['dir4', 'test.txt']) != "This is the dir4 test.\n") + +test.pass_test() diff --git a/test/SConscript/env.py b/test/SConscript/env.py new file mode 100644 index 0000000..0ad0561 --- /dev/null +++ b/test/SConscript/env.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__" + +""" +Test calling SConscript through a construction environment. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.subdir('sub1', 'sub2') + +test.write("SConstruct", """\ +env = Environment(SUB1='sub1', SUB2='sub2') +print "SConstruct" +x = 'xxx' +y = 'yyy' +env.Export(["x", "y"]) +env.SConscript('$SUB1/SConscript') +env.SConscript(dirs=['$SUB2']) +SConscript(['s1', 's2']) +env.SConscript(['s3', 's4']) +""") + +test.write(['sub1', 'SConscript'], """\ +env = Environment() +env.Import("x") +print "sub1/SConscript" +print "x =", x +""") + +test.write(['sub2', 'SConscript'], """\ +env = Environment() +env.Import("y") +print "sub2/SConscript" +print "y =", y +""") + +test.write('s1', "\n") +test.write('s2', "\n") +test.write('s3', "\n") +test.write('s4', "\n") + +expect = """\ +SConstruct +sub1/SConscript +x = xxx +sub2/SConscript +y = yyy +""" + +test.run(arguments = ".", + stdout = test.wrap_stdout(read_str = expect, + build_str = "scons: `.' is up to date.\n")) + +test.write("SConstruct", """\ +def builder(target, source, env): + import SCons.Script.SConscript + assert SCons.Script.SConscript.sconscript_reading == 0 +env = Environment(BUILDERS={'builder':Builder(action=builder)}) +env.builder('test',[]) +import SCons.Script.SConscript +assert SCons.Script.SConscript.sconscript_reading == 1 +""") + +test.pass_test() diff --git a/test/SConscript/src_dir.py b/test/SConscript/src_dir.py new file mode 100644 index 0000000..f18066b --- /dev/null +++ b/test/SConscript/src_dir.py @@ -0,0 +1,97 @@ +#!/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__" + +""" +Test that the SConscript() src_dir argument. + +Test case contributed by Dobes Vandermeer. +""" + +import TestSCons + +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +test.subdir(['build'], + ['samples'], + ['src']) + +test.write(['SConstruct'], """\ +env = Environment() + +for src_dir in ['src','samples']: + SConscript('build/glob_build.py', + src_dir=src_dir, + build_dir='build/output/'+src_dir, + duplicate=0, + exports=['env']) +""") + +test.write(['build', 'glob_build.py'], """\ +from glob import glob +from os.path import join +from os.path import basename +Import('env') + +sources = map(basename, glob(join(str(env.Dir('.').srcnode()),'*.c'))) + +# Trivial example; really I read the configuration file +# their build system uses to generate the vcproj files +for source in sources: + env.Program(source) +""") + +test.write(['samples', 'goodbye.c'], """\ +#include <stdio.h> + +int main(int argc, char *argv[]) +{ + printf("Goodbye, world!\\n"); + exit(0); +} +""") + +test.write(['src', 'hello.c'], """\ +#include <stdio.h> + +int main(int argc, char *argv[]) +{ + printf("Hello, world!\\n"); + exit(0); +} +""") + +test.run() + +goodbye = test.workpath('build', 'output', 'samples', 'goodbye') +hello = test.workpath('build', 'output', 'src', 'hello') + +test.run(program = goodbye, stdout = "Goodbye, world!\n") + +test.run(program = hello, stdout = "Hello, world!\n") + +test.pass_test() diff --git a/test/SConscript/variables.py b/test/SConscript/variables.py new file mode 100644 index 0000000..34f52a0 --- /dev/null +++ b/test/SConscript/variables.py @@ -0,0 +1,169 @@ +#!/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__" + +""" +Test importing and exporting variables between SConscript files. +""" + +import TestSCons + +test = TestSCons.TestSCons() + + +# Test exporting all global variables as a list of keys: +test.write("SConstruct", """ +x = 'x' +y = 'zoom' +Export(globals().keys()) +SConscript('SConscript') +""") + +test.write("SConscript", """ +Import(['x', 'y']) +assert x == 'x' +assert y == 'zoom' +""") + +test.run(arguments = ".") + +# Test exporting all global variables as a list of keys in SConscript call: +test.write("SConstruct", """ +x = 'x' +y = 'zoom' +SConscript('SConscript', globals().keys()) +""") + +test.write("SConscript", """ +Import(['x', 'y']) +assert x == 'x' +assert y == 'zoom' +""") + +test.run(arguments = ".") + +# Test exporting all global variables as a dictionary: +test.write("SConstruct", """ +x = 'x' +y = 'zoom' +Export(globals()) +SConscript('SConscript') +""") + +test.write("SConscript", """ +Import(['x', 'y']) +assert x == 'x' +assert y == 'zoom' +""") + +test.run(arguments = ".") + +# Test exporting all global variables as dictionary in SConscript call: +test.write("SConstruct", """ +x = 'x' +y = 'zoom' +SConscript('SConscript', globals()) +""") + +test.write("SConscript", """ +Import(['x', 'y']) +assert x == 'x' +assert y == 'zoom' +""") + +test.run(arguments = ".") + +# Test export of local variables: +test.write("SConstruct", """ +def f(): + x = 'x' + y = 'zoom' + Export('x', 'y') + +f() +SConscript('SConscript') +""") + +test.write("SConscript", """ +Import(['x', 'y']) +assert x == 'x' +assert y == 'zoom' +""") + +test.run(arguments = ".") + +# Test export of local variables in SConscript call: +test.write("SConstruct", """ +def f(): + x = 'x' + y = 'zoom' + SConscript('SConscript', ['x', 'y']) +f() +""") + +test.write("SConscript", """ +Import(['x', 'y']) +assert x == 'x' +assert y == 'zoom' +""") + +test.run(arguments = ".") + +# Test export of local variables as a dictionary: +test.write("SConstruct", """ +def f(): + x = 'x' + y = 'zoom' + Export(locals()) + +f() +SConscript('SConscript') +""") + +test.write("SConscript", """ +Import(['x', 'y']) +assert x == 'x' +assert y == 'zoom' +""") + +test.run(arguments = ".") + +# Test importing all variables: +test.write("SConstruct", """ +x = 'x' +y = 'zoom' +Export('x') +SConscript('SConscript', 'y') +""") + +test.write("SConscript", """ +Import('*') +assert x == 'x' +assert y == 'zoom' +""") + +test.run(arguments = ".") + +test.pass_test() diff --git a/test/SConscript/white-space.py b/test/SConscript/white-space.py new file mode 100644 index 0000000..87eb701 --- /dev/null +++ b/test/SConscript/white-space.py @@ -0,0 +1,50 @@ +#!/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__" + +""" +Test handling of white space in an SConscript path name. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.subdir('white space') +test.write("SConstruct", """\ +SConscript('white space/SConscript') +""") + +test.write(['white space', 'SConscript'], """\ +print "`white space/SConscript'" +""") + +expect = test.wrap_stdout(read_str = "`white space/SConscript'\n", + build_str = "scons: `.' is up to date.\n") + +test.run(arguments = ".", stdout = expect) + + +test.pass_test() |