diff options
Diffstat (limited to 'test')
55 files changed, 2307 insertions, 305 deletions
diff --git a/test/AS/ml.py b/test/AS/ml.py index 0cb0e9e..633befd 100644 --- a/test/AS/ml.py +++ b/test/AS/ml.py @@ -39,7 +39,7 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() -if sys.platform == 'win32': +if sys.platform != 'win32': test.skip_test("Skipping ml test on non-win32 platform '%s'\n" % sys.platform) ml = test.where_is('ml') diff --git a/test/AS/nasm.py b/test/AS/nasm.py index f96db7e..f1b99ee 100644 --- a/test/AS/nasm.py +++ b/test/AS/nasm.py @@ -45,7 +45,7 @@ if not nasm: test.skip_test('nasm not found; skipping test\n') if string.find(sys.platform, 'linux') == -1: - test.skip_test("skipping test on non-Linux platform '%s'\n" % sys.platfrom) + test.skip_test("skipping test on non-Linux platform '%s'\n" % sys.platform) try: import popen2 diff --git a/test/Actions/addpost-link.py b/test/Actions/addpost-link.py new file mode 100644 index 0000000..f97d4a3 --- /dev/null +++ b/test/Actions/addpost-link.py @@ -0,0 +1,76 @@ +#!/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 AddPostAction() on a program target doesn't interfere with +linking. + +This is a test for fix of Issue 1004, reported by Matt Doar and +packaged by Gary Oberbrunner. +""" + +import TestSCons + + +test = TestSCons.TestSCons() + +test.write('SConstruct', """\ +env = Environment() + +mylib = env.StaticLibrary('mytest', 'test_lib.c') + +myprog = env.Program('test1.c', + LIBPATH = ['.'], + LIBS = ['mytest']) +if ARGUMENTS['case']=='2': + AddPostAction(myprog, Action('strip ' + myprog[0].abspath)) +""") + +test.write('test1.c', """\ +extern void test_lib_fn(); +int main(int argc, char **argv) { + test_lib_fn(); + return 0; +} +""") + +test.write('test_lib.c', r"""\ +#include <stdio.h> + +void test_lib_fn() { + printf("Hello world\n"); +} +""") + +test.run(arguments="-Q case=1", stderr=None) + +test.run(arguments="-Q -c case=1") + +test.must_not_exist('test1.o') + +test.run(arguments="-Q case=2", stderr=None) + +test.pass_test() diff --git a/test/Actions/pre-post.py b/test/Actions/pre-post.py index 7566f2f..674c628 100644 --- a/test/Actions/pre-post.py +++ b/test/Actions/pre-post.py @@ -49,9 +49,11 @@ import stat env = Environment(XXX='bar%(_exe)s') def before(env, target, source): - f=open(str(target[0]), "wb") + a=str(target[0]) + f=open(a, "wb") f.write("Foo\\n") f.close() + os.chmod(a, os.stat(a)[stat.ST_MODE] | stat.S_IXUSR) f=open("before.txt", "ab") f.write(os.path.splitext(str(target[0]))[0] + "\\n") f.close() diff --git a/test/AddOption/optional-arg.py b/test/AddOption/optional-arg.py new file mode 100644 index 0000000..f7a0337 --- /dev/null +++ b/test/AddOption/optional-arg.py @@ -0,0 +1,102 @@ +#!/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 use of the nargs='?' keyword argument to specify a long +command-line option with an optional argument value. +""" + +import string + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """\ +AddOption('--install', + nargs='?', + dest='install', + default='/default/directory', + const='/called/default/directory', + action='store', + type='string', + metavar='DIR', + help='installation directory') +print GetOption('install') +""") + +test.run('-Q -q', + stdout="/default/directory\n") + +test.run('-Q -q next-arg', + stdout="/default/directory\n", + status=1) + +test.run('-Q -q . --install', + stdout="/called/default/directory\n") + +test.run('-Q -q . --install next-arg', + stdout="/called/default/directory\n", + status=1) + +test.run('-Q -q . first-arg --install', + stdout="/called/default/directory\n", + status=1) + +test.run('-Q -q . first-arg --install next-arg', + stdout="/called/default/directory\n", + status=1) + +test.run('-Q -q . --install=/command/line/directory', + stdout="/command/line/directory\n") + +test.run('-Q -q . --install=/command/line/directory next-arg', + stdout="/command/line/directory\n", + status=1) + +test.run('-Q -q . first-arg --install=/command/line/directory', + stdout="/command/line/directory\n", + status=1) + +test.run('-Q -q . first-arg --install=/command/line/directory next-arg', + stdout="/command/line/directory\n", + status=1) + + +test.write('SConstruct', """\ +AddOption('-X', nargs='?') +""") + +expect = r""" +scons: \*\*\* option -X: nargs='\?' is incompatible with short options +File "[^"]+", line \d+, in \S+ +""" + +test.run(status=2, stderr=expect, match=TestSCons.match_re) + + + +test.pass_test() diff --git a/test/BuildDir/CPPPATH-subdir.py b/test/BuildDir/CPPPATH-subdir.py index 7254279..9d3bb98 100644 --- a/test/BuildDir/CPPPATH-subdir.py +++ b/test/BuildDir/CPPPATH-subdir.py @@ -58,6 +58,7 @@ env.Library('foo', 'foo.c') test.write(['src', 'glscry', 'foo.c'], """\ #include <foo.h> +int foo(void) { return 0; } """) diff --git a/test/CPPPATH/match-dir.py b/test/CPPPATH/match-dir.py new file mode 100644 index 0000000..f8501c6 --- /dev/null +++ b/test/CPPPATH/match-dir.py @@ -0,0 +1,61 @@ +#!/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 we don't blow up if there's a directory name within +$CPPPATH that matches a #include file name. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.subdir(['src'], + ['src', 'inc'], + ['src', 'inc', 'inc2']) + +test.write('SConstruct', """\ +SConscript('src/SConscript', build_dir = 'build', duplicate = 0) +""") + +test.write(['src', 'SConscript'], """\ +env = Environment(CPPPATH = ['#build/inc', '#build/inc/inc2']) +env.Object('foo.c') +""") + +test.write(['src', 'foo.c'], """\ +#include "inc1" +""") + +test.subdir(['src', 'inc', 'inc1']) + +test.write(['src', 'inc', 'inc2', 'inc1'], "\n") + +test.run(arguments = '.') + +test.up_to_date(arguments = '.') + +test.pass_test() diff --git a/test/CacheDir/BuildDir.py b/test/CacheDir/BuildDir.py index d03bfa6..a41d397 100644 --- a/test/CacheDir/BuildDir.py +++ b/test/CacheDir/BuildDir.py @@ -39,11 +39,6 @@ test.subdir('cache', 'src') cache = test.workpath('cache') cat_out = test.workpath('cat.out') -test.write(['src', 'SConstruct'], """\ -CacheDir(r'%(cache)s') -SConscript('SConscript') -""" % locals()) - test.write(['src', 'SConscript'], """\ def cat(env, source, target): target = str(target[0]) @@ -72,7 +67,7 @@ test.write(['src', 'ccc.in'], "ccc.in\n") # test.write('SConstruct', """\ env = Environment(TWO = '2') -env.CacheDir(r'%s') +CacheDir(r'%s') BuildDir('build', 'src', duplicate=0) SConscript('build/SConscript') """ % test.workpath('cache${TWO}')) diff --git a/test/CacheDir/environment.py b/test/CacheDir/environment.py new file mode 100644 index 0000000..391fb94 --- /dev/null +++ b/test/CacheDir/environment.py @@ -0,0 +1,163 @@ +#!/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 whether or not a target gets retrieved from a CacheDir +is configurable by construction environment. +""" + +import os + +import TestSCons + +test = TestSCons.TestSCons() + +cache = test.workpath('cache') + +src_aaa_out = test.workpath('src', 'aaa.out') +src_bbb_out = test.workpath('src', 'bbb.out') +src_ccc_out = test.workpath('src', 'ccc.out') +src_cat_out = test.workpath('src', 'cat.out') +src_all = test.workpath('src', 'all') + +test.subdir('cache', 'src') + +test.write(['src', 'SConstruct'], """\ +CacheDir(r'%(cache)s') +SConscript('SConscript') +""" % locals()) + +test.write(['src', 'SConscript'], """\ +def cat(env, source, target): + target = str(target[0]) + open('cat.out', 'ab').write(target + "\\n") + source = map(str, source) + f = open(target, "wb") + for src in source: + f.write(open(src, "rb").read()) + f.close() +env_cache = Environment(BUILDERS={'Cat':Builder(action=cat)}) +env_nocache = env_cache.Clone() +env_nocache.CacheDir(None) +env_cache.Cat('aaa.out', 'aaa.in') +env_nocache.Cat('bbb.out', 'bbb.in') +env_cache.Cat('ccc.out', 'ccc.in') +env_nocache.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out']) +""") + +test.write(['src', 'aaa.in'], "aaa.in\n") +test.write(['src', 'bbb.in'], "bbb.in\n") +test.write(['src', 'ccc.in'], "ccc.in\n") + +# Verify that building with -n and an empty cache reports that proper +# build operations would be taken, but that nothing is actually built +# and that the cache is still empty. +test.run(chdir = 'src', arguments = '-n .', stdout = test.wrap_stdout("""\ +cat(["aaa.out"], ["aaa.in"]) +cat(["bbb.out"], ["bbb.in"]) +cat(["ccc.out"], ["ccc.in"]) +cat(["all"], ["aaa.out", "bbb.out", "ccc.out"]) +""")) + +test.must_not_exist(src_aaa_out) +test.must_not_exist(src_bbb_out) +test.must_not_exist(src_ccc_out) +test.must_not_exist(src_all) +test.fail_test(len(os.listdir(cache))) + +# Verify that a normal build works correctly, and clean up. +# This should populate the cache with our derived files. +test.run(chdir = 'src', arguments = '.') + +test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n") +test.must_match(src_cat_out, "aaa.out\nbbb.out\nccc.out\nall\n") + +test.up_to_date(chdir = 'src', arguments = '.') + +test.run(chdir = 'src', arguments = '-c .') +test.unlink(src_cat_out) + +# Verify that we now retrieve the derived files from cache, +# not rebuild them. Then clean up. +test.run(chdir = 'src', arguments = '.', stdout = test.wrap_stdout("""\ +Retrieved `aaa.out' from cache +cat(["bbb.out"], ["bbb.in"]) +Retrieved `ccc.out' from cache +cat(["all"], ["aaa.out", "bbb.out", "ccc.out"]) +""")) + +test.must_match(src_cat_out, "bbb.out\nall\n") + +test.up_to_date(chdir = 'src', arguments = '.') + +test.run(chdir = 'src', arguments = '-c .') +test.unlink(src_cat_out) + +# Verify that rebuilding with -n reports that files were retrieved +# from the cache, but that nothing really was. +test.run(chdir = 'src', arguments = '-n .', stdout = test.wrap_stdout("""\ +Retrieved `aaa.out' from cache +cat(["bbb.out"], ["bbb.in"]) +Retrieved `ccc.out' from cache +cat(["all"], ["aaa.out", "bbb.out", "ccc.out"]) +""")) + +test.must_not_exist(src_aaa_out) +test.must_not_exist(src_bbb_out) +test.must_not_exist(src_ccc_out) +test.must_not_exist(src_all) + +# Verify that rebuilding with -s retrieves everything from the cache +# even though it doesn't report anything. +test.run(chdir = 'src', arguments = '-s .', stdout = "") + +test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n") + +test.must_match(src_cat_out, "bbb.out\nall\n") + +test.up_to_date(chdir = 'src', arguments = '.') + +test.run(chdir = 'src', arguments = '-c .') +test.unlink(src_cat_out) + +# Verify that updating one input file builds its derived file and +# dependency but that the other files are retrieved from cache. +test.write(['src', 'bbb.in'], "bbb.in 2\n") + +test.run(chdir = 'src', arguments = '.', stdout = test.wrap_stdout("""\ +Retrieved `aaa.out' from cache +cat(["bbb.out"], ["bbb.in"]) +Retrieved `ccc.out' from cache +cat(["all"], ["aaa.out", "bbb.out", "ccc.out"]) +""")) + +test.must_match(['src', 'all'], "aaa.in\nbbb.in 2\nccc.in\n") +test.must_match(src_cat_out, "bbb.out\nall\n") + +test.up_to_date(chdir = 'src', arguments = '.') + + +test.pass_test() diff --git a/test/option--cd.py b/test/CacheDir/option--cd.py index 9aa9402..9aa9402 100644 --- a/test/option--cd.py +++ b/test/CacheDir/option--cd.py diff --git a/test/option--cf.py b/test/CacheDir/option--cf.py index 47847d4..47847d4 100644 --- a/test/option--cf.py +++ b/test/CacheDir/option--cf.py diff --git a/test/option--cs.py b/test/CacheDir/option--cs.py index 1e62c49..1e62c49 100644 --- a/test/option--cs.py +++ b/test/CacheDir/option--cs.py diff --git a/test/Case.py b/test/Case.py index 9b6bb94..663aa40 100644 --- a/test/Case.py +++ b/test/Case.py @@ -65,6 +65,9 @@ void bar() { } """) +if sys.platform == 'darwin': + test.skip_test("Skipping test on Darwin/OSX; it has partial case sensitivity.") + if sys.platform in ['cygwin', 'win32']: sys.stdout.write("Using case-insensitive filesystem, testing for failure\n") sys.stdout.flush() diff --git a/test/Fortran/FORTRANMODDIR.py b/test/Fortran/FORTRANMODDIR.py index f0c500c..a81439a 100644 --- a/test/Fortran/FORTRANMODDIR.py +++ b/test/Fortran/FORTRANMODDIR.py @@ -54,6 +54,8 @@ test.write('SConstruct', """ env = Environment(FORTRANCOM = r'%(_python_)s myfortran.py $FORTRANMODDIR $SOURCE $TARGET', FORTRANMODDIR = 'modules') env.Object(target = 'test1.obj', source = 'test1.f') +env.Object(target = 'sub/test2.obj', source = 'test1.f', + FORTRANMODDIR='${TARGET.dir}') """ % locals()) test.write('test1.f', """\ @@ -86,6 +88,9 @@ test.must_match('test1.obj', "myfortran.py wrote test1.obj\n") test.must_match(['modules', 'mod_foo.mod'], "myfortran.py wrote mod_foo.mod\n") test.must_not_exist(['modules', 'mod_bar.mod']) +test.must_match(['sub', 'test2.obj'], "myfortran.py wrote test2.obj\n") +test.must_match(['sub', 'mod_foo.mod'], "myfortran.py wrote mod_foo.mod\n") + test.up_to_date(arguments = '.') diff --git a/test/Java/JARCHDIR.py b/test/Java/JARCHDIR.py index 9250843..f7d9fca 100644 --- a/test/Java/JARCHDIR.py +++ b/test/Java/JARCHDIR.py @@ -28,8 +28,14 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" Test that when JARCHDIR that our command to create .jar files correctly finds all the .class files (by putting -C in front of each class file argument). + +Includes logic to make sure that expansions of $JARCHDIR that include +${TARGET} or ${SOURCE} work. """ +import os +import string + import TestSCons test = TestSCons.TestSCons() @@ -50,6 +56,8 @@ else: if not where_jar: test.skip_test("Could not find Java jar, skipping test(s).\n") + + test.write('SConstruct', """ dir = 'dist' env = Environment(tools = ['javac', 'jar'], @@ -64,9 +72,19 @@ jar = env.Jar(File('c.jar', dir), bin) env = env.Clone(JARCHDIR = '.') inner = env.Jar('inner.jar', 'Inner$$Class.class') +target_env = env.Clone(JARCHDIR = '${TARGET.dir}') +target_env.Jar('out/t.jar', 'in/t.class') + +source_env = env.Clone(JARCHDIR = '${SOURCE.dir}') +source_env.Jar('out/s.jar', 'in/s.class') + Default(bin, jar, inner) """ % locals()) + + +test.subdir('in') + test.write('a.java', """\ package foo.bar; public class a {} @@ -77,8 +95,36 @@ package foo.bar; public class b {} """) +test.write(['in', 's.class'], "s.class\n") + +# Okay, this is bogus, but we're going with it for testing purposes. +# If jar gets a command line like: +# +# jar cf out/t.jar -C out /tmp/tmpXYZZY/in/t.class +# +# Empirically, it doesn't seem to treat the absolute path name +# of the argument class file as an absolute path, but looks for +# "out/tmp/tmpXYZZY/in/t.class". SCons, however, still looks for it in +# the path name specified on the command line. To make this test work, +# we're going to just create the t.class file in both locations, and +# we can revisit this if someone actually tries to use ${TARGET.dir} +# in a real-life expansion. Right now, it at least makes sure things +# don't blow up (i.e., validates that we pass the right arguments to +# env.subst() in the code that handle jar). + +p = test.workpath('out') +for d in string.split(test.workpath('in'), os.sep): + p = p + d + test.subdir(p) + p = p + os.sep + +test.write([p, 't.class'], "t.class\n") +test.write(['in', 't.class'], "t.class\n") + test.write('Inner$Class.class', "Inner$Class.class\n") test.run(arguments = '.') + + test.pass_test() diff --git a/test/Java/JAVACCOM.py b/test/Java/JAVACCOM.py index 7086a2a..b6a30e9 100644 --- a/test/Java/JAVACCOM.py +++ b/test/Java/JAVACCOM.py @@ -60,7 +60,7 @@ test.write(['src', 'file3.java'], "file3.java\n/*javac*/\n") test.run() -test.must_match(['classes', 'src', 'file1.class'], +test.must_match(['classes', 'file1.class'], "file1.java\nfile2.java\nfile3.java\n") diff --git a/test/Java/JAVACCOMSTR.py b/test/Java/JAVACCOMSTR.py index 44b1449..88fa31d 100644 --- a/test/Java/JAVACCOMSTR.py +++ b/test/Java/JAVACCOMSTR.py @@ -62,16 +62,16 @@ test.write(['src', 'file1.java'], "file1.java\n/*javac*/\n") test.write(['src', 'file2.java'], "file2.java\n/*javac*/\n") test.write(['src', 'file3.java'], "file3.java\n/*javac*/\n") -classes_src_file1_class = os.path.join('classes', 'src', 'file1.class') +classes_file1_class = os.path.join('classes', 'file1.class') src_file1_java= os.path.join('src', 'file1.java') src_file2_java= os.path.join('src', 'file2.java') src_file3_java= os.path.join('src', 'file3.java') test.run(stdout = test.wrap_stdout("""\ -Compiling class(es) %(classes_src_file1_class)s from %(src_file1_java)s %(src_file2_java)s %(src_file3_java)s +Compiling class(es) %(classes_file1_class)s from %(src_file1_java)s %(src_file2_java)s %(src_file3_java)s """ % locals())) -test.must_match(['classes', 'src', 'file1.class'], +test.must_match(['classes', 'file1.class'], "file1.java\nfile2.java\nfile3.java\n") diff --git a/test/Java/JAVACLASSPATH.py b/test/Java/JAVACLASSPATH.py new file mode 100644 index 0000000..0ae7dea --- /dev/null +++ b/test/Java/JAVACLASSPATH.py @@ -0,0 +1,104 @@ +#!/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 $JAVASOURCEPATH allows finding Java .class +files in alternate locations by adding the -classpath option +to the javac command line. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) +else: + where_javac = test.where_is('javac') +if not where_javac: + test.skip_test("Could not find Java javac, skipping test(s).\n") + +if test.detect_tool('javah', ENV=ENV): + where_javah = test.detect('JAVAH', 'javah', ENV=ENV) +else: + where_javah = test.where_is('javah') +if not where_javah: + test.skip_test("Could not find Java javah, skipping test(s).\n") + +test.write('SConstruct', """ +env = Environment(tools = ['javac', 'javah'], + JAVAC = r'%(where_javac)s', + JAVAH = r'%(where_javah)s') +j1 = env.Java(target = 'class1', source = 'com1/Example1.java') +j2 = env.Java(target = 'class2', source = 'com2/Example2.java') +env.JavaH(target = 'outdir', source = [j1, j2], JAVACLASSPATH = 'class2') +""" % locals()) + +test.subdir('com1', 'com2') + +test.write(['com1', 'Example1.java'], """\ +package com; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com2', 'Example2.java'], """\ +package com; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.run(arguments = '.') + +test.must_exist(['class1', 'com', 'Example1.class']) +test.must_exist(['class2', 'com', 'Example2.class']) + +test.must_exist(['outdir', 'com_Example1.h']) +test.must_exist(['outdir', 'com_Example2.h']) + +test.up_to_date(arguments = '.') + +test.pass_test() diff --git a/test/Java/JAVASOURCEPATH.py b/test/Java/JAVASOURCEPATH.py new file mode 100644 index 0000000..069e228 --- /dev/null +++ b/test/Java/JAVASOURCEPATH.py @@ -0,0 +1,81 @@ +#!/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 $JAVASOURCEPATH allows finding source .java +files in alternate locations by adding the -sourcepath option +to the javac command line. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) +else: + where_javac = test.where_is('javac') +if not where_javac: + test.skip_test("Could not find Java javac, skipping test(s).\n") + +test.write('SConstruct', """ +env = Environment(tools = ['javac', 'javah'], + JAVAC = r'%(where_javac)s') +bar = env.Java(target = 'bar/classes', + source = 'bar/src/TestBar.java', + JAVASOURCEPATH = ['foo/src']) +""" % locals()) + +test.subdir('foo', + ['foo', 'src'], + ['foo', 'src', 'com'], + ['foo', 'src', 'com', 'foo'], + ['foo', 'src', 'com', 'foo', 'test'], + 'bar', ['bar', 'src']) + +test.write(['foo', 'src', 'com', 'foo', 'test', 'TestFoo.java'], """\ +package com.foo.test; +public class TestFoo {;} +""") + +test.write(['bar', 'src', 'TestBar.java'], """\ +package com.bar.test; +import com.foo.test.TestFoo; +class TestBar extends TestFoo {;} +""") + +test.run(arguments = '.') + +test.must_exist(['bar', 'classes', 'com', 'bar', 'test', 'TestBar.class']) +test.must_exist(['bar', 'classes', 'com', 'foo', 'test', 'TestFoo.class']) + +test.up_to_date(arguments = '.') + +test.pass_test() diff --git a/test/Java/Java-1.4.py b/test/Java/Java-1.4.py index 8c3af59..3d3d47a 100644 --- a/test/Java/Java-1.4.py +++ b/test/Java/Java-1.4.py @@ -58,6 +58,7 @@ env.Java(target = 'class2', source = 'com/sub/bar') env.Java(target = 'class3', source = ['src1', 'src2']) env.Java(target = 'class4', source = ['src4']) env.Java(target = 'class5', source = ['src5']) +env.Java(target = 'class6', source = ['src6']) """ % locals()) test.subdir('com', @@ -67,7 +68,8 @@ test.subdir('com', 'src1', 'src2', 'src4', - 'src5') + 'src5', + 'src6') test.write(['com', 'sub', 'foo', 'Example1.java'], """\ package com.sub.foo; @@ -273,23 +275,27 @@ class TestSCons { class Foo { } """) -test.run(arguments = '.') +# Test private inner class instantiation, courtesy Tilo Prutz: +# http://scons.tigris.org/issues/show_bug.cgi?id=1594 +test.write(['src6', 'TestSCons.java'], """\ +class test +{ + test() + { + super(); + new inner(); + } -def get_class_files(dir): - def find_class_files(arg, dirname, fnames): - for fname in fnames: - if fname[-6:] == '.class': - arg.append(os.path.join(dirname, fname)) - result = [] - os.path.walk(dir, find_class_files, result) - result.sort() - return result + static class inner + { + private inner() {} + } +} +""") -classes_1 = get_class_files(test.workpath('class1')) -classes_2 = get_class_files(test.workpath('class2')) -classes_3 = get_class_files(test.workpath('class3')) -classes_4 = get_class_files(test.workpath('class4')) -classes_5 = get_class_files(test.workpath('class5')) + + +test.run(arguments = '.') expect_1 = [ test.workpath('class1', 'com', 'other', 'Example2.class'), @@ -327,9 +333,27 @@ expect_5 = [ test.workpath('class5', 'TestSCons.class'), ] +expect_6 = [ + test.workpath('class6', 'test$1.class'), + test.workpath('class6', 'test$inner.class'), + test.workpath('class6', 'test.class'), +] + failed = None -def classes_must_match(dir, expect, got): +def get_class_files(dir): + def find_class_files(arg, dirname, fnames): + for fname in fnames: + if fname[-6:] == '.class': + arg.append(os.path.join(dirname, fname)) + result = [] + os.path.walk(dir, find_class_files, result) + result.sort() + return result + +def classes_must_match(dir, expect): + global failed + got = get_class_files(test.workpath(dir)) if expect != got: sys.stderr.write("Expected the following class files in '%s':\n" % dir) for c in expect: @@ -339,13 +363,40 @@ def classes_must_match(dir, expect, got): sys.stderr.write(' %s\n' % c) failed = 1 -classes_must_match('class1', expect_1, classes_1) -classes_must_match('class2', expect_2, classes_2) -classes_must_match('class3', expect_3, classes_3) -classes_must_match('class4', expect_4, classes_4) +def classes_must_not_exist(dir, expect): + global failed + present = filter(os.path.exists, expect) + if present: + sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir) + for c in present: + sys.stderr.write(' %s\n' % c) + failed = 1 + +classes_must_match('class1', expect_1) +classes_must_match('class2', expect_2) +classes_must_match('class3', expect_3) +classes_must_match('class4', expect_4) +classes_must_match('class5', expect_5) +classes_must_match('class6', expect_6) test.fail_test(failed) test.up_to_date(options='--debug=explain', arguments = '.') +test.run(arguments = '-c .') + +classes_must_not_exist('class1', expect_1) +classes_must_not_exist('class2', expect_2) +classes_must_not_exist('class3', expect_3) +classes_must_not_exist('class4', expect_4) +classes_must_not_exist('class5', expect_5) +# This test case should pass, but doesn't. +# The expect_6 list contains the class files that the Java compiler +# actually creates, apparently because of the "private" instantiation +# of the "inner" class. Our parser doesn't currently detect this, so +# it doesn't know to remove that generated class file. +#classes_must_not_exist('class6', expect_6) + +test.fail_test(failed) + test.pass_test() diff --git a/test/Java/Java-1.5.py b/test/Java/Java-1.5.py index 0b3ba27..4ac3d96 100644 --- a/test/Java/Java-1.5.py +++ b/test/Java/Java-1.5.py @@ -59,6 +59,7 @@ env.Java(target = 'class2', source = 'com/sub/bar') env.Java(target = 'class3', source = ['src1', 'src2']) env.Java(target = 'class4', source = ['src4']) env.Java(target = 'class5', source = ['src5']) +env.Java(target = 'class6', source = ['src6']) """ % locals()) test.subdir('com', @@ -68,7 +69,8 @@ test.subdir('com', 'src1', 'src2', 'src4', - 'src5') + 'src5', + 'src6') test.write(['com', 'sub', 'foo', 'Example1.java'], """\ package com.sub.foo; @@ -274,23 +276,27 @@ class TestSCons { class Foo { } """) -test.run(arguments = '.') +# Test private inner class instantiation, courtesy Tilo Prutz: +# http://scons.tigris.org/issues/show_bug.cgi?id=1594 +test.write(['src6', 'TestSCons.java'], """\ +class test +{ + test() + { + super(); + new inner(); + } -def get_class_files(dir): - def find_class_files(arg, dirname, fnames): - for fname in fnames: - if fname[-6:] == '.class': - arg.append(os.path.join(dirname, fname)) - result = [] - os.path.walk(dir, find_class_files, result) - result.sort() - return result + static class inner + { + private inner() {} + } +} +""") -classes_1 = get_class_files(test.workpath('class1')) -classes_2 = get_class_files(test.workpath('class2')) -classes_3 = get_class_files(test.workpath('class3')) -classes_4 = get_class_files(test.workpath('class4')) -classes_5 = get_class_files(test.workpath('class5')) + + +test.run(arguments = '.') expect_1 = [ test.workpath('class1', 'com', 'other', 'Example2.class'), @@ -328,9 +334,27 @@ expect_5 = [ test.workpath('class5', 'TestSCons.class'), ] +expect_6 = [ + test.workpath('class6', 'test$1.class'), + test.workpath('class6', 'test$inner.class'), + test.workpath('class6', 'test.class'), +] + failed = None -def classes_must_match(dir, expect, got): +def get_class_files(dir): + def find_class_files(arg, dirname, fnames): + for fname in fnames: + if fname[-6:] == '.class': + arg.append(os.path.join(dirname, fname)) + result = [] + os.path.walk(dir, find_class_files, result) + result.sort() + return result + +def classes_must_match(dir, expect): + global failed + got = get_class_files(test.workpath(dir)) if expect != got: sys.stderr.write("Expected the following class files in '%s':\n" % dir) for c in expect: @@ -340,13 +364,40 @@ def classes_must_match(dir, expect, got): sys.stderr.write(' %s\n' % c) failed = 1 -classes_must_match('class1', expect_1, classes_1) -classes_must_match('class2', expect_2, classes_2) -classes_must_match('class3', expect_3, classes_3) -classes_must_match('class4', expect_4, classes_4) +def classes_must_not_exist(dir, expect): + global failed + present = filter(os.path.exists, expect) + if present: + sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir) + for c in present: + sys.stderr.write(' %s\n' % c) + failed = 1 + +classes_must_match('class1', expect_1) +classes_must_match('class2', expect_2) +classes_must_match('class3', expect_3) +classes_must_match('class4', expect_4) +classes_must_match('class5', expect_5) +classes_must_match('class6', expect_6) test.fail_test(failed) test.up_to_date(options='--debug=explain', arguments = '.') +test.run(arguments = '-c .') + +classes_must_not_exist('class1', expect_1) +classes_must_not_exist('class2', expect_2) +classes_must_not_exist('class3', expect_3) +classes_must_not_exist('class4', expect_4) +classes_must_not_exist('class5', expect_5) +# This test case should pass, but doesn't. +# The expect_6 list contains the class files that the Java compiler +# actually creates, apparently because of the "private" instantiation +# of the "inner" class. Our parser doesn't currently detect this, so +# it doesn't know to remove that generated class file. +#classes_must_not_exist('class6', expect_6) + +test.fail_test(failed) + test.pass_test() diff --git a/test/Java/Java-1.6.py b/test/Java/Java-1.6.py index 0b4ddd7..f2b629a 100644 --- a/test/Java/Java-1.6.py +++ b/test/Java/Java-1.6.py @@ -59,6 +59,7 @@ env.Java(target = 'class2', source = 'com/sub/bar') env.Java(target = 'class3', source = ['src1', 'src2']) env.Java(target = 'class4', source = ['src4']) env.Java(target = 'class5', source = ['src5']) +env.Java(target = 'class6', source = ['src6']) """ % locals()) test.subdir('com', @@ -68,7 +69,8 @@ test.subdir('com', 'src1', 'src2', 'src4', - 'src5') + 'src5', + 'src6') test.write(['com', 'sub', 'foo', 'Example1.java'], """\ package com.sub.foo; @@ -274,23 +276,27 @@ class TestSCons { class Foo { } """) -test.run(arguments = '.') +# Test private inner class instantiation, courtesy Tilo Prutz: +# http://scons.tigris.org/issues/show_bug.cgi?id=1594 +test.write(['src6', 'TestSCons.java'], """\ +class test +{ + test() + { + super(); + new inner(); + } -def get_class_files(dir): - def find_class_files(arg, dirname, fnames): - for fname in fnames: - if fname[-6:] == '.class': - arg.append(os.path.join(dirname, fname)) - result = [] - os.path.walk(dir, find_class_files, result) - result.sort() - return result + static class inner + { + private inner() {} + } +} +""") -classes_1 = get_class_files(test.workpath('class1')) -classes_2 = get_class_files(test.workpath('class2')) -classes_3 = get_class_files(test.workpath('class3')) -classes_4 = get_class_files(test.workpath('class4')) -classes_5 = get_class_files(test.workpath('class5')) + + +test.run(arguments = '.') expect_1 = [ test.workpath('class1', 'com', 'other', 'Example2.class'), @@ -328,9 +334,27 @@ expect_5 = [ test.workpath('class5', 'TestSCons.class'), ] +expect_6 = [ + test.workpath('class6', 'test$1.class'), + test.workpath('class6', 'test$inner.class'), + test.workpath('class6', 'test.class'), +] + failed = None -def classes_must_match(dir, expect, got): +def get_class_files(dir): + def find_class_files(arg, dirname, fnames): + for fname in fnames: + if fname[-6:] == '.class': + arg.append(os.path.join(dirname, fname)) + result = [] + os.path.walk(dir, find_class_files, result) + result.sort() + return result + +def classes_must_match(dir, expect): + global failed + got = get_class_files(test.workpath(dir)) if expect != got: sys.stderr.write("Expected the following class files in '%s':\n" % dir) for c in expect: @@ -340,13 +364,40 @@ def classes_must_match(dir, expect, got): sys.stderr.write(' %s\n' % c) failed = 1 -classes_must_match('class1', expect_1, classes_1) -classes_must_match('class2', expect_2, classes_2) -classes_must_match('class3', expect_3, classes_3) -classes_must_match('class4', expect_4, classes_4) +def classes_must_not_exist(dir, expect): + global failed + present = filter(os.path.exists, expect) + if present: + sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir) + for c in present: + sys.stderr.write(' %s\n' % c) + failed = 1 + +classes_must_match('class1', expect_1) +classes_must_match('class2', expect_2) +classes_must_match('class3', expect_3) +classes_must_match('class4', expect_4) +classes_must_match('class5', expect_5) +classes_must_match('class6', expect_6) test.fail_test(failed) test.up_to_date(options='--debug=explain', arguments = '.') +test.run(arguments = '-c .') + +classes_must_not_exist('class1', expect_1) +classes_must_not_exist('class2', expect_2) +classes_must_not_exist('class3', expect_3) +classes_must_not_exist('class4', expect_4) +classes_must_not_exist('class5', expect_5) +# This test case should pass, but doesn't. +# The expect_6 list contains the class files that the Java compiler +# actually creates, apparently because of the "private" instantiation +# of the "inner" class. Our parser doesn't currently detect this, so +# it doesn't know to remove that generated class file. +#classes_must_not_exist('class6', expect_6) + +test.fail_test(failed) + test.pass_test() diff --git a/test/Java/multi-step.py b/test/Java/multi-step.py new file mode 100644 index 0000000..1b69838 --- /dev/null +++ b/test/Java/multi-step.py @@ -0,0 +1,567 @@ +#!/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__" + +""" +Real-world test (courtesy Leanid Nazdrynau) of the multi-step +capabilities of the various Java Builders. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +# This test requires javac and swig +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) +else: + where_javac = test.where_is('javac') +if not where_javac: + test.skip_test("Could not find Java javac, skipping test(s).\n") + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + + + +test.subdir(['src'], + ['src', 'HelloApplet'], + ['src', 'HelloApplet', 'com'], + ['src', 'javah'], + ['src', 'jni'], + ['src', 'server'], + ['src', 'server', 'JavaSource'], + ['src', 'server', 'JavaSource', 'com'], + ['src', 'server', 'JavaSource', 'com', 'gnu'], + ['src', 'server', 'JavaSource', 'com', 'gnu', 'scons'], + ['src', 'server', 'JavaSource', 'com', 'gnu', 'scons', 'web'], + ['src', 'server', 'JavaSource', 'com', 'gnu', 'scons', 'web', 'tools'], + ['src', 'server', 'WebContent'], + ['src', 'server', 'WebContent', 'META-INF'], + ['src', 'server', 'WebContent', 'WEB-INF'], + ['src', 'server', 'WebContent', 'WEB-INF', 'conf'], + ['src', 'server', 'WebContent', 'WEB-INF', 'lib'], + ['src', 'server', 'WebContent', 'theme']) + +test.write(['SConstruct'], """\ +import os,sys +env=Environment(tools = ['default', 'javac', 'javah']) +Export('env') +env.PrependENVPath('PATH',os.environ.get('PATH',[])) +env['INCPREFIX']='-I' +env.Append(SWIGFLAGS=['-c++','$_CPPINCFLAGS']) + +#this is for JNI +#env.Append(CCFLAGS=['/IN:/jdk/v1.3.1/include','/IN:/jdk/v1.3.1/include/win32']) + +#this for windows only C++ build +#env.Append(CXXFLAGS='-GX') + +env.Append(CPPPATH='.') + +env.BuildDir('buildout', 'src', duplicate=0) + +if sys.platform=='darwin': + env.Append(CPPPATH=['/System/Library/Frameworks/JavaVM.framework/Headers']) + +#If you do not have swig on your system please remove 'buildout/jni/SConscript' line from next call +env.SConscript(['buildout/server/JavaSource/SConscript', + 'buildout/HelloApplet/SConscript', + 'buildout/jni/SConscript', + 'buildout/javah/SConscript']) +""") + +test.write(['src', 'HelloApplet', 'Hello.html'], """\ +<HTML> +<HEAD> +<TITLE> Applet Hello </TITLE> +</HEAD> +<BODY> +<CENTER> +<applet name="Hello" archive="HelloApplet.jar" code="com.Hello.Hello.class" + width="800" height="286" MAYSCRIPT> +</applet> +</CENTER> +</BODY> +</HTML> + +""") + +test.write(['src', 'HelloApplet', 'SConscript'], """\ +import os +Import ("env") +denv=env.Copy() +classes=denv.Java(target='classes',source=['com']) +#set correct path for jar +denv['JARCHDIR']=os.path.join(denv.Dir('.').get_abspath(),'classes') +denv.Jar('HelloApplet',classes) + + +#To sign applet you have to create keystore before and made a calls like this + +#keystore='/path/to/jarsignkey' +#denv['JARSIGNFLAGS']='-keystore '+keystore+' -storepass pass -keypass passkey' +#denv['JARSIGNALIAS']='ALIAS' +#denv['JARCOM']=[denv['JARCOM'],'$JARSIGNCOM'] + +""") + +test.write(['src', 'HelloApplet', 'com', 'Hello.java'], """\ +package com.Hello; +import java.awt.*; +import java.applet.*; + +public class Hello extends Applet { + public void paint(Graphics g) { + g.drawString("Hello from SCons signed applet",250,150); + } + } + +""") + +test.write(['src', 'javah', 'MyID.cc'], """\ +#include "MyID.h" +int getMyID() +{ + return 0; +} +""") + +test.write(['src', 'javah', 'MyID.java'], """\ +import java.util.*; +import java.io.IOException; +import java.lang.reflect.*; + +public class MyID +{ + static private long current = System.currentTimeMillis(); + static public String get() + { + current++; + return new Long( current ).toString(); + } +} +""") + +test.write(['src', 'javah', 'SConscript'], """\ +Import('env') +denv=env.Copy() +denv['JARCHDIR']=denv.Dir('.').get_abspath() +denv.Jar('myid','MyID.java') +denv.JavaH(denv.Dir('.').get_abspath(),'MyID.java') +denv.SharedLibrary('myid','MyID.cc') + +""") + +test.write(['src', 'jni', 'A.java'], """\ +package web.jni; + +import web.jni.*; + +public class A +{ +class C +{ + void echo2( String text ) + { + System.out.println( text+"aa" ); + + } +} +class B +{ + void echo( String text ) + { + System.out.println( text ); + C c = new C(); + c.echo2("from B callin C"); + } +} + public void main( String[] x) + { + B b = new B(); + b.echo("123"); + C c = new C(); + c.echo2("456"); + } +} +""") + +test.write(['src', 'jni', 'JniWrapper.cc'], """\ +#include <vector> +#include <iostream> + +#include "JniWrapper.h" + + + +JniWrapper::JniWrapper( JNIEnv *pEnv ) + : mpEnv( pEnv ) +{ +} + +JniWrapper::JniWrapper( const JniWrapper& rJniWrapper ) + : mpEnv( rJniWrapper.mpEnv ) +{ +} + +JniWrapper::~JniWrapper() +{ + +} + +JniWrapper& JniWrapper::operator=( const JniWrapper& rJniWrapper ) +{ + if ( this != &rJniWrapper ) + { + mpEnv = rJniWrapper.mpEnv; + } + return *this; +} + +std::string JniWrapper::unmarshalString( jstring value ) +{ + std::string result; + if( value ) + { + const char *pStr = mpEnv->GetStringUTFChars( value, 0 ); + result = pStr; + mpEnv->ReleaseStringUTFChars( value, pStr ); + } + return result; +} + +jobject JniWrapper::marshalDouble( double value ) +{ + jclass classObject = mpEnv->FindClass( "java/lang/Double" ); + jmethodID constructorId = mpEnv->GetMethodID( classObject, "<init>", "(D)V" ); + jobject result = mpEnv->NewObject( classObject, constructorId, value ); + + return result; +} + +jobject JniWrapper::getVectorElement( jobject values, int i ) +{ + jclass vectorClass = mpEnv->FindClass( "java/util/Vector" ); + jmethodID methodID = mpEnv->GetMethodID( vectorClass, + "elementAt", + "(I)Ljava/lang/Object;" ); + jobject result = mpEnv->CallObjectMethod( values, methodID, i ); + + return result; +} + +jobject JniWrapper::newVector() +{ + jclass vectorClass = mpEnv->FindClass( "java/util/Vector" ); + jmethodID constructorID = mpEnv->GetMethodID( vectorClass, "<init>", "()V" ); + jobject result = mpEnv->NewObject( vectorClass, constructorID ); + + return result; +} + +void JniWrapper::addElement( jobject vector, jobject element ) +{ + jclass vectorClass = mpEnv->FindClass( "java/util/Vector" ); + jmethodID addElementMethodID = mpEnv->GetMethodID( vectorClass, + "addElement", + "(Ljava/lang/Object;)V" ); + + mpEnv->CallVoidMethod( vector, addElementMethodID, element ); +} + +jobject JniWrapper::marshalDoubleVector( const std::vector<double>& rVector ) +{ + jobject result = newVector(); + + for ( int i = 0; i < rVector.size(); i++ ) + { + addElement( result, marshalDouble( rVector[i] ) ); + } + + return result; +} + +std::pair<std::string, std::string> JniWrapper::unmarshalPairString( jobject vector ) +{ + std::pair<std::string, std::string> result; + result.first = unmarshalString( (jstring)getVectorElement( vector, 0 ) ); + result.second = unmarshalString( (jstring)getVectorElement( vector, 1 ) ); + + return result; +} +""") + +test.write(['src', 'jni', 'JniWrapper.h'], """\ +#ifndef JniWrapper_h +#define JniWrapper_h + +#include <jni.h> +/** + * Provides routines for dealing with JNI translation etc. + */ + +class JniWrapper +{ +public: + JniWrapper( JNIEnv *pEnv ); + JniWrapper( const JniWrapper& rJniWrapper ); + virtual ~JniWrapper(); + JniWrapper& operator=( const JniWrapper& rJniWrapper ); + + + std::string unmarshalString( jstring value ); + + jstring marshalString( const std::string& value ); + + jbyteArray marshalByteArray( const std::string& value ); + + double unmarshalDouble( jobject value ); + + jobject marshalDouble( double value ); + jobject marshallStringVector( const std::vector<std::string>& rMap ); + + jobject marshalDoubleVector( const std::vector<double>& rVector ); + std::pair<std::string, std::string> unmarshalPairString( jobject ); + +protected: + JNIEnv *mpEnv; + +private: + JniWrapper(); + jobject newVector(); + void addElement( jobject vector, jobject element ); + jobject getVectorElement( jobject values, int i ); + +}; + +#endif // JniWrapper_h + + +""") + +test.write(['src', 'jni', 'SConscript'], """\ +Import ("env") +denv=env.Copy() + +denv.Append(SWIGFLAGS=['-java']) +denv.SharedLibrary('scons',['JniWrapper.cc','Sample.i']) +denv['JARCHDIR']=denv.Dir('.').get_abspath() +denv.Jar(['Sample.i','A.java']) +""") + +test.write(['src', 'jni', 'Sample.h'], """\ +#include <vector> +#include <iostream> + +class SampleTest +{ +public: + std::vector<double> test1( std::pair<std::string, std::string> param ) + { + std::vector<double> result; + result.push_back(10); + return result; + } +}; + +""") + +test.write(['src', 'jni', 'Sample.i'], """\ +%module Sample + +%{ +#include "Sample.h" +#include "JniWrapper.h" +%} + +%typemap(jni) std::vector<double>, std::vector<double>& "jobject" +%typemap(jtype) std::vector<double>, std::vector<double>& "java.util.Vector" +%typemap(jstype) std::vector<double>, std::vector<double>& "java.util.Vector" + +// return a Vector of Doubles +%typemap(javaout) std::vector<double> { + return $jnicall; +} +%typemap(out) std::vector<double> { + JniWrapper JniWrapper(jenv); + $result = JniWrapper.marshalDoubleVector( $1 ); +} + +/********************************************************************* + * + * Pairs of String (IN/OUT) + * + *********************************************************************/ +%typemap(jni) std::pair<std::string, std::string>, const std::pair<std::string, std::string>& "jobject" +%typemap(jtype) std::pair<std::string, std::string>, const std::pair<std::string, std::string>& "java.util.Vector" +%typemap(jstype) std::pair<std::string, std::string>, const std::pair<std::string, std::string>& "java.util.Vector" +%typemap(javain) std::pair<std::string, std::string>, const std::pair<std::string, std::string>& "$javainput" + +// pass in by reference a Vector of std::string +%typemap(in) const std::pair<std::string, std::string>& { + $1 = new std::pair<std::string, std::string>(); + JniWrapper JniWrapper(jenv); + *($1) = JniWrapper.unmarshalPairString( $input ); +} + +//cleanup +%typemap(freearg) const std::pair<std::string, std::string>& { + delete $1; +} + +%include "Sample.h" + +// generate:Sample.java +// generate:SampleJni.java +// generate:SampleTest.java +""") + +test.write(['src', 'server', 'JavaSource', 'SConscript'], """\ +import os +Import ("env") +classes=env.Java(target='classes',source=['com']) + +HelloApplet=os.path.join('#/buildout/HelloApplet/HelloApplet.jar') +env['WARXFILES']=['SConscript','.cvsignore'] +env['WARXDIRS']=['CVS'] +#env.War('scons',[classes,Dir('../WebContent'),HelloApplet]) +""") + +test.write(['src', 'server', 'JavaSource', 'com', 'gnu', 'scons', 'web', 'tools', 'Bool.java'], """\ +package com.gnu.scons.web.tools; +public class Bool { + boolean flag; + + public Bool() + { + flag = false; + } + + public Bool( boolean aFlag ) + { + flag = aFlag; + } + + public boolean booleanValue() + { + return flag; + } +} +""") + +test.write(['src', 'server', 'JavaSource', 'com', 'gnu', 'scons', 'web', 'tools', 'StringUtils.java'], """\ +package com.gnu.scons.web.tools; + +import java.util.Iterator; +import java.util.Map; + +public class StringUtils +{ + public static String toPercent( String value ) + { + if ( value.equals("") ) + { + return ""; + } + else + { + return value + "%"; + } + } + +} +""") + +test.write(['src', 'server', 'WebContent', 'index.html'], """\ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<HTML> +<HEAD> +<META http-equiv="refresh" content="0;URL=go?action=home"> +<TITLE>index.html</TITLE> +</HEAD> +<BODY> +<P><a href="go?action=home">go?action=home</a></P> +</BODY> +</HTML> +""") + +test.write(['src', 'server', 'WebContent', 'META-INF', 'MANIFEST.MF'], """\ +Manifest-Version: 1.0 +Class-Path: + +""") + +test.write(['src', 'server', 'WebContent', 'WEB-INF', 'web.xml'], """\ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> +<web-app id="WebExample"> + <display-name>scons</display-name> + <servlet> + <servlet-name>WebExample</servlet-name> + <display-name>WebExample</display-name> + <servlet-class>com.gnu.scons.web.tool.WebExample</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>WebExample</servlet-name> + <url-pattern>/go</url-pattern> + </servlet-mapping> + <welcome-file-list> + <welcome-file>index.html</welcome-file> + <welcome-file>index.htm</welcome-file> + </welcome-file-list> +</web-app> +""") + +test.write(['src', 'server', 'WebContent', 'WEB-INF', 'conf', 'app.properties'], """\ +logging = webExample.Example +""") + +test.write(['src', 'server', 'WebContent', 'theme', 'Master.css'], """\ +body +{ + font-family: Helvetica,Sans-Serif; + font-size: 11pt; +} +""") + +test.run(arguments = '.') + +test.must_exist(['buildout', 'javah', 'myid.jar']) +test.must_exist(['buildout', 'javah', 'MyID', 'MyID.class']) + +test.must_exist(['buildout', 'jni', 'Sample.class']) +test.must_exist(['buildout', 'jni', 'Sample.java']) +test.must_exist(['buildout', 'jni', 'SampleJNI.class']) +test.must_exist(['buildout', 'jni', 'SampleJNI.java']) +test.must_exist(['buildout', 'jni', 'SampleTest.class']) +test.must_exist(['buildout', 'jni', 'SampleTest.java']) + +test.up_to_date(arguments = '.') + +test.pass_test() diff --git a/test/Java/source-files.py b/test/Java/source-files.py new file mode 100644 index 0000000..8d2506f --- /dev/null +++ b/test/Java/source-files.py @@ -0,0 +1,127 @@ +#!/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 we can pass the Java() builder explicit lists of .java +files as sources. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) +else: + where_javac = test.where_is('javac') +if not where_javac: + test.skip_test("Could not find Java javac, skipping test(s).\n") + + +test.write('SConstruct', """ +env = Environment(tools = ['javac', 'javah'], + JAVAC = r'%(where_javac)s') +env.Java(target = 'class1', source = 'com/Example1.java') +env.Java(target = 'class2', source = ['com/Example2.java', 'com/Example3.java']) +""" % locals()) + +test.subdir('com', 'src') + +test.write(['com', 'Example1.java'], """\ +package com; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'Example2.java'], """\ +package com; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'Example3.java'], """\ +package com; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'Example4.java'], """\ +package com; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.run(arguments = '.') + +test.must_exist (['class1', 'com', 'Example1.class']) +test.must_not_exist(['class1', 'com', 'Example2.class']) +test.must_not_exist(['class1', 'com', 'Example3.class']) +test.must_not_exist(['class1', 'com', 'Example4.class']) + +test.must_not_exist(['class2', 'com', 'Example1.class']) +test.must_exist (['class2', 'com', 'Example2.class']) +test.must_exist (['class2', 'com', 'Example3.class']) +test.must_not_exist(['class2', 'com', 'Example4.class']) + +test.up_to_date(arguments = '.') + +test.pass_test() diff --git a/test/Java/swig-dependencies.py b/test/Java/swig-dependencies.py new file mode 100644 index 0000000..c6961f2 --- /dev/null +++ b/test/Java/swig-dependencies.py @@ -0,0 +1,135 @@ +#!/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 dependencies on SWIG-generated .java files work correctly. + +Test case courtesy Jonathan (toolshed@tigris.org). +""" + +import TestSCons + +test = TestSCons.TestSCons() + +ENV = test.java_ENV() +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) +else: + where_javac = test.where_is('javac') +if not where_javac: + test.skip_test("Could not find Java javac, skipping test(s).\n") + +if test.detect_tool('jar', ENV=ENV): + where_jar = test.detect('JAR', 'jar', ENV=ENV) +else: + where_jar = test.where_is('jar') +if not where_jar: + test.skip_test("Could not find Java jar, skipping test(s).\n") + + +test.subdir(['foo'], + ['java'], + ['java', 'build']) + +test.write(['SConstruct'], """\ +import os + +env = Environment(ENV = os.environ) + +env.Append(CPPFLAGS = ' -g -Wall') + +Export('env') + +SConscript('#foo/SConscript') +SConscript('#java/SConscript') +""") + +test.write(['foo', 'SConscript'], """\ +Import('env') + +env.SharedLibrary('foo', 'foo.cpp') +""") + +test.write(['foo', 'foo.cpp'], """\ +#include "foo.h" + +int fooAdd(int a, int b) { + return a + b; +} +""") + +test.write(['foo', 'foo.h'], """\ +int fooAdd(int, int); +""") + +test.write(['java', 'Java_foo_interface.i'], """\ +#include "foo.h" + +%module foopack +""") + +test.write(['java', 'SConscript'], """\ +import os + +Import('env') + +# unnecessary? +env = env.Copy() + +env.Prepend(CPPPATH = ['#foo',]) + +libadd = ['foo',] + +libpath = ['#foo',] + +#swigflags = '-c++ -java -Wall -package foopack -Ifoo' +swigflags = '-c++ -java -Wall -Ifoo' + +Java_foo_interface = env.SharedLibrary( + 'Java_foo_interface', + 'Java_foo_interface.i', + LIBS = libadd, + LIBPATH = libpath, + SWIGFLAGS = swigflags, + SWIGOUTDIR = Dir('build'), + SWIGCXXFILESUFFIX = "_wrap.cpp") + +foopack_jar_javac = env.Java('classes', 'build') + +env['JARCHDIR'] = 'java/classes' +foopack_jar = env.Jar(target = 'foopack.jar', source = 'classes') +""") + +test.run(arguments = '.') + +#test.must_exist(['java', 'classes', 'foopack', 'foopack.class']) +#test.must_exist(['java', 'classes', 'foopack', 'foopackJNI.class']) +test.must_exist(['java', 'classes', 'foopack.class']) +test.must_exist(['java', 'classes', 'foopackJNI.class']) + +test.up_to_date(arguments = '.') + +test.pass_test() diff --git a/test/LEX/LEXFLAGS.py b/test/LEX/LEXFLAGS.py index b6a06fa..e72fa9e 100644 --- a/test/LEX/LEXFLAGS.py +++ b/test/LEX/LEXFLAGS.py @@ -35,36 +35,42 @@ _exe = TestSCons._exe test = TestSCons.TestSCons() +test.subdir('in') + test.write('mylex.py', """ import getopt import string import sys -cmd_opts, args = getopt.getopt(sys.argv[1:], 'tx', []) +cmd_opts, args = getopt.getopt(sys.argv[1:], 'I:tx', []) opt_string = '' +i_arguments = '' for opt, arg in cmd_opts: - opt_string = opt_string + ' ' + opt + if opt == '-I': i_arguments = i_arguments + ' ' + arg + else: opt_string = opt_string + ' ' + opt for a in args: contents = open(a, 'rb').read() - sys.stdout.write(string.replace(contents, 'LEXFLAGS', opt_string)) + contents = string.replace(contents, 'LEXFLAGS', opt_string) + contents = string.replace(contents, 'I_ARGS', i_arguments) + sys.stdout.write(contents) sys.exit(0) """) test.write('SConstruct', """ env = Environment(LEX = r'%(_python_)s mylex.py', - LEXFLAGS = '-x', + LEXFLAGS = '-x -I${TARGET.dir} -I${SOURCE.dir}', tools=['default', 'lex']) -env.CFile(target = 'aaa', source = 'aaa.l') +env.CFile(target = 'out/aaa', source = 'in/aaa.l') """ % locals()) -test.write('aaa.l', "aaa.l\nLEXFLAGS\n") +test.write(['in', 'aaa.l'], "aaa.l\nLEXFLAGS\nI_ARGS\n") test.run('.', stderr = None) # Read in with mode='r' because mylex.py implicitley wrote to stdout # with mode='w'. -test.must_match('aaa.c', "aaa.l\n -x -t\n", mode='r') +test.must_match(['out', 'aaa.c'], "aaa.l\n -x -t\n out in\n", mode='r') diff --git a/test/SWIG/SWIG.py b/test/SWIG/SWIG.py index dfee5ef..491cb7c 100644 --- a/test/SWIG/SWIG.py +++ b/test/SWIG/SWIG.py @@ -28,26 +28,15 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" Verify that the swig tool generates file names that we expect. """ -import os -import string -import sys import TestSCons -if sys.platform =='darwin': - # change to make it work with stock OS X python framework - # we can't link to static libpython because there isn't one on OS X - # so we link to a framework version. However, testing must also - # use the same version, or else you get interpreter errors. - python = "/System/Library/Frameworks/Python.framework/Versions/Current/bin/python" - _python_ = '"' + python + '"' -else: - _python_ = TestSCons._python_ - _exe = TestSCons._exe _obj = TestSCons._obj test = TestSCons.TestSCons() +_python_ = test.get_quoted_platform_python() + test.write('myswig.py', r""" diff --git a/test/SWIG/SWIGFLAGS.py b/test/SWIG/SWIGFLAGS.py new file mode 100644 index 0000000..22c311b --- /dev/null +++ b/test/SWIG/SWIGFLAGS.py @@ -0,0 +1,69 @@ +#!/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 we can use ${SOURCE} expansions in $SWIGFLAGS. +""" + +import sys + +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') + +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + + + +test.subdir('src') + +test.write(['src', 'foo.i'], """\ +%module foo + +%include bar.i +""") + +test.write(['src', 'bar.i'], """\ +%module bar +""") + +test.write('SConstruct', """ +# Note that setting the -I option in $SWIGFLAGS is not good and the +# documentation says to use $SWIGPATH. This is just for testing. +env = Environment(SWIGFLAGS='-python -I${SOURCE.dir}') +env.CFile(target = 'foo', source = ['src/foo.i']) +""") + +test.run() + +test.up_to_date(arguments = "foo_wrap.c") + + + +test.pass_test() diff --git a/test/SWIG/SWIGOUTDIR.py b/test/SWIG/SWIGOUTDIR.py index 69d535c..b638a3b 100644 --- a/test/SWIG/SWIGOUTDIR.py +++ b/test/SWIG/SWIGOUTDIR.py @@ -29,10 +29,21 @@ Verify that use of the $SWIGOUTDIR variable causes SCons to recognize that Java files are created in the specified output directory. """ +import sys + import TestSCons test = TestSCons.TestSCons() +test = TestSCons.TestSCons() + +swig = test.where_is('swig') + +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + + + test.write(['SConstruct'], """\ env = Environment(tools = ['default', 'swig']) diff --git a/test/SWIG/SWIGPATH.py b/test/SWIG/SWIGPATH.py new file mode 100644 index 0000000..dd2db47 --- /dev/null +++ b/test/SWIG/SWIGPATH.py @@ -0,0 +1,91 @@ +#!/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 SWIGPATH finds dependency files in subdirectories. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') + +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +_python_ = test.get_quoted_platform_python() + + + +test.subdir('inc1', 'inc2') + +test.write(['inc2', 'dependency.i'], """\ +%module dependency +""") + +test.write("dependent.i", """\ +%module dependent + +%include dependency.i +""") + +test.write('SConstruct', """ +foo = Environment(SWIGFLAGS='-python', + SWIGPATH=['inc1', 'inc2']) +swig = foo.Dictionary('SWIG') +bar = foo.Clone(SWIG = r'%(_python_)s wrapper.py ' + swig) +foo.CFile(target = 'dependent', source = ['dependent.i']) +""" % locals()) + +test.run() + +test.up_to_date(arguments = "dependent_wrap.c") + +test.write(['inc1', 'dependency.i'], """\ +%module dependency + +extern char *dependency_1(); +""") + +test.not_up_to_date(arguments = "dependent_wrap.c") + +test.write(['inc2', 'dependency.i'], """\ +%module dependency +extern char *dependency_2(); +""") + +test.up_to_date(arguments = "dependent_wrap.c") + +test.unlink(['inc1', 'dependency.i']) + +test.not_up_to_date(arguments = "dependent_wrap.c") + +test.up_to_date(arguments = "dependent_wrap.c") + + + +test.pass_test() diff --git a/test/SWIG/build-dir.py b/test/SWIG/build-dir.py new file mode 100644 index 0000000..593a26a --- /dev/null +++ b/test/SWIG/build-dir.py @@ -0,0 +1,167 @@ +#!/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__" + +""" +Make sure SWIG works when a BuildDir (or build_dir) is used. + +Test case courtesy Joe Maruszewski. +""" + +import os.path +import sys + +import TestSCons + +test = TestSCons.TestSCons() + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.dll' +else: + _dll = '.so' + +test.subdir(['source']) + +python_include_dir = test.get_python_inc() + +Python_h = os.path.join(python_include_dir, 'Python.h') + +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +python_frameworks_flags = test.get_python_frameworks_flags() + +test.write(['SConstruct'], """\ +# +# Create the build environment. +# +env = Environment(CPPPATH = [".", r'%(python_include_dir)s'], + CPPDEFINES = "NDEBUG", + SWIGFLAGS = ["-python", "-c++"], + SWIGCXXFILESUFFIX = "_wrap.cpp", + LDMODULEPREFIX='_', + LDMODULESUFFIX='%(_dll)s', + FRAMEWORKSFLAGS='%(python_frameworks_flags)s') + +import sys +if sys.version[0] == '1': + # SWIG requires the -classic flag on pre-2.0 Python versions. + env.Append(SWIGFLAGS = '-classic') + +Export("env") + +# +# Build the libraries. +# +SConscript("source/SConscript", build_dir = "build") +""" % locals()) + +test.write(['source', 'SConscript'], """\ +Import("env") +lib = env.SharedLibrary("_linalg", + "linalg.i", + SHLIBPREFIX = "", + SHLIBSUFFIX = ".pyd") +""") + +test.write(['source', 'Vector.hpp'], """\ +class Vector +{ + public: + Vector(int size = 0) : _size(size) + { + _v = new double[_size]; + for (int i = 0; i < _size; ++i) + _v[i] = 0.0; + } + + ~Vector() { delete [] _v; } + + int size() const { return _size; } + + double& operator[](int key) { return _v[key]; } + double const& operator[](int key) const { return _v[key]; } + + private: + int _size; + double* _v; +}; +""") + +test.write(['source', 'linalg.i'], """\ +%module linalg +%{ +#include <sstream> +#include "Vector.hpp" +%} + + +class Vector +{ +public: + Vector(int n = 0); + ~Vector(); + + %extend + { + const char* __str__() { return "linalg.Vector()"; } + int __len__() { return $self->size(); } + double __getitem__(int key) { return $self->operator[](key); } + void __setitem__(int key, double value) { $self->operator[](key) = value; } + + %pythoncode %{ + def __iter__(self): + for i in xrange(len(self)): + yield self[i] + %} + } +}; +""") + +test.write(['source', 'test.py'], """\ +#!/usr/bin/env python +import linalg + + +x = linalg.Vector(5) +print x + +x[1] = 99.5 +x[3] = 8.3 +x[4] = 11.1 + + +for i, v in enumerate(x): + print "\tx[%d] = %g" % (i, v) + +""") + +test.run(arguments = '.') + +test.up_to_date(arguments = '.') + +test.pass_test() diff --git a/test/SWIG/implicit-dependencies.py b/test/SWIG/implicit-dependencies.py index 81e3cf9..9b3eb8e 100644 --- a/test/SWIG/implicit-dependencies.py +++ b/test/SWIG/implicit-dependencies.py @@ -32,17 +32,6 @@ import sys import TestSCons -if sys.platform =='darwin': - # change to make it work with stock OS X python framework - # we can't link to static libpython because there isn't one on OS X - # so we link to a framework version. However, testing must also - # use the same version, or else you get interpreter errors. - python = "/System/Library/Frameworks/Python.framework/Versions/Current/bin/python" - _python_ = '"' + python + '"' -else: - python = TestSCons.python - _python_ = TestSCons._python_ - test = TestSCons.TestSCons() swig = test.where_is('swig') @@ -50,10 +39,9 @@ swig = test.where_is('swig') if not swig: test.skip_test('Can not find installed "swig", skipping test.\n') +_python_ = test.get_quoted_platform_python() -version = sys.version[:3] # see also sys.prefix documentation - test.write("dependency.i", """\ %module dependency diff --git a/test/SWIG/live.py b/test/SWIG/live.py index d319af7..5070d8e 100644 --- a/test/SWIG/live.py +++ b/test/SWIG/live.py @@ -34,17 +34,6 @@ import sys import TestSCons -if sys.platform =='darwin': - # change to make it work with stock OS X python framework - # we can't link to static libpython because there isn't one on OS X - # so we link to a framework version. However, testing must also - # use the same version, or else you get interpreter errors. - python = "/System/Library/Frameworks/Python.framework/Versions/Current/bin/python" - _python_ = '"' + python + '"' -else: - python = TestSCons.python - _python_ = TestSCons._python_ - # swig-python expects specific filenames. # the platform specific suffix won't necessarily work. if sys.platform == 'win32': @@ -59,29 +48,22 @@ swig = test.where_is('swig') if not swig: test.skip_test('Can not find installed "swig", skipping test.\n') +python = test.get_platform_python() +_python_ = test.get_quoted_platform_python() -version = sys.version[:3] # see also sys.prefix documentation # handle testing on other platforms: ldmodule_prefix = '_' -frameworks = '' -platform_sys_prefix = sys.prefix -if sys.platform == 'darwin': - # OS X has a built-in Python but no static libpython - # so you should link to it using apple's 'framework' scheme. - # (see top of file for further explanation) - frameworks = '-framework Python' - platform_sys_prefix = '/System/Library/Frameworks/Python.framework/Versions/%s/' % version - -python_include_dir = os.path.join(platform_sys_prefix, - 'include', - 'python' + version) +python_include_dir = test.get_python_inc() + Python_h = os.path.join(python_include_dir, 'Python.h') if not os.path.exists(Python_h): test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +python_frameworks_flags = test.get_python_frameworks_flags() test.write("wrapper.py", """import os @@ -96,7 +78,7 @@ foo = Environment(SWIGFLAGS='-python', CPPPATH='%(python_include_dir)s/', LDMODULEPREFIX='%(ldmodule_prefix)s', LDMODULESUFFIX='%(_dll)s', - FRAMEWORKSFLAGS='%(frameworks)s', + FRAMEWORKSFLAGS='%(python_frameworks_flags)s', ) import sys diff --git a/test/SWIG/noproxy.py b/test/SWIG/noproxy.py index c0f6da6..8b0adb0 100644 --- a/test/SWIG/noproxy.py +++ b/test/SWIG/noproxy.py @@ -33,17 +33,6 @@ import sys import TestSCons -if sys.platform =='darwin': - # change to make it work with stock OS X python framework - # we can't link to static libpython because there isn't one on OS X - # so we link to a framework version. However, testing must also - # use the same version, or else you get interpreter errors. - python = "/System/Library/Frameworks/Python.framework/Versions/Current/bin/python" - _python_ = '"' + python + '"' -else: - python = TestSCons.python - _python_ = TestSCons._python_ - # swig-python expects specific filenames. # the platform specific suffix won't necessarily work. if sys.platform == 'win32': @@ -58,21 +47,14 @@ swig = test.where_is('swig') if not swig: test.skip_test('Can not find installed "swig", skipping test.\n') - - -version = sys.version[:3] # see also sys.prefix documentation +_python_ = test.get_quoted_platform_python() # handle testing on other platforms: ldmodule_prefix = '_' -frameworks = '' -platform_sys_prefix = sys.prefix -if sys.platform == 'darwin': - # OS X has a built-in Python but no static libpython - # so you should link to it using apple's 'framework' scheme. - # (see top of file for further explanation) - frameworks = '-framework Python' - platform_sys_prefix = '/System/Library/Frameworks/Python.framework/Versions/%s/' % version +python_include_dir = test.get_python_inc() + +python_frameworks_flags = test.get_python_frameworks_flags() test.write("dependency.i", """\ %module dependency @@ -86,10 +68,10 @@ test.write("dependent.i", """\ test.write('SConstruct', """ foo = Environment(SWIGFLAGS=['-python', '-noproxy'], - CPPPATH='%(platform_sys_prefix)s/include/python%(version)s/', + CPPPATH='%(python_include_dir)s', LDMODULEPREFIX='%(ldmodule_prefix)s', LDMODULESUFFIX='%(_dll)s', - FRAMEWORKSFLAGS='%(frameworks)s', + FRAMEWORKSFLAGS='%(python_frameworks_flags)s', ) swig = foo.Dictionary('SWIG') diff --git a/test/SWIG/remove-modules.py b/test/SWIG/remove-modules.py index f5d4010..5f15dcf 100644 --- a/test/SWIG/remove-modules.py +++ b/test/SWIG/remove-modules.py @@ -50,27 +50,17 @@ if not swig: -version = sys.version[:3] # see also sys.prefix documentation - # handle testing on other platforms: ldmodule_prefix = '_' -frameworks = '' -platform_sys_prefix = sys.prefix -if sys.platform == 'darwin': - # OS X has a built-in Python but no static libpython - # so you should link to it using apple's 'framework' scheme. - # (see top of file for further explanation) - frameworks = '-framework Python' - platform_sys_prefix = '/System/Library/Frameworks/Python.framework/Versions/%s/' % version - -python_include_dir = os.path.join(platform_sys_prefix, - 'include', - 'python' + version) +python_include_dir = test.get_python_inc() + Python_h = os.path.join(python_include_dir, 'Python.h') if not os.path.exists(Python_h): test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +python_frameworks_flags = test.get_python_frameworks_flags() test.write("module.i", """\ @@ -79,10 +69,10 @@ test.write("module.i", """\ test.write('SConstruct', """ foo = Environment(SWIGFLAGS='-python', - CPPPATH='%(platform_sys_prefix)s/include/python%(version)s/', + CPPPATH='%(python_include_dir)s', LDMODULEPREFIX='%(ldmodule_prefix)s', LDMODULESUFFIX='%(_dll)s', - FRAMEWORKSFLAGS='%(frameworks)s', + FRAMEWORKSFLAGS='%(python_frameworks_flags)s', ) import sys diff --git a/test/Scanner/generated.py b/test/Scanner/generated.py index 99b5787..2dfd322 100644 --- a/test/Scanner/generated.py +++ b/test/Scanner/generated.py @@ -232,12 +232,13 @@ for k in fromdict.keys(): # do env.subst on: # $RMIC $RMICFLAGS -d ${TARGET.attributes.java_lookupdir} ... # When $TARGET is None, so $TARGET.attributes would throw an - # exception. + # exception, which SCons would turn into a UserError. They're + # not important for this test, so just catch 'em. f = fromdict[k] - if SCons.Util.is_String(f) and \ - string.find(f, "TARGET") == -1 and \ - string.find(f, "SOURCE") == -1: + try: todict[k] = env.subst(f) + except SCons.Errors.UserError: + pass todict["CFLAGS"] = fromdict["CPPFLAGS"] + " " + \ string.join(map(lambda x: "-I" + x, env["CPPPATH"])) + " " + \ string.join(map(lambda x: "-L" + x, env["LIBPATH"])) diff --git a/test/TEX/auxiliaries.py b/test/TEX/auxiliaries.py index 39984b3..e189d57 100644 --- a/test/TEX/auxiliaries.py +++ b/test/TEX/auxiliaries.py @@ -124,7 +124,7 @@ ps_output_1 = test.read(['build', 'docs', 'test.ps']) # Adding blank lines will cause SCons to re-run the builds, but the # actual contents of the output files should be the same modulo -# the CreationDate header. +# the CreationDate header and some other PDF garp. test.write(['docs', 'test.tex'], tex_input + "\n\n\n") test.run(stderr=None) @@ -137,7 +137,19 @@ ps_output_2 = test.read(['build', 'docs', 'test.ps']) pdf_output_1 = test.normalize_pdf(pdf_output_1) pdf_output_2 = test.normalize_pdf(pdf_output_2) -assert pdf_output_1 == pdf_output_2, test.diff_substr(pdf_output_1, pdf_output_2, 80, 80) +if pdf_output_1 != pdf_output_2: + import sys + test.write(['build', 'docs', 'test.normalized.1.pdf'], pdf_output_1) + test.write(['build', 'docs', 'test.normalized.2.pdf'], pdf_output_2) + sys.stdout.write("***** 1 and 2 are different!\n") + sys.stdout.write(test.diff_substr(pdf_output_1, pdf_output_2, 80, 80) + '\n') + sys.stdout.write("Output from run 1:\n") + sys.stdout.write(test.stdout(-1) + '\n') + sys.stdout.write("Output from run 2:\n") + sys.stdout.write(test.stdout() + '\n') + sys.stdout.flush() + test.fail_test() + assert ps_output_1 == ps_output_2, test.diff_substr(ps_output_1, ps_output_2, 80, 80) diff --git a/test/TEX/bibtex-latex-rerun.py b/test/TEX/bibtex-latex-rerun.py index a0ba5c2..9191713 100644 --- a/test/TEX/bibtex-latex-rerun.py +++ b/test/TEX/bibtex-latex-rerun.py @@ -98,13 +98,24 @@ pdf_output_3 = test.read('bibtest.pdf') # If the PDF file is now different than the second run, modulo the -# creation timestamp and the ID, then something else odd has happened, -# so fail. +# creation timestamp and the ID and some other PDF garp, then something +# else odd has happened, so fail. pdf_output_2 = test.normalize_pdf(pdf_output_2) pdf_output_3 = test.normalize_pdf(pdf_output_3) -assert pdf_output_2 == pdf_output_3, test.diff_substr(pdf_output_2, pdf_output_3, 80, 80) +if pdf_output_2 != pdf_output_3: + import sys + test.write('bibtest.normalized.2.pdf', pdf_output_2) + test.write('bibtest.normalized.3.pdf', pdf_output_3) + sys.stdout.write("***** 2 and 3 are different!\n") + sys.stdout.write(test.diff_substr(pdf_output_2, pdf_output_3, 80, 80) + '\n') + sys.stdout.write("Output from run 2:\n") + sys.stdout.write(test.stdout(-2) + '\n') + sys.stdout.write("Output from run 3:\n") + sys.stdout.write(test.stdout() + '\n') + sys.stdout.flush() + test.fail_test() diff --git a/test/YACC/YACCFLAGS.py b/test/YACC/YACCFLAGS.py index b7e2167..91b391b 100644 --- a/test/YACC/YACCFLAGS.py +++ b/test/YACC/YACCFLAGS.py @@ -42,37 +42,43 @@ else: test = TestSCons.TestSCons() +test.subdir('in') + test.write('myyacc.py', """ import getopt import string import sys -cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:x', []) +cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:I:x', []) output = None opt_string = '' +i_arguments = '' for opt, arg in cmd_opts: if opt == '-o': output = open(arg, 'wb') + elif opt == '-I': i_arguments = i_arguments + ' ' + arg else: opt_string = opt_string + ' ' + opt for a in args: contents = open(a, 'rb').read() - output.write(string.replace(contents, 'YACCFLAGS', opt_string)) + contents = string.replace(contents, 'YACCFLAGS', opt_string) + contents = string.replace(contents, 'I_ARGS', i_arguments) + output.write(contents) output.close() sys.exit(0) """) test.write('SConstruct', """ env = Environment(YACC = r'%(_python_)s myyacc.py', - YACCFLAGS = '-x', + YACCFLAGS = '-x -I${TARGET.dir} -I${SOURCE.dir}', tools=['yacc', '%(linker)s', '%(compiler)s']) -env.CFile(target = 'aaa', source = 'aaa.y') +env.CFile(target = 'out/aaa', source = 'in/aaa.y') """ % locals()) -test.write('aaa.y', "aaa.y\nYACCFLAGS\n") +test.write(['in', 'aaa.y'], "aaa.y\nYACCFLAGS\nI_ARGS\n") test.run('.', stderr = None) -test.must_match('aaa.c', "aaa.y\n -x\n") +test.must_match(['out', 'aaa.c'], "aaa.y\n -x\n out in\n") diff --git a/test/import.py b/test/import.py index a26d745..9c5d3af 100644 --- a/test/import.py +++ b/test/import.py @@ -29,6 +29,7 @@ Verify that we can import and use the contents of Platform and Tool modules directly. """ +import os import re import sys @@ -36,6 +37,14 @@ import TestSCons test = TestSCons.TestSCons() +# Before executing the any of the platform or tool modules, add some +# null entries to the environment $PATH variable to make sure there's +# no code that tries to index elements from the list before making sure +# they're non-null. +# (This was a problem in checkpoint release 0.97.d020070809.) +os.environ['PATH'] = os.pathsep + os.environ['PATH'] + \ + os.pathsep + os.pathsep + '/no/such/dir' + os.pathsep + SConstruct_path = test.workpath('SConstruct') platforms = [ @@ -216,6 +225,7 @@ env = Environment(tools = ['%(tool)s']) import SCons.Tool.%(tool)s env = Environment() +SCons.Tool.%(tool)s.exists(env) SCons.Tool.%(tool)s.generate(env) """ diff --git a/test/long-lines.py b/test/long-lines.py index 1c501e3..340cd9a 100644 --- a/test/long-lines.py +++ b/test/long-lines.py @@ -46,6 +46,13 @@ elif sys.platform == 'cygwin': arflag = 'o' linkflag_init = '-L' + test.workpath() linkflag = ' -L' + test.workpath() +elif sys.platform in ('darwin', 'irix6'): + lib_shared_dll = 'libshared' + TestSCons._dll + lib_static_lib = 'libstatic.a' + arflag_init = 'r' + arflag = 'v' + linkflag_init = '-L' + test.workpath() + linkflag = ' -L' + test.workpath() else: lib_shared_dll = 'libshared.so' lib_static_lib = 'libstatic.a' diff --git a/test/option--random.py b/test/option--random.py index 8c7ef1e..eebd34e 100644 --- a/test/option--random.py +++ b/test/option--random.py @@ -64,7 +64,7 @@ test.run(arguments = '-n -Q') non_random_output = test.stdout() tries = 0 -max_tries = 3 +max_tries = 10 while test.stdout() == non_random_output: if tries >= max_tries: print "--random generated the non-random output %s times!" % max_tries @@ -82,7 +82,7 @@ test.run(arguments = '-n -Q') non_random_output = test.stdout() tries = 0 -max_tries = 3 +max_tries = 10 while test.stdout() == non_random_output: if tries >= max_tries: print "--random generated the non-random output %s times!" % max_tries diff --git a/test/option/debug-time.py b/test/option/debug-time.py index bf18b97..e8873cf 100644 --- a/test/option/debug-time.py +++ b/test/option/debug-time.py @@ -117,6 +117,7 @@ scons_time = get_scons_time(stdout) command_time = get_command_time(stdout) failures = [] +warnings = [] if not within_tolerance(expected_command_time, command_time, 0.01): failures.append("""\ @@ -134,15 +135,21 @@ outside of the 1%% tolerance. """ % locals()) if not within_tolerance(total_time, expected_total_time, 0.15): - failures.append("""\ -SCons -j1 reported total build time of %(total_time)s, + # This tolerance check seems empirically to work fine if there's + # a light load on the system, but on a heavily loaded system the + # timings get screwy and it can fail frequently. Some obvious + # attempts to work around the problem didn't, so just treat it as + # a warning for now. + warnings.append("""\ +Warning: SCons -j1 reported total build time of %(total_time)s, but the actual measured build time was %(expected_total_time)s (end-to-end time of %(complete_time)s less Python overhead of %(overhead)s), outside of the 15%% tolerance. """ % locals()) +if failures or warnings: + print string.join([test.stdout()] + failures + warnings, '\n') if failures: - print string.join([test.stdout()] + failures, '\n') test.fail_test(1) test.run(arguments = "--debug=time . SLEEP=0") diff --git a/test/option/tree-all.py b/test/option/tree-all.py index 92b9065..ec7c7d8 100644 --- a/test/option/tree-all.py +++ b/test/option/tree-all.py @@ -122,14 +122,14 @@ tree3 = """ +-. +-Bar.c +-Bar.ooo - | +-[Bar.c] + | +-Bar.c | +-Bar.h | +-Foo.h +-Foo.c +-Foo.ooo - | +-[Foo.c] - | +-[Foo.h] - | +-[Bar.h] + | +-Foo.c + | +-Foo.h + | +-Bar.h +-Foo.xxx | +-[Foo.ooo] | +-[Bar.ooo] diff --git a/test/option/tree-derived.py b/test/option/tree-derived.py index a10faa2..3ccada8 100644 --- a/test/option/tree-derived.py +++ b/test/option/tree-derived.py @@ -98,8 +98,8 @@ dtree3 = """ +-bar.ooo +-foo.ooo +-foo.xxx - +-[foo.ooo] - +-[bar.ooo] + +-foo.ooo + +-bar.ooo """ test.run(arguments = "--tree=derived,prune .") diff --git a/test/packaging/msi/file-placement.py b/test/packaging/msi/file-placement.py index 08b0ba6..c2aaf35 100644 --- a/test/packaging/msi/file-placement.py +++ b/test/packaging/msi/file-placement.py @@ -37,17 +37,19 @@ test = TestSCons.TestSCons() try: from xml.dom.minidom import * except ImportError: - test.skip_test('Canoot import xml.dom.minidom skipping test\n') + test.skip_test('Cannot import xml.dom.minidom; skipping test\n') wix = test.Environment().WhereIs('candle') -if wix: - # - # Test the default directory layout - # - test.write( 'file1.exe', "file1" ) +if not wix: + test.skip_test("No 'candle' found; skipping test\n") - test.write('SConstruct', """ +# +# Test the default directory layout +# +test.write( 'file1.exe', "file1" ) + +test.write('SConstruct', """ env = Environment(tools=['default', 'packaging']) f1 = env.Install( '/bin/' , 'file1.exe' ) @@ -61,28 +63,28 @@ env.Package( NAME = 'foo', ) """) - test.run(arguments='', stderr = None) +test.run(arguments='', stderr = None) - dom = parse( test.workpath( 'foo-1.2.wxs' ) ) - dirs = dom.getElementsByTagName( 'Directory' ) +dom = parse( test.workpath( 'foo-1.2.wxs' ) ) +dirs = dom.getElementsByTagName( 'Directory' ) - test.fail_test( not dirs[0].attributes['Name'].value == 'SourceDir' ) - test.fail_test( not dirs[1].attributes['Name'].value == 'PFiles' ) - test.fail_test( not dirs[2].attributes['Name'].value == 'NANOSOF1' ) - test.fail_test( not dirs[3].attributes['Name'].value == 'FOO-1.2' ) +test.fail_test( not dirs[0].attributes['Name'].value == 'SourceDir' ) +test.fail_test( not dirs[1].attributes['Name'].value == 'PFiles' ) +test.fail_test( not dirs[2].attributes['Name'].value == 'NANOSOF1' ) +test.fail_test( not dirs[3].attributes['Name'].value == 'FOO-1.2' ) - # - # Try to put 7 files into 5 distinct directories of varying depth and overlapping count - # - test.write( 'file1.exe', "file1" ) - test.write( 'file2.exe', "file2" ) - test.write( 'file3.dll', "file3" ) - test.write( 'file4.dll', "file4" ) - test.write( 'file5.class', "file5" ) - test.write( 'file6.class', "file6" ) - test.write( 'file7.class', "file7" ) - - test.write('SConstruct', """ +# +# Try to put 7 files into 5 distinct directories of varying depth and overlapping count +# +test.write( 'file1.exe', "file1" ) +test.write( 'file2.exe', "file2" ) +test.write( 'file3.dll', "file3" ) +test.write( 'file4.dll', "file4" ) +test.write( 'file5.class', "file5" ) +test.write( 'file6.class', "file6" ) +test.write( 'file7.class', "file7" ) + +test.write('SConstruct', """ env = Environment(tools=['default', 'packaging']) f1 = env.Install( '/bin/' , 'file1.exe' ) f2 = env.Install( '/bin/' , 'file2.exe' ) @@ -103,35 +105,35 @@ env.Package( NAME = 'foo', ) """) - test.run(arguments='', stderr = None) +test.run(arguments='', stderr = None) - dom = parse( test.workpath( 'foo-1.2.wxs' ) ) - files = dom.getElementsByTagName( 'File' ) +dom = parse( test.workpath( 'foo-1.2.wxs' ) ) +files = dom.getElementsByTagName( 'File' ) - test.fail_test( not files[0].parentNode.parentNode.attributes['LongName'].value == 'bin' ) - test.fail_test( not files[1].parentNode.parentNode.attributes['LongName'].value == 'bin' ) - test.fail_test( not files[2].parentNode.parentNode.attributes['LongName'].value == 'lib' ) - test.fail_test( not files[3].parentNode.parentNode.attributes['LongName'].value == 'lib' ) - - test.fail_test( not files[4].parentNode.parentNode.attributes['LongName'].value == 'teco' ) - test.fail_test( not files[4].parentNode.parentNode.parentNode.attributes['LongName'].value == 'edu' ) - test.fail_test( not files[4].parentNode.parentNode.parentNode.parentNode.attributes['LongName'].value == 'java' ) +test.fail_test( not files[0].parentNode.parentNode.attributes['LongName'].value == 'bin' ) +test.fail_test( not files[1].parentNode.parentNode.attributes['LongName'].value == 'bin' ) +test.fail_test( not files[2].parentNode.parentNode.attributes['LongName'].value == 'lib' ) +test.fail_test( not files[3].parentNode.parentNode.attributes['LongName'].value == 'lib' ) + +test.fail_test( not files[4].parentNode.parentNode.attributes['LongName'].value == 'teco' ) +test.fail_test( not files[4].parentNode.parentNode.parentNode.attributes['LongName'].value == 'edu' ) +test.fail_test( not files[4].parentNode.parentNode.parentNode.parentNode.attributes['LongName'].value == 'java' ) - test.fail_test( not files[5].parentNode.parentNode.attributes['LongName'].value == 'teco' ) - test.fail_test( not files[5].parentNode.parentNode.parentNode.attributes['LongName'].value == 'java' ) +test.fail_test( not files[5].parentNode.parentNode.attributes['LongName'].value == 'teco' ) +test.fail_test( not files[5].parentNode.parentNode.parentNode.attributes['LongName'].value == 'java' ) - test.fail_test( not files[6].parentNode.parentNode.attributes['LongName'].value == 'tec' ) - test.fail_test( not files[6].parentNode.parentNode.parentNode.attributes['LongName'].value == 'java' ) +test.fail_test( not files[6].parentNode.parentNode.attributes['LongName'].value == 'tec' ) +test.fail_test( not files[6].parentNode.parentNode.parentNode.attributes['LongName'].value == 'java' ) - # - # Test distinct directories put into distinct features - # - test.write( 'file1.exe', "file1" ) - test.write( 'file2.exe', "file2" ) - test.write( 'file3.dll', "file3" ) - test.write( 'file3-.dll', "file3" ) +# +# Test distinct directories put into distinct features +# +test.write( 'file1.exe', "file1" ) +test.write( 'file2.exe', "file2" ) +test.write( 'file3.dll', "file3" ) +test.write( 'file3-.dll', "file3" ) - test.write('SConstruct', """ +test.write('SConstruct', """ env = Environment(tools=['default', 'packaging']) f1 = env.Install( '/bin/' , 'file1.exe' ) f2 = env.Install( '/bin/' , 'file2.exe' ) @@ -152,21 +154,19 @@ env.Package( NAME = 'foo', ) """) - test.run(arguments='', stderr = None) - - dom = parse( test.workpath( 'foo-1.2.wxs' ) ) - features = dom.getElementsByTagName( 'Feature' ) +test.run(arguments='', stderr = None) - test.fail_test( not features[1].attributes['Title'].value == 'Core Part' ) - componentrefs = features[1].getElementsByTagName( 'ComponentRef' ) - test.fail_test( not componentrefs[0].attributes['Id'].value == 'file1.exe' ) - test.fail_test( not componentrefs[1].attributes['Id'].value == 'file2.exe' ) - test.fail_test( not componentrefs[2].attributes['Id'].value == 'file3.dll1' ) +dom = parse( test.workpath( 'foo-1.2.wxs' ) ) +features = dom.getElementsByTagName( 'Feature' ) - test.fail_test( not features[2].attributes['Title'].value == 'Java Part' ) - componentrefs = features[2].getElementsByTagName( 'ComponentRef' ) - test.fail_test( not componentrefs[0].attributes['Id'].value == 'file3.dll' ) +test.fail_test( not features[1].attributes['Title'].value == 'Core Part' ) +componentrefs = features[1].getElementsByTagName( 'ComponentRef' ) +test.fail_test( not componentrefs[0].attributes['Id'].value == 'file1.exe' ) +test.fail_test( not componentrefs[1].attributes['Id'].value == 'file2.exe' ) +test.fail_test( not componentrefs[2].attributes['Id'].value == 'file3.dll1' ) -else: - test.no_result() +test.fail_test( not features[2].attributes['Title'].value == 'Java Part' ) +componentrefs = features[2].getElementsByTagName( 'ComponentRef' ) +test.fail_test( not componentrefs[0].attributes['Id'].value == 'file3.dll' ) +test.pass_test() diff --git a/test/packaging/msi/package.py b/test/packaging/msi/package.py index 24bd26d..e6ce668 100644 --- a/test/packaging/msi/package.py +++ b/test/packaging/msi/package.py @@ -42,14 +42,16 @@ except ImportError: wix = test.Environment().WhereIs('candle') -if wix: - # - # build with minimal tag set and test for the given package meta-data - # - test.write( 'file1.exe', "file1" ) - test.write( 'file2.exe', "file2" ) - - test.write('SConstruct', """ +if not wix: + test.skip_test("No 'candle' found; skipping test\n") + +# +# build with minimal tag set and test for the given package meta-data +# +test.write( 'file1.exe', "file1" ) +test.write( 'file2.exe', "file2" ) + +test.write('SConstruct', """ import os env = Environment(tools=['default', 'packaging']) @@ -69,32 +71,32 @@ env.Package( NAME = 'foo', env.Alias( 'install', [ f1, f2 ] ) """) - test.run(arguments='', stderr = None) +test.run(arguments='', stderr = None) - test.must_exist( 'foo-1.2.wxs' ) - test.must_exist( 'foo-1.2.msi' ) +test.must_exist( 'foo-1.2.wxs' ) +test.must_exist( 'foo-1.2.msi' ) - dom = parse( test.workpath( 'foo-1.2.wxs' ) ) - Product = dom.getElementsByTagName( 'Product' )[0] - Package = dom.getElementsByTagName( 'Package' )[0] +dom = parse( test.workpath( 'foo-1.2.wxs' ) ) +Product = dom.getElementsByTagName( 'Product' )[0] +Package = dom.getElementsByTagName( 'Package' )[0] - test.fail_test( not Product.attributes['Manufacturer'].value == 'Nanosoft_2000' ) - test.fail_test( not Product.attributes['Version'].value == '1.2' ) - test.fail_test( not Product.attributes['Name'].value == 'foo' ) +test.fail_test( not Product.attributes['Manufacturer'].value == 'Nanosoft_2000' ) +test.fail_test( not Product.attributes['Version'].value == '1.2' ) +test.fail_test( not Product.attributes['Name'].value == 'foo' ) - test.fail_test( not Package.attributes['Description'].value == 'balalalalal' ) - test.fail_test( not Package.attributes['Comments'].value == 'this should be reallly really long' ) +test.fail_test( not Package.attributes['Description'].value == 'balalalalal' ) +test.fail_test( not Package.attributes['Comments'].value == 'this should be reallly really long' ) - # - # build with file tags resulting in multiple components in the msi installer - # - test.write( 'file1.exe', "file1" ) - test.write( 'file2.exe', "file2" ) - test.write( 'file3.html', "file3" ) - test.write( 'file4.dll', "file4" ) - test.write( 'file5.dll', "file5" ) +# +# build with file tags resulting in multiple components in the msi installer +# +test.write( 'file1.exe', "file1" ) +test.write( 'file2.exe', "file2" ) +test.write( 'file3.html', "file3" ) +test.write( 'file4.dll', "file4" ) +test.write( 'file5.dll', "file5" ) - test.write('SConstruct', """ +test.write('SConstruct', """ import os env = Environment(tools=['default', 'packaging']) f1 = env.Install( '/usr/' , 'file1.exe' ) @@ -121,18 +123,19 @@ env.Package( NAME = 'foo', env.Alias( 'install', [ f1, f2, f3, f4, f5 ] ) """) - test.run(arguments='', stderr = None) +test.run(arguments='', stderr = None) + +test.must_exist( 'foo-1.2.wxs' ) +test.must_exist( 'foo-1.2.msi' ) + +dom = parse( test.workpath( 'foo-1.2.wxs' ) ) +elements = dom.getElementsByTagName( 'Feature' ) +test.fail_test( not elements[1].attributes['Title'].value == 'Main Part' ) +test.fail_test( not elements[2].attributes['Title'].value == 'Documentation' ) +test.fail_test( not elements[3].attributes['Title'].value == 'Another Feature' ) +test.fail_test( not elements[3].attributes['Description'].value == 'with a long description' ) +test.fail_test( not elements[4].attributes['Title'].value == 'Java Part' ) - test.must_exist( 'foo-1.2.wxs' ) - test.must_exist( 'foo-1.2.msi' ) - dom = parse( test.workpath( 'foo-1.2.wxs' ) ) - elements = dom.getElementsByTagName( 'Feature' ) - test.fail_test( not elements[1].attributes['Title'].value == 'Main Part' ) - test.fail_test( not elements[2].attributes['Title'].value == 'Documentation' ) - test.fail_test( not elements[3].attributes['Title'].value == 'Another Feature' ) - test.fail_test( not elements[3].attributes['Description'].value == 'with a long description' ) - test.fail_test( not elements[4].attributes['Title'].value == 'Java Part' ) -else: - test.no_result() +test.pass_test() diff --git a/test/packaging/option--package-type.py b/test/packaging/option--package-type.py index 68a075c..00a569e 100644 --- a/test/packaging/option--package-type.py +++ b/test/packaging/option--package-type.py @@ -35,6 +35,8 @@ _python_ = TestSCons._python_ test = TestSCons.TestSCons() +rpm_build_root = test.workpath('rpm_build_root') + scons = test.program rpm = test.Environment().WhereIs('rpm') @@ -50,6 +52,7 @@ test.write('SConstruct', """ # -*- coding: iso-8859-15 -*- env=Environment(tools=['default', 'packaging']) env.Prepend(RPM = 'TAR_OPTIONS=--wildcards ') +env.Append(RPMFLAGS = r' --buildroot %(rpm_build_root)s') prog=env.Install( '/bin', 'main' ) env.Package( NAME = 'foo', VERSION = '1.2.3', diff --git a/test/packaging/rpm/cleanup.py b/test/packaging/rpm/cleanup.py index 26bf79b..5472fbb 100644 --- a/test/packaging/rpm/cleanup.py +++ b/test/packaging/rpm/cleanup.py @@ -45,6 +45,8 @@ rpm = test.Environment().WhereIs('rpm') if not rpm: test.skip_test('rpm not found, skipping test\n') +rpm_build_root = test.workpath('rpm_build_root') + test.subdir('src') test.write( [ 'src', 'main.c' ], r""" @@ -57,7 +59,10 @@ int main( int argc, char* argv[] ) test.write('SConstruct', """ env=Environment(tools=['default', 'packaging']) +env['ENV']['RPM_BUILD_ROOT'] = r'%(rpm_build_root)s/foo-1.2.3' + env.Prepend(RPM = 'TAR_OPTIONS=--wildcards ') +env.Append(RPMFLAGS = r' --buildroot %(rpm_build_root)s') prog = env.Install( '/bin/' , Program( 'src/main.c') ) diff --git a/test/packaging/rpm/internationalization.py b/test/packaging/rpm/internationalization.py index 66c2291..af0bc75 100644 --- a/test/packaging/rpm/internationalization.py +++ b/test/packaging/rpm/internationalization.py @@ -47,6 +47,8 @@ rpm = test.Environment().WhereIs('rpm') if not rpm: test.skip_test('rpm not found, skipping test\n') +rpm_build_root = test.workpath('rpm_build_root') + # # test INTERNATIONAL PACKAGE META-DATA # @@ -64,6 +66,7 @@ import os env = Environment(tools=['default', 'packaging']) env.Prepend(RPM = 'TAR_OPTIONS=--wildcards ') +env.Append(RPMFLAGS = r' --buildroot %(rpm_build_root)s') prog = env.Install( '/bin', Program( 'main.c' ) ) diff --git a/test/packaging/rpm/package.py b/test/packaging/rpm/package.py index a5f9f0f..2a37265 100644 --- a/test/packaging/rpm/package.py +++ b/test/packaging/rpm/package.py @@ -43,6 +43,8 @@ rpm = test.Environment().WhereIs('rpm') if not rpm: test.skip_test('rpm not found, skipping test\n') +rpm_build_root = test.workpath('rpm_build_root') + test.subdir('src') test.write( [ 'src', 'main.c' ], r""" @@ -58,6 +60,7 @@ import os env=Environment(tools=['default', 'packaging']) env.Prepend(RPM = 'TAR_OPTIONS=--wildcards ') +env.Append(RPMFLAGS = r' --buildroot %(rpm_build_root)s') prog = env.Install( '/bin/' , Program( 'src/main.c') ) diff --git a/test/packaging/rpm/tagging.py b/test/packaging/rpm/tagging.py index 198799a..d0fce83 100644 --- a/test/packaging/rpm/tagging.py +++ b/test/packaging/rpm/tagging.py @@ -45,6 +45,8 @@ rpm = test.Environment().WhereIs('rpm') if not rpm: test.skip_test('rpm not found, skipping test\n') +rpm_build_root = test.workpath('rpm_build_root') + # # Test adding an attr tag to the built program. # @@ -61,7 +63,10 @@ test.write('SConstruct', """ import os env = Environment(tools=['default', 'packaging']) + env.Prepend(RPM = 'TAR_OPTIONS=--wildcards ') +env.Append(RPMFLAGS = r' --buildroot %(rpm_build_root)s') + install_dir= os.path.join( ARGUMENTS.get('prefix', '/'), 'bin/' ) prog_install = env.Install( install_dir , Program( 'src/main.c' ) ) env.Tag( prog_install, UNIX_ATTR = '(0755, root, users)' ) diff --git a/test/scons-time/run/archive/zip.py b/test/scons-time/run/archive/zip.py index 67cfc3a..b5b122b 100644 --- a/test/scons-time/run/archive/zip.py +++ b/test/scons-time/run/archive/zip.py @@ -29,6 +29,8 @@ Verify basic generation of timing information from an input fake-project .zip file. """ +import sys + import TestSCons_time test = TestSCons_time.TestSCons_time() @@ -37,6 +39,28 @@ test.write_fake_scons_py() test.write_sample_project('foo.zip') +try: + import zipfile + # There's a bug in the Python 2.1 zipfile library that makes it blow + # up on 64-bit architectures, when trying to read normal 32-bit zip + # files. Check for it by trying to read the archive we just created, + # and skipping the test gracefully if there's a problem. + zf = zipfile.ZipFile('foo.zip', 'r') + for name in zf.namelist(): + zf.read(name) +except ImportError: + # This "shouldn't happen" because the early Python versions that + # have no zipfile module don't support the scons-time script, + # so the initialization above should short-circuit this test. + # But just in case... + fmt = "Python %s has no zipfile module. Skipping test.\n" + test.skip_test(fmt % sys.version[:3]) +except zipfile.BadZipfile, e: + if str(e)[:11] == 'Bad CRC-32 ': + fmt = "Python %s zipfile module doesn't work on 64-bit architectures. Skipping test.\n" + test.skip_test(fmt % sys.version[:3]) + raise + test.run(arguments = 'run foo.zip') test.must_exist('foo-000-0.log', diff --git a/test/scons-time/run/option/quiet.py b/test/scons-time/run/option/quiet.py index 5d5d7cf..f5a3d8c 100644 --- a/test/scons-time/run/option/quiet.py +++ b/test/scons-time/run/option/quiet.py @@ -39,7 +39,7 @@ test.diff_function = TestSCons_time.diff_re def tempdir_re(*args): - import os + import os,sys import os.path import string import tempfile @@ -49,6 +49,9 @@ def tempdir_re(*args): x = apply(os.path.join, args) x = re.escape(x) x = string.replace(x, 'time\\-', 'time\\-[^%s]*' % sep) + if sys.platform=='darwin': + # OSX has /tmp in /private/tmp. + x = '(/private)?' + x return x scons_py = re.escape(test.workpath('src', 'script', 'scons.py')) diff --git a/test/scons-time/run/option/verbose.py b/test/scons-time/run/option/verbose.py index cdf5b5a..fb95dab 100644 --- a/test/scons-time/run/option/verbose.py +++ b/test/scons-time/run/option/verbose.py @@ -40,7 +40,7 @@ test.diff_function = TestSCons_time.diff_re def tempdir_re(*args): - import os + import os,sys import os.path import string import tempfile @@ -50,6 +50,9 @@ def tempdir_re(*args): x = apply(os.path.join, args) x = re.escape(x) x = string.replace(x, 'time\\-', 'time\\-[^%s]*' % sep) + if sys.platform=='darwin': + # OSX has /tmp in /private/tmp. + x = '(/private)?' + x return x scons_py = re.escape(test.workpath('src', 'script', 'scons.py')) |