diff options
author | Steven Knight <knight@baldmt.com> | 2009-02-06 14:55:23 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2009-02-06 14:55:23 (GMT) |
commit | e112f6b49c9063e6a584ff4f7abf9d7a644eef30 (patch) | |
tree | 978573b4ff11f036428c0a08a89085313ad990fa /test/option | |
parent | 9405dad6e18db3934eec7b992e12a2016b1466db (diff) | |
download | SCons-e112f6b49c9063e6a584ff4f7abf9d7a644eef30.zip SCons-e112f6b49c9063e6a584ff4f7abf9d7a644eef30.tar.gz SCons-e112f6b49c9063e6a584ff4f7abf9d7a644eef30.tar.bz2 |
Commonize new string-search-in-output methods:
test.must_contain_all_lines()
test.must_contain_any_line()
test.must_not_contain_any_line()
Update tests to use them. Remove "import string" lines where the
change made them unnecessary.
Diffstat (limited to 'test/option')
-rw-r--r-- | test/option/debug-includes.py | 11 | ||||
-rw-r--r-- | test/option/debug-memoizer.py | 20 | ||||
-rw-r--r-- | test/option/debug-pdb.py | 5 | ||||
-rw-r--r-- | test/option/debug-stacktrace.py | 43 | ||||
-rw-r--r-- | test/option/h.py | 18 | ||||
-rw-r--r-- | test/option/help-options.py | 7 | ||||
-rw-r--r-- | test/option/profile.py | 16 | ||||
-rw-r--r-- | test/option/tree-all.py | 5 | ||||
-rw-r--r-- | test/option/tree-derived.py | 11 | ||||
-rw-r--r-- | test/option/tree-lib.py | 6 |
10 files changed, 42 insertions, 100 deletions
diff --git a/test/option/debug-includes.py b/test/option/debug-includes.py index de9b288..b923306 100644 --- a/test/option/debug-includes.py +++ b/test/option/debug-includes.py @@ -31,7 +31,6 @@ dependencies of a target. import TestSCons import sys -import string import re import time @@ -88,13 +87,7 @@ includes = """ """ test.run(arguments = "--debug=includes foo.obj") -if string.find(test.stdout(), includes) == -1: - print "Did not find expected string in standard output." - print "Expected ==========================================================" - print includes - print "Actual ============================================================" - print test.stdout() - test.fail_test() +test.must_contain_all_lines(test.stdout(), [includes]) @@ -115,7 +108,7 @@ if string.find(test.stdout(), includes) == -1: #test.run(arguments = "--debug=includes foo.exe", # status = 2, # stderr = None) -#test.fail_test(string.find(test.stdout(), includes) == -1) +#test.must_contain_all_lines(test.stdout(), [includes]) diff --git a/test/option/debug-memoizer.py b/test/option/debug-memoizer.py index 7d984de..709f2b1 100644 --- a/test/option/debug-memoizer.py +++ b/test/option/debug-memoizer.py @@ -30,8 +30,6 @@ Test calling the --debug=memoizer option. import os import new -import string - import TestSCons test = TestSCons.TestSCons(match = TestSCons.match_re_dotall) @@ -85,14 +83,7 @@ if use_metaclass: def run_and_check(test, args, desc): test.run(arguments = args) - stdout = test.stdout() - missing = filter(lambda e, s=stdout: string.find(s, e) == -1, expect) - if missing: - print "Missing the following strings in the %s output:" % desc - print " " + string.join(missing, "\n ") - print "STDOUT ============" - print stdout - test.fail_test() + test.must_contain_any_line(test.stdout(), expect) else: @@ -104,14 +95,7 @@ scons: warning: memoization is not supported in this version of Python \\(%s\\) def run_and_check(test, args, desc): test.run(arguments = args, stderr = expect_no_metaclasses) - stdout = test.stdout() - present = filter(lambda e, s=stdout: string.find(s, e) != -1, expect) - if present: - print "The following unexpected strings are present in the %s output:" % desc - print " " + string.join(present, "\n ") - print "STDOUT ============" - print stdout - test.fail_test() + test.must_contain_not_contain_any_line(test.stdout(), expect) for args in ['-h --debug=memoizer', '--debug=memoizer']: diff --git a/test/option/debug-pdb.py b/test/option/debug-pdb.py index fa703d5..bd79d7f 100644 --- a/test/option/debug-pdb.py +++ b/test/option/debug-pdb.py @@ -24,8 +24,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import string - import TestSCons test = TestSCons.TestSCons() @@ -35,7 +33,6 @@ env = Environment() """) test.run(arguments = "--debug=pdb", stdin = "n\ns\nq\n") -test.fail_test(string.find(test.stdout(), "(Pdb)") == -1) -test.fail_test(string.find(test.stdout(), "SCons") == -1) +test.must_contain_all_lines(test.stdout(), ["(Pdb)", "SCons"]) test.pass_test() diff --git a/test/option/debug-stacktrace.py b/test/option/debug-stacktrace.py index 93cb206..80915fd 100644 --- a/test/option/debug-stacktrace.py +++ b/test/option/debug-stacktrace.py @@ -29,26 +29,9 @@ Test the --debug=stacktrace option. """ import TestSCons -import sys -import string -import re -import time test = TestSCons.TestSCons() -def must_contain_all_lines(content, lines): - missing = filter(lambda l, c=content: string.find(c, l) == -1, lines) - if missing: - return [ - "Missing the following lines:\n", - "\t" + string.join(missing, "\n\t") + "\n", - "Output =====\n", - content - ] - return None - - - test.write('SConstruct', """\ def kfile_scan(node, env, target): raise Exception, "kfile_scan error" @@ -77,10 +60,7 @@ lines = [ 'raise Exception, "kfile_scan error"', ] -err = must_contain_all_lines(test.stderr(), lines) -if err: - print string.join(err, '') - test.fail_test(1) +test.must_contain_all_lines(test.stderr(), lines) @@ -96,7 +76,7 @@ test.run(arguments = '--debug=stacktrace', status = 2, stderr = None) -lines = [ +user_error_lines = [ 'UserError: explicit UserError!', 'scons: *** explicit UserError!', ] @@ -104,15 +84,13 @@ lines = [ # The "(most recent call last)" message is used by more recent Python # versions than the "(innermost last)" message, so that's the one # we report if neither matches. -recent_lines = [ "Traceback (most recent call last)" ] + lines -inner_lines = [ "Traceback (innermost last)" ] + lines - -err = must_contain_all_lines(test.stderr(), recent_lines) -if err and must_contain_all_lines(test.stderr(), inner_lines): - print string.join(err, '') - test.fail_test(1) - +traceback_lines = [ + "Traceback (most recent call last)", + "Traceback (innermost last)", +] +test.must_contain_all_lines(test.stderr(), user_error_lines) +test.must_contain_any_line(test.stderr(), traceback_lines) # Test that full path names to SConscript files show up in stack traces. @@ -128,10 +106,7 @@ lines = [ ' File "%s", line 1:' % test.workpath('SConstruct'), ] -err = must_contain_all_lines(test.stderr(), lines) -if err: - print string.join(err, '') - test.fail_test(1) +test.must_contain_all_lines(test.stderr(), lines) diff --git a/test/option/h.py b/test/option/h.py index bf6a6ae..f921333 100644 --- a/test/option/h.py +++ b/test/option/h.py @@ -24,36 +24,34 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import string - import TestSCons test = TestSCons.TestSCons() test.run(arguments = '-h') -test.fail_test(string.find(test.stdout(), '-h, --help') == -1) +test.must_contain_all_lines(test.stdout(), ['-h, --help']) test.run(arguments = '-u -h') -test.fail_test(string.find(test.stdout(), '-h, --help') == -1) +test.must_contain_all_lines(test.stdout(), ['-h, --help']) test.run(arguments = '-U -h') -test.fail_test(string.find(test.stdout(), '-h, --help') == -1) +test.must_contain_all_lines(test.stdout(), ['-h, --help']) test.run(arguments = '-D -h') -test.fail_test(string.find(test.stdout(), '-h, --help') == -1) +test.must_contain_all_lines(test.stdout(), ['-h, --help']) test.write('SConstruct', "") test.run(arguments = '-h') -test.fail_test(string.find(test.stdout(), '-h, --help') == -1) +test.must_contain_all_lines(test.stdout(), ['-h, --help']) test.run(arguments = '-u -h') -test.fail_test(string.find(test.stdout(), '-h, --help') == -1) +test.must_contain_all_lines(test.stdout(), ['-h, --help']) test.run(arguments = '-U -h') -test.fail_test(string.find(test.stdout(), '-h, --help') == -1) +test.must_contain_all_lines(test.stdout(), ['-h, --help']) test.run(arguments = '-D -h') -test.fail_test(string.find(test.stdout(), '-h, --help') == -1) +test.must_contain_all_lines(test.stdout(), ['-h, --help']) test.pass_test() diff --git a/test/option/help-options.py b/test/option/help-options.py index 5f8270f..f33ae52 100644 --- a/test/option/help-options.py +++ b/test/option/help-options.py @@ -39,8 +39,11 @@ test.write('SConstruct', "") test.run(arguments = '-H') -test.fail_test(string.find(test.stdout(), '-H, --help-options') == -1) -test.fail_test(string.find(test.stdout(), '--debug=TYPE') == -1) +expect = [ + '-H, --help-options', + '--debug=TYPE', +] +test.must_contain_all_lines(test.stdout(), expect) # Validate that the help output lists the options in case-insensitive # alphabetical order. diff --git a/test/option/profile.py b/test/option/profile.py index d0c0ffc..aafebda 100644 --- a/test/option/profile.py +++ b/test/option/profile.py @@ -46,7 +46,7 @@ test.write('file.in', "file.in\n") scons_prof = test.workpath('scons.prof') test.run(arguments = "--profile=%s -h" % scons_prof) -test.fail_test(string.find(test.stdout(), 'usage: scons [OPTION]') == -1) +test.must_contain_all_lines(test.stdout(), ['usage: scons [OPTION]']) try: save_stdout = sys.stdout @@ -61,8 +61,7 @@ try: finally: sys.stdout = save_stdout -test.fail_test(string.find(s, 'Main.py') == -1) -test.fail_test(string.find(s, '_main') == -1) +test.must_contain_all_lines(s, ['Main.py', '_main']) @@ -83,17 +82,18 @@ try: finally: sys.stdout = save_stdout -test.fail_test(string.find(s, 'Main.py') == -1) -test.fail_test(string.find(s, '_main') == -1) -test.fail_test(string.find(s, 'FS.py') == -1) +test.must_contain_all_lines(s, ['Main.py', '_main', 'FS.py']) scons_prof = test.workpath('scons3.prof') test.run(arguments = "--profile %s --debug=memory -h" % scons_prof) -test.fail_test(string.find(test.stdout(), 'usage: scons [OPTION]') == -1) -test.fail_test(string.find(test.stdout(), 'Options:') == -1) +expect = [ + 'usage: scons [OPTION]', + 'Options:' +] +test.must_contain_all_lines(test.stdout(), expect) expect = 'Memory before reading SConscript files' lines = string.split(test.stdout(), '\n') diff --git a/test/option/tree-all.py b/test/option/tree-all.py index 0a0af7d..d569b31 100644 --- a/test/option/tree-all.py +++ b/test/option/tree-all.py @@ -134,10 +134,7 @@ tree2 = """ """ % locals() test.run(arguments = "--tree=all .") -if string.find(test.stdout(), tree2) == -1: - sys.stdout.write('Did not find expected tree in the following output:\n') - sys.stdout.write(test.stdout()) - test.fail_test() +test.must_contain_all_lines(test.stdout(), [tree2]) tree3 = """ +-. diff --git a/test/option/tree-derived.py b/test/option/tree-derived.py index 43735f8..3f7cb45 100644 --- a/test/option/tree-derived.py +++ b/test/option/tree-derived.py @@ -31,7 +31,6 @@ dependencies (sources or Depends()) of a target. import TestSCons import sys -import string import re import time @@ -80,7 +79,7 @@ dtree1 = """ """ test.run(arguments = "--tree=derived foo.xxx") -test.fail_test(string.find(test.stdout(), dtree1) == -1) +test.must_contain_all_lines(test.stdout(), [dtree1]) dtree2 = """ +-. @@ -92,7 +91,7 @@ dtree2 = """ """ test.run(arguments = "--tree=derived .") -test.fail_test(string.find(test.stdout(), dtree2) == -1) +test.must_contain_all_lines(test.stdout(), [dtree2]) dtree3 = """ +-. @@ -104,7 +103,7 @@ dtree3 = """ """ test.run(arguments = "--tree=derived,prune .") -test.fail_test(string.find(test.stdout(), dtree3) == -1) +test.must_contain_all_lines(test.stdout(), [dtree3]) dtree4 = """ E = exists @@ -126,7 +125,7 @@ dtree4 = """ test.run(arguments = '-c foo.xxx') test.run(arguments = "--no-exec --tree=derived,status foo.xxx") -test.fail_test(string.find(test.stdout(), dtree4) == -1) +test.must_contain_all_lines(test.stdout(), [dtree4]) # Make sure we print the debug stuff even if there's a build failure. test.write('bar.h', """ @@ -140,6 +139,6 @@ THIS SHOULD CAUSE A BUILD FAILURE test.run(arguments = "--tree=derived foo.xxx", status = 2, stderr = None) -test.fail_test(string.find(test.stdout(), dtree1) == -1) +test.must_contain_all_lines(test.stdout(), [dtree1]) test.pass_test() diff --git a/test/option/tree-lib.py b/test/option/tree-lib.py index 8858b74..d1fdcd2 100644 --- a/test/option/tree-lib.py +++ b/test/option/tree-lib.py @@ -33,7 +33,6 @@ on disk.) Issue 1363: http://scons.tigris.org/issues/show_bug.cgi?id=1363 """ -import string import sys import TestSCons @@ -78,10 +77,7 @@ expect = """ """ test.run(arguments = '--tree=derived foo.h') -if string.find(test.stdout(), expect) == -1: - sys.stdout.write('Did not find expected tree in the following output:\n') - sys.stdout.write(test.stdout()) - test.fail_test() +test.must_contain_all_lines(test.stdout(), [expect]) test.up_to_date(arguments = 'foo.h') |