From 2ed12fcec8baf5eefc5492bb763592a96541a32c Mon Sep 17 00:00:00 2001 From: stevenknight Date: Fri, 4 Oct 2002 22:04:27 +0000 Subject: [PATCH] win32 test portability fixes (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@474 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- etc/TestSCons.py | 14 ++++++++++++++ src/engine/SCons/UtilTests.py | 11 +++++------ test/AS.py | 3 +-- test/RANLIB.py | 2 +- test/RANLIBFLAGS.py | 2 +- test/Scanner.py | 4 ++-- test/TAR.py | 7 +++---- test/TARFLAGS.py | 9 ++++----- test/option--D.py | 2 +- test/option-q.py | 2 +- test/option-u.py | 2 +- 11 files changed, 34 insertions(+), 24 deletions(-) diff --git a/etc/TestSCons.py b/etc/TestSCons.py index 5d4d4a09..997104bc 100644 --- a/etc/TestSCons.py +++ b/etc/TestSCons.py @@ -151,6 +151,20 @@ class TestSCons(TestCmd.TestCmd): print self.stderr() raise TestFailed + def detect(self, var, prog): + """ + Detect a program named 'prog' by first checking the construction + variable named 'var' and finally searching the path. If either method + fails to detect the program, then false is returned, otherwise + the programs full path is returned. + """ + + import SCons.Environment + try: + return SCons.Environment.Environment()[var] == prog and self.where_is(prog) + except KeyError: + return None + def wrap_stdout(self, build_str = "", read_str = ""): """Wraps standard output string(s) in the normal "Reading ... done" and "Building ... done" strings diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index cad5670b..628de307 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -58,7 +58,6 @@ class UtilTestCase(unittest.TestCase): def cvt(str): return string.replace(str, '/', os.sep) - newcom = scons_subst("test $TARGETS $SOURCES", loc, {}) assert newcom == cvt("test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp /bar/ack.cpp ../foo/ack.c") @@ -90,15 +89,15 @@ class UtilTestCase(unittest.TestCase): assert newcom == cvt("test foo") newcom = scons_subst("test ${TARGET.abspath}", loc, {}) - assert newcom == cvt("test %s/foo/bar.exe"%os.getcwd()), newcom + assert newcom == cvt("test %s/foo/bar.exe"%SCons.Util.updrive(os.getcwd())), newcom newcom = scons_subst("test ${SOURCES.abspath}", loc, {}) - assert newcom == cvt("test %s/foo/blah.cpp %s %s/foo/ack.c"%(os.getcwd(), - os.path.abspath(os.path.normpath("/bar/ack.cpp")), - os.path.normpath(os.getcwd()+"/.."))), newcom + assert newcom == cvt("test %s/foo/blah.cpp %s %s/foo/ack.c"%(SCons.Util.updrive(os.getcwd()), + SCons.Util.updrive(os.path.abspath(os.path.normpath("/bar/ack.cpp"))), + SCons.Util.updrive(os.path.normpath(os.getcwd()+"/..")))), newcom newcom = scons_subst("test ${SOURCE.abspath}", loc, {}) - assert newcom == cvt("test %s/foo/blah.cpp"%os.getcwd()), newcom + assert newcom == cvt("test %s/foo/blah.cpp"%SCons.Util.updrive(os.getcwd())), newcom newcom = scons_subst("test $xxx", loc, {}) assert newcom == cvt("test"), newcom diff --git a/test/AS.py b/test/AS.py index 97ad0ce2..b25a1b62 100644 --- a/test/AS.py +++ b/test/AS.py @@ -167,8 +167,7 @@ test.fail_test(test.read('test5' + _exe) != "This is a .spp file.\n") test.fail_test(test.read('test6' + _exe) != "This is a .SPP file.\n") - -as = test.where_is('as') +as = test.detect('AS', 'as') if as: diff --git a/test/RANLIB.py b/test/RANLIB.py index 14708e01..04a084f1 100644 --- a/test/RANLIB.py +++ b/test/RANLIB.py @@ -39,7 +39,7 @@ else: test = TestSCons.TestSCons() -ranlib = test.where_is('ranlib') +ranlib = test.detect('RANLIB', 'ranlib') test.no_result(not ranlib) diff --git a/test/RANLIBFLAGS.py b/test/RANLIBFLAGS.py index b3e94510..80aaf161 100644 --- a/test/RANLIBFLAGS.py +++ b/test/RANLIBFLAGS.py @@ -38,7 +38,7 @@ else: test = TestSCons.TestSCons() -ranlib = test.where_is('ranlib') +ranlib = test.detect('RANLIB', 'ranlib') test.no_result(not ranlib) diff --git a/test/Scanner.py b/test/Scanner.py index 96088994..461f4148 100644 --- a/test/Scanner.py +++ b/test/Scanner.py @@ -73,10 +73,10 @@ kscan = Scanner(name = 'kfile', scanners = Environment().Dictionary('SCANNERS') env = Environment(SCANNERS = scanners + [kscan]) -env.Command('foo', 'foo.k', '%s build.py $SOURCES $TARGET') +env.Command('foo', 'foo.k', r'%s build.py $SOURCES $TARGET') bar_in = File('bar.in') -env.Command('bar', bar_in, '%s build.py $SOURCES $TARGET') +env.Command('bar', bar_in, r'%s build.py $SOURCES $TARGET') bar_in.source_scanner = kscan """ % (python, python)) diff --git a/test/TAR.py b/test/TAR.py index ee9e7d41..fbfacf6b 100644 --- a/test/TAR.py +++ b/test/TAR.py @@ -82,8 +82,7 @@ test.run(arguments = 'bbb.tar', stderr = None) test.fail_test(test.read('bbb.tar') != "sub1/file5\nsub1/file6\nfile4\n") - -tar = test.where_is('tar') +tar = test.detect('TAR', 'tar') if tar: @@ -95,9 +94,9 @@ os.system(string.join(sys.argv[1:], " ")) """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) test.write('SConstruct', """ -foo = Environment(tools = ['tar']) +foo = Environment() tar = foo.Dictionary('TAR') -bar = Environment(tools = ['tar'], TAR = r'%s wrapper.py ' + tar) +bar = Environment(TAR = r'%s wrapper.py ' + tar) foo.Tar(target = 'foo.tar', source = ['file10', 'file11']) foo.Tar(target = 'foo.tar', source = 'file12') bar.Tar(target = 'bar.tar', source = ['file13', 'file14']) diff --git a/test/TARFLAGS.py b/test/TARFLAGS.py index 9bf1359e..583e2742 100644 --- a/test/TARFLAGS.py +++ b/test/TARFLAGS.py @@ -87,7 +87,7 @@ test.fail_test(test.read('bbb.tar') != "options: -x\nsub1/file5\nsub1/file6\nfi -tar = test.where_is('tar') +tar = test.detect('TAR', 'tar') if tar: @@ -99,11 +99,10 @@ os.system(string.join(sys.argv[1:], " ")) """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) test.write('SConstruct', """ -foo = Environment(tools = ['tar']) +foo = Environment() tar = foo['TAR'] -bar = Environment(tools = ['tar'], - TAR = '', - TARFLAGS = '%s wrapper.py ' + tar + ' -c -b 1') +bar = Environment(TAR = '', + TARFLAGS = r'%s wrapper.py ' + tar + ' -c -b 1') foo.Tar(target = 'foo.tar', source = ['file10', 'file11']) foo.Tar(target = 'foo.tar', source = 'file12') bar.Tar(target = 'bar.tar', source = ['file13', 'file14']) diff --git a/test/option--D.py b/test/option--D.py index dbfbb3e6..67517cd8 100644 --- a/test/option--D.py +++ b/test/option--D.py @@ -44,7 +44,7 @@ file.close() test.write('SConstruct', """ import SCons.Defaults -B = Builder(action='%s build.py $TARGET $SOURCES') +B = Builder(action=r'%s build.py $TARGET $SOURCES') env = Environment() env['BUILDERS']['B'] = B env.B(target = 'sub1/foo.out', source = 'sub1/foo.in') diff --git a/test/option-q.py b/test/option-q.py index efb192a1..c6f21317 100644 --- a/test/option-q.py +++ b/test/option-q.py @@ -43,7 +43,7 @@ file.close() """) test.write('SConstruct', """ -B = Builder(action='%s build.py $TARGET $SOURCES') +B = Builder(action=r'%s build.py $TARGET $SOURCES') env = Environment(BUILDERS = { 'B' : B }) env.B(target = 'aaa.out', source = 'aaa.in') env.B(target = 'bbb.out', source = 'bbb.in') diff --git a/test/option-u.py b/test/option-u.py index 54f4f460..5e00ea8d 100644 --- a/test/option-u.py +++ b/test/option-u.py @@ -46,7 +46,7 @@ file.close() test.write('SConstruct', """ import SCons.Defaults env = Environment() -env['BUILDERS']['B'] = Builder(action='%s build.py $TARGET $SOURCES') +env['BUILDERS']['B'] = Builder(action=r'%s build.py $TARGET $SOURCES') env.B(target = 'sub1/foo.out', source = 'sub1/foo.in') Default('.') Export('env') -- 2.26.2