From 51fee8699e9d5f64a9ae5e06c0c1acaa7c084185 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Tue, 21 Sep 2004 22:29:07 +0000 Subject: Better test infrastructure for cleaning (-c) messages. (Kevin Quick) --- etc/TestSCons.py | 10 ++++++---- src/CHANGES.txt | 2 ++ test/option-c.py | 39 ++++++++++++++++++--------------------- test/option-n.py | 9 +-------- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/etc/TestSCons.py b/etc/TestSCons.py index 0a5469b..64bb90d 100644 --- a/etc/TestSCons.py +++ b/etc/TestSCons.py @@ -165,18 +165,20 @@ class TestSCons(TestCommon): return None return env.Detect([prog]) - def wrap_stdout(self, build_str = "", read_str = "", error = 0): + def wrap_stdout(self, build_str = "", read_str = "", error = 0, cleaning = 0): """Wraps standard output string(s) in the normal "Reading ... done" and "Building ... done" strings """ + cap,lc = [ ('Build','build'), + ('Clean','clean') ][cleaning] if error: - term = "scons: building terminated because of errors.\n" + term = "scons: %sing terminated because of errors.\n" % lc else: - term = "scons: done building targets.\n" + term = "scons: done %sing targets.\n" % lc return "scons: Reading SConscript files ...\n" + \ read_str + \ "scons: done reading SConscript files.\n" + \ - "scons: Building targets ...\n" + \ + "scons: %sing targets ...\n" % cap + \ build_str + \ term diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 502ef2a..71c03dc 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -135,6 +135,8 @@ RELEASE 0.97 - XXX - Catch incidents of bad builder creation (without an action) and supply meaningful error messages. + - Better test infrastructure for -c output. + From Christoph Wiedemann: - Add an Environment.SetDefault() method that only sets values if diff --git a/test/option-c.py b/test/option-c.py index 26d40ea..30ec6f8 100644 --- a/test/option-c.py +++ b/test/option-c.py @@ -72,15 +72,8 @@ test.fail_test(test.read(test.workpath('foo2.xxx')) != "foo2.in\n") test.fail_test(test.read(test.workpath('foo2.out')) != "foo2.in\n") test.fail_test(test.read(test.workpath('foo3.out')) != "foo3.in\n") -def wrap_clean_stdout(string): - return "scons: Reading SConscript files ...\n" + \ - "scons: done reading SConscript files.\n" + \ - "scons: Cleaning targets ...\n" + \ - string + \ - "scons: done cleaning targets.\n" - test.run(arguments = '-c foo1.out', - stdout = wrap_clean_stdout("Removed foo1.out\n")) + stdout = test.wrap_stdout("Removed foo1.out\n", cleaning=1)) test.fail_test(os.path.exists(test.workpath('foo1.out'))) test.fail_test(not os.path.exists(test.workpath('foo2.xxx'))) @@ -88,7 +81,8 @@ test.fail_test(not os.path.exists(test.workpath('foo2.out'))) test.fail_test(not os.path.exists(test.workpath('foo3.out'))) test.run(arguments = '--clean foo2.out foo2.xxx', - stdout = wrap_clean_stdout("Removed foo2.xxx\nRemoved foo2.out\n")) + stdout = test.wrap_stdout("Removed foo2.xxx\nRemoved foo2.out\n", + cleaning=1)) test.fail_test(os.path.exists(test.workpath('foo1.out'))) test.fail_test(os.path.exists(test.workpath('foo2.xxx'))) @@ -96,7 +90,7 @@ test.fail_test(os.path.exists(test.workpath('foo2.out'))) test.fail_test(not os.path.exists(test.workpath('foo3.out'))) test.run(arguments = '--remove foo3.out', - stdout = wrap_clean_stdout("Removed foo3.out\n")) + stdout = test.wrap_stdout("Removed foo3.out\n", cleaning=1)) test.fail_test(os.path.exists(test.workpath('foo1.out'))) test.fail_test(os.path.exists(test.workpath('foo2.xxx'))) @@ -115,7 +109,7 @@ if hasattr(os, 'symlink'): test.fail_test(not os.path.islink(test.workpath('symlink2'))) test.run(arguments = '-c foo2.xxx', - stdout = wrap_clean_stdout("Removed foo2.xxx\n")) + stdout = test.wrap_stdout("Removed foo2.xxx\n", cleaning=1)) test.fail_test(test.read(test.workpath('foo1.out')) != "foo1.in\n") test.fail_test(os.path.exists(test.workpath('foo2.xxx'))) @@ -134,11 +128,11 @@ if hasattr(os, 'symlink'): test.run(arguments = 'foo1.out foo2.out foo3.out') -expect = wrap_clean_stdout("""Removed foo1.out +expect = test.wrap_stdout("""Removed foo1.out Removed foo2.xxx Removed foo2.out Removed foo3.out -""") +""", cleaning=1) test.run(arguments = '-c -n foo1.out foo2.out foo3.out', stdout = expect) @@ -152,7 +146,7 @@ test.fail_test(test.read(test.workpath('foo3.out')) != "foo3.in\n") test.writable('.', 0) f = open(test.workpath('foo1.out')) test.run(arguments = '-c foo1.out', - stdout = wrap_clean_stdout("scons: Could not remove 'foo1.out': Permission denied\n")) + stdout = test.wrap_stdout("scons: Could not remove 'foo1.out': Permission denied\n", cleaning=1)) test.fail_test(not os.path.exists(test.workpath('foo1.out'))) f.close() test.writable('.', 1) @@ -179,37 +173,40 @@ test.write(['subd', 'SConscript'], """ Clean('.', 'foox.in') """) -expect = wrap_clean_stdout("""Removed foo2.xxx +expect = test.wrap_stdout("""Removed foo2.xxx Removed aux1.x Removed aux2.x -""") +""", cleaning=1) test.run(arguments = '-c foo2.xxx', stdout=expect) test.fail_test(test.read(test.workpath('foo1.out')) != "foo1.in\n") test.fail_test(os.path.exists(test.workpath('foo2.xxx'))) test.fail_test(test.read(test.workpath('foo2.out')) != "foo2.in\n") test.fail_test(test.read(test.workpath('foo3.out')) != "foo3.in\n") -expect = wrap_clean_stdout("Removed %s\n" % os.path.join('subd', 'foox.in')) +expect = test.wrap_stdout("Removed %s\n" % os.path.join('subd', 'foox.in'), + cleaning = 1) test.run(arguments = '-c subd', stdout=expect) test.fail_test(os.path.exists(test.workpath('foox.in'))) -expect = wrap_clean_stdout("""Removed foo1.out +expect = test.wrap_stdout("""Removed foo1.out Removed foo2.xxx Removed foo2.out Removed foo3.out Removed %s Removed %s Removed directory subd -""" % (os.path.join('subd','SConscript'), os.path.join('subd', 'foon.in'))) +""" % (os.path.join('subd','SConscript'), os.path.join('subd', 'foon.in')), + cleaning = 1) test.run(arguments = '-c -n .', stdout=expect) -expect = wrap_clean_stdout("""Removed foo1.out +expect = test.wrap_stdout("""Removed foo1.out Removed foo2.out Removed foo3.out Removed %s Removed %s Removed directory subd -""" % (os.path.join('subd','SConscript'), os.path.join('subd', 'foon.in'))) +""" % (os.path.join('subd','SConscript'), os.path.join('subd', 'foon.in')), + cleaning = 1) test.run(arguments = '-c .', stdout=expect) test.fail_test(os.path.exists(test.workpath('subdir', 'foon.in'))) test.fail_test(os.path.exists(test.workpath('subdir'))) diff --git a/test/option-n.py b/test/option-n.py index 8730c83..aa0b8f2 100644 --- a/test/option-n.py +++ b/test/option-n.py @@ -125,14 +125,7 @@ test.write('f1.out', "X1.out\n") test.run(arguments = '-n f1.out', stdout = expect) test.run(arguments = '-n f1.out', stdout = expect) -def wrap_clean_stdout(string): - return "scons: Reading SConscript files ...\n" + \ - "scons: done reading SConscript files.\n" + \ - "scons: Cleaning targets ...\n" + \ - string + \ - "scons: done cleaning targets.\n" - -expect = wrap_clean_stdout("Removed f1.out\nRemoved f2.out\n") +expect = test.wrap_stdout("Removed f1.out\nRemoved f2.out\n", cleaning=1) test.run(arguments = '-n -c ' + args, stdout = expect) -- cgit v0.12