diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CPPSUFFIXES.py | 112 | ||||
-rw-r--r-- | test/DSUFFIXES.py | 122 | ||||
-rw-r--r-- | test/FORTRANSUFFIXES.py | 124 | ||||
-rw-r--r-- | test/HeaderInstall.py | 65 | ||||
-rw-r--r-- | test/Scanner.py | 5 | ||||
-rw-r--r-- | test/option--warn.py | 7 | ||||
-rw-r--r-- | test/scan-once.py | 65 |
7 files changed, 406 insertions, 94 deletions
diff --git a/test/CPPSUFFIXES.py b/test/CPPSUFFIXES.py index e64dff2..a340a4a 100644 --- a/test/CPPSUFFIXES.py +++ b/test/CPPSUFFIXES.py @@ -25,43 +25,131 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ -Test that we can add filesuffixes to $CPPSUFFIXES. +Test the ability to scan additional filesuffixes added to $CPPSUFFIXES. """ import TestSCons +python = TestSCons.python + test = TestSCons.TestSCons() +test.write('mycc.py', r""" +import string +import sys +def do_file(outf, inf): + for line in open(inf, 'rb').readlines(): + if line[:10] == '#include <': + do_file(outf, line[10:-2]) + else: + outf.write(line) +outf = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + do_file(outf, f) +sys.exit(0) +""") + test.write('SConstruct', """ -env = Environment(CPPPATH = ['.']) +env = Environment(CPPPATH = ['.'], + CC = r'%s mycc.py', + CCFLAGS = [], + CCCOM = '$CC $TARGET $SOURCES', + OBJSUFFIX = '.o') env.Append(CPPSUFFIXES = ['.x']) -env.InstallAs('foo_c', 'foo.c') -env.InstallAs('foo_x', 'foo.x') +env.Object(target = 'test1', source = 'test1.c') +env.InstallAs('test1_c', 'test1.c') +env.InstallAs('test1_h', 'test1.h') +env.InstallAs('test1_x', 'test1.x') +""" % (python,)) + +test.write('test1.c', """\ +test1.c 1 +#include <test1.h> +#include <test1.x> """) -test.write('foo.c', """\ +test.write('test1.h', """\ +test1.h 1 #include <foo.h> """) -test.write('foo.x', """\ +test.write('test1.x', """\ +test1.x 1 #include <foo.h> """) test.write('foo.h', "foo.h 1\n") test.run(arguments='.', stdout=test.wrap_stdout("""\ -Install file: "foo.c" as "foo_c" -Install file: "foo.x" as "foo_x" -""")) +%s mycc.py test1.o test1.c +Install file: "test1.c" as "test1_c" +Install file: "test1.h" as "test1_h" +Install file: "test1.x" as "test1_x" +""" % (python,))) + +test.must_match('test1.o', """\ +test1.c 1 +test1.h 1 +foo.h 1 +test1.x 1 +foo.h 1 +""") test.up_to_date(arguments='.') test.write('foo.h', "foo.h 2\n") test.run(arguments='.', stdout=test.wrap_stdout("""\ -Install file: "foo.c" as "foo_c" -Install file: "foo.x" as "foo_x" -""")) +%s mycc.py test1.o test1.c +""" % (python,))) + +test.must_match('test1.o', """\ +test1.c 1 +test1.h 1 +foo.h 2 +test1.x 1 +foo.h 2 +""") + +test.up_to_date(arguments='.') + +test.write('test1.x', """\ +test1.x 2 +#include <foo.h> +""") + +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s mycc.py test1.o test1.c +Install file: "test1.x" as "test1_x" +""" % (python,))) + +test.must_match('test1.o', """\ +test1.c 1 +test1.h 1 +foo.h 2 +test1.x 2 +foo.h 2 +""") + +test.up_to_date(arguments='.') + +test.write('test1.h', """\ +test1.h 2 +#include <foo.h> +""") + +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s mycc.py test1.o test1.c +Install file: "test1.h" as "test1_h" +""" % (python,))) + +test.must_match('test1.o', """\ +test1.c 1 +test1.h 2 +foo.h 2 +test1.x 2 +foo.h 2 +""") test.up_to_date(arguments='.') diff --git a/test/DSUFFIXES.py b/test/DSUFFIXES.py index 6f10439..188da9b 100644 --- a/test/DSUFFIXES.py +++ b/test/DSUFFIXES.py @@ -25,43 +25,131 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ -Test that we can add filesuffixes to $DSUFFIXES. +Test the ability to scan additional filesuffixes added to $DSUFFIXES. """ import TestSCons +python = TestSCons.python + test = TestSCons.TestSCons() +test.write('mydc.py', r""" +import string +import sys +def do_file(outf, inf): + for line in open(inf, 'rb').readlines(): + if line[:7] == 'import ': + do_file(outf, line[7:-2]+'.d') + else: + outf.write(line) +outf = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + do_file(outf, f) +sys.exit(0) +""") + test.write('SConstruct', """ -env = Environment(DPATH=['.']) -env.Append(DSUFFIXES = ['.x']) -env.InstallAs('foo_d', 'foo.d') -env.InstallAs('foo_x', 'foo.x') +env = Environment(DPATH = ['.'], + DC = r'%s mydc.py', + DFLAGS = [], + DCOM = '$DC $TARGET $SOURCES', + OBJSUFFIX = '.o') +env.Append(CPPSUFFIXES = ['.x']) +env.Object(target = 'test1', source = 'test1.d') +env.InstallAs('test1_d', 'test1.d') +env.InstallAs('test2_d', 'test2.d') +env.InstallAs('test3_d', 'test3.d') +""" % (python,)) + +test.write('test1.d', """\ +test1.d 1 +import test2; +import test3; +""") + +test.write('test2.d', """\ +test2.d 1 +import foo; """) -test.write('foo.d', """\ -import inc; +test.write('test3.d', """\ +test3.d 1 +import foo; """) -test.write('foo.x', """\ -import inc; +test.write('foo.d', "foo.d 1\n") + +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s mydc.py test1.o test1.d +Install file: "test1.d" as "test1_d" +Install file: "test2.d" as "test2_d" +Install file: "test3.d" as "test3_d" +""" % (python,))) + +test.must_match('test1.o', """\ +test1.d 1 +test2.d 1 +foo.d 1 +test3.d 1 +foo.d 1 +""") + +test.up_to_date(arguments='.') + +test.write('foo.d', "foo.d 2\n") + +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s mydc.py test1.o test1.d +""" % (python,))) + +test.must_match('test1.o', """\ +test1.d 1 +test2.d 1 +foo.d 2 +test3.d 1 +foo.d 2 """) -test.write('inc.d', "inc.d 1\n") +test.up_to_date(arguments='.') + +test.write('test3.d', """\ +test3.d 2 +import foo; +""") test.run(arguments='.', stdout=test.wrap_stdout("""\ -Install file: "foo.d" as "foo_d" -Install file: "foo.x" as "foo_x" -""")) +%s mydc.py test1.o test1.d +Install file: "test3.d" as "test3_d" +""" % (python,))) + +test.must_match('test1.o', """\ +test1.d 1 +test2.d 1 +foo.d 2 +test3.d 2 +foo.d 2 +""") test.up_to_date(arguments='.') -test.write('inc.d', "inc 2\n") +test.write('test2.d', """\ +test2.d 2 +import foo; +""") test.run(arguments='.', stdout=test.wrap_stdout("""\ -Install file: "foo.d" as "foo_d" -Install file: "foo.x" as "foo_x" -""")) +%s mydc.py test1.o test1.d +Install file: "test2.d" as "test2_d" +""" % (python,))) + +test.must_match('test1.o', """\ +test1.d 1 +test2.d 2 +foo.d 2 +test3.d 2 +foo.d 2 +""") test.up_to_date(arguments='.') diff --git a/test/FORTRANSUFFIXES.py b/test/FORTRANSUFFIXES.py index 1ab7306..c5047f7 100644 --- a/test/FORTRANSUFFIXES.py +++ b/test/FORTRANSUFFIXES.py @@ -25,43 +25,135 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ -Test that we can add filesuffixes to $FORTRANSUFFIXES. +Test the ability to scan additional filesuffixes added to $FORTRANSUFFIXES. """ import TestSCons +python = TestSCons.python + test = TestSCons.TestSCons() +test.write('myfc.py', r""" +import string +import sys +def do_file(outf, inf): + for line in open(inf, 'rb').readlines(): + if line[:15] == " INCLUDE '": + do_file(outf, line[15:-2]) + else: + outf.write(line) +outf = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + do_file(outf, f) +sys.exit(0) +""") + test.write('SConstruct', """ -env = Environment() +env = Environment(F77PATH = ['.'], + F77 = r'%s myfc.py', + F77FLAGS = [], + F77COM = '$F77 $TARGET $SOURCES', + OBJSUFFIX = '.o') env.Append(FORTRANSUFFIXES = ['.x']) -env.InstallAs('foo_f', 'foo.f') -env.InstallAs('foo_x', 'foo.x') +env.Object(target = 'test1', source = 'test1.f') +env.InstallAs('test1_f', 'test1.f') +env.InstallAs('test1_h', 'test1.h') +env.InstallAs('test1_x', 'test1.x') +""" % (python,)) + +test.write('test1.f', """\ + test1.f 1 + INCLUDE 'test1.h' + INCLUDE 'test1.x' +""") + +test.write('test1.h', """\ + test1.h 1 + INCLUDE 'foo.h' +""") + +test.write('test1.x', """\ + test1.x 1 + INCLUDE 'foo.h' +""") + +test.write('foo.h', """\ + foo.h 1 +""") + +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s myfc.py test1.o test1.f +Install file: "test1.f" as "test1_f" +Install file: "test1.h" as "test1_h" +Install file: "test1.x" as "test1_x" +""" % (python,))) + +test.must_match('test1.o', """\ + test1.f 1 + test1.h 1 + foo.h 1 + test1.x 1 + foo.h 1 """) -test.write('foo.f', """\ -INCLUDE 'foo.h' +test.up_to_date(arguments='.') + +test.write('foo.h', """\ + foo.h 2 """) -test.write('foo.x', """\ -INCLUDE 'foo.h' +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s myfc.py test1.o test1.f +""" % (python,))) + +test.must_match('test1.o', """\ + test1.f 1 + test1.h 1 + foo.h 2 + test1.x 1 + foo.h 2 """) -test.write('foo.h', "foo.h 1\n") +test.up_to_date(arguments='.') + +test.write('test1.x', """\ + test1.x 2 + INCLUDE 'foo.h' +""") test.run(arguments='.', stdout=test.wrap_stdout("""\ -Install file: "foo.f" as "foo_f" -Install file: "foo.x" as "foo_x" -""")) +%s myfc.py test1.o test1.f +Install file: "test1.x" as "test1_x" +""" % (python,))) + +test.must_match('test1.o', """\ + test1.f 1 + test1.h 1 + foo.h 2 + test1.x 2 + foo.h 2 +""") test.up_to_date(arguments='.') -test.write('foo.h', "foo.h 2\n") +test.write('test1.h', """\ + test1.h 2 + INCLUDE 'foo.h' +""") test.run(arguments='.', stdout=test.wrap_stdout("""\ -Install file: "foo.f" as "foo_f" -Install file: "foo.x" as "foo_x" -""")) +%s myfc.py test1.o test1.f +Install file: "test1.h" as "test1_h" +""" % (python,))) + +test.must_match('test1.o', """\ + test1.f 1 + test1.h 2 + foo.h 2 + test1.x 2 + foo.h 2 +""") test.up_to_date(arguments='.') diff --git a/test/HeaderInstall.py b/test/HeaderInstall.py index 523044c..cccf4d6 100644 --- a/test/HeaderInstall.py +++ b/test/HeaderInstall.py @@ -27,11 +27,15 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" Test that dependencies in installed header files get re-scanned correctly. """ +import os.path + import TestSCons test = TestSCons.TestSCons() -test.write('SConstruct', """ +test.subdir('work1', ['work1', 'dist']) + +test.write(['work1', 'SConstruct'], """ env = Environment(CPPPATH=['#include']) Export('env') SConscript('dist/SConscript') @@ -39,31 +43,72 @@ libfoo = env.StaticLibrary('foo', ['foo.c']) Default(libfoo) """) -test.write('foo.c', """ +test.write(['work1', 'foo.c'], """ #include <h1.h> """) -test.subdir('dist') - -test.write(['dist', 'SConscript'], """\ +test.write(['work1', 'dist', 'SConscript'], """\ Import('env') env.Install('#include', ['h1.h', 'h2.h', 'h3.h']) """) -test.write(['dist', 'h1.h'], """\ +test.write(['work1', 'dist', 'h1.h'], """\ #include "h2.h" """) -test.write(['dist', 'h2.h'], """\ +test.write(['work1', 'dist', 'h2.h'], """\ #include "h3.h" """) -test.write(['dist', 'h3.h'], """\ +test.write(['work1', 'dist', 'h3.h'], """\ int foo = 3; """) -test.run(arguments = ".") +test.run(chdir = 'work1', arguments = ".") + +test.up_to_date(chdir = 'work1', arguments = ".") + +# +test.subdir('ref', 'work2', ['work2', 'src']) + +test.write(['work2', 'SConstruct'], """ +env = Environment(CPPPATH=['build', r'%s']) +env.Install('build', 'src/in1.h') +env.Install('build', 'src/in2.h') +env.Install('build', 'src/in3.h') +""" % test.workpath('ref')) + +test.write(['ref', 'in1.h'], '#define FILE "ref/in1.h"\n#include <in2.h>\n') +test.write(['ref', 'in2.h'], '#define FILE "ref/in2.h"\n#include <in3.h>\n') +test.write(['ref', 'in3.h'], '#define FILE "ref/in3.h"\n#define FOO 0\n') + +src_in1_h = '#define FILE "src/in1.h"\n#include <in2.h>\n' +src_in2_h = '#define FILE "src/in2.h"\n#include <in3.h>\n' +src_in3_h = '#define FILE "src/in3.h"\n#define FOO 0\n' +test.write(['work2', 'src', 'in1.h'], src_in1_h) +test.write(['work2', 'src', 'in2.h'], src_in2_h) +test.write(['work2', 'src', 'in3.h'], src_in3_h) + +test.run(chdir = 'work2', arguments = 'build') + +test.must_match(['work2', 'build', 'in1.h'], src_in1_h) +test.must_match(['work2', 'build', 'in2.h'], src_in2_h) +test.must_match(['work2', 'build', 'in3.h'], src_in3_h) + +test.up_to_date(chdir = 'work2', arguments = 'build') + +src_in3_h = '#define FILE "src/in3.h"\n#define FOO 1\n' +test.write(['work2', 'src', 'in3.h'], src_in3_h) + +test.run(chdir = 'work2', arguments = 'build', stdout=test.wrap_stdout("""\ +Install file: "%s" as "%s" +""" % (os.path.join('src', 'in3.h'), + os.path.join('build', 'in3.h')))) + +test.must_match(['work2', 'build', 'in1.h'], src_in1_h) +test.must_match(['work2', 'build', 'in2.h'], src_in2_h) +test.must_match(['work2', 'build', 'in3.h'], src_in3_h) -test.up_to_date(arguments = ".") +test.up_to_date(chdir = 'work2', arguments = 'build') test.pass_test() diff --git a/test/Scanner.py b/test/Scanner.py index 61d9e39..0bb3d8b 100644 --- a/test/Scanner.py +++ b/test/Scanner.py @@ -91,9 +91,8 @@ env2 = env.Copy() env2.Append(SCANNERS = [k2scan]) env2.Command('junk', 'junk.k2', r'%s build.py $SOURCES $TARGET') -bar_in = File('bar.in') -env.Command('bar', bar_in, r'%s build.py $SOURCES $TARGET') -bar_in.source_scanner = kscan +bar = env.Command('bar', 'bar.in', r'%s build.py $SOURCES $TARGET') +bar.source_scanner = kscan """ % (python, python, python)) test.write('foo.k', diff --git a/test/option--warn.py b/test/option--warn.py index 41a37e1..8c84b6d 100644 --- a/test/option--warn.py +++ b/test/option--warn.py @@ -54,12 +54,15 @@ test = TestSCons.TestSCons(match = TestCmd.match_re_dotall) -test.write("SConstruct",""" +test.write("SConstruct", """\ +import SCons.Defaults + def build(target, source, env): pass env=Environment() -env['BUILDERS']['test'] = Builder(action=build) +env['BUILDERS']['test'] = Builder(action=build, + source_scanner=SCons.Defaults.ObjSourceScan) env.test(target='foo', source='foo.c') """) diff --git a/test/scan-once.py b/test/scan-once.py index 52b4505..606590b 100644 --- a/test/scan-once.py +++ b/test/scan-once.py @@ -110,38 +110,6 @@ builders["StaticLibMerge"] = BStaticLibMerge env = Environment(BUILDERS = builders) e = env.Dictionary() # Slightly easier to type -Scanned = {} - -def write_out(file, dict): - keys = dict.keys() - keys.sort() - f = open(file, 'wb') - for k in keys: - file = os.path.split(k)[1] - f.write(file + ": " + str(dict[k]) + "\\n") - f.close() - -import SCons.Scanner.C -c_scanner = SCons.Scanner.C.CScan() -def MyCScan(node, env, target): - deps = c_scanner(node, env, target) - - global Scanned - n = str(node) - try: - Scanned[n] = Scanned[n] + 1 - except KeyError: - Scanned[n] = 1 - write_out('MyCScan.out', Scanned) - - return deps -S_MyCScan = SCons.Scanner.Current(skeys = [".c", ".C", ".cxx", ".cpp", ".c++", ".cc", - ".h", ".H", ".hxx", ".hpp", ".h++", ".hh"], - function = MyCScan, - recursive = 1) -# QQQ Yes, this is manner of fixing the SCANNERS list is fragile. -env["SCANNERS"] = [S_MyCScan] + env["SCANNERS"][1:] - global_env = env e["GlobalEnv"] = global_env @@ -167,7 +135,6 @@ test.write(['SLF', 'Mylib.py'], """\ import os import string import re -import SCons.Environment def Subdirs(env, dirlist): for file in _subconf_list(dirlist): @@ -376,10 +343,40 @@ for h in ['libg_gx.h', 'libg_gy.h', 'libg_gz.h']: """) test.write(['SLF', 'src', 'lib_geng', 'SConstruct'], """\ +import os + +Scanned = {} + +def write_out(file, dict): + keys = dict.keys() + keys.sort() + f = open(file, 'wb') + for k in keys: + file = os.path.split(k)[1] + f.write(file + ": " + str(dict[k]) + "\\n") + f.close() + +orig_function = CScan.function + +def MyCScan(node, env, target, orig_function=orig_function): + deps = orig_function(node, env, target) + + global Scanned + n = str(node) + try: + Scanned[n] = Scanned[n] + 1 + except KeyError: + Scanned[n] = 1 + write_out(r'%s', Scanned) + + return deps + +CScan.function = MyCScan + env = Environment(CPPPATH = ".") l = env.StaticLibrary("g", Split("libg_1.c libg_2.c libg_3.c")) Default(l) -""") +""" % test.workpath('MyCScan.out')) # These were the original shell script and Makefile from SLF's original # bug report. We're not using them--in order to make this script as |