From: stevenknight Date: Wed, 16 Dec 2009 07:07:13 +0000 (+0000) Subject: Fix the tests of runtest.py now that QMTest is no longer being used X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0a74aa36eb77913875d8d5d6a5cc54c1fa46b2f1;p=scons.git Fix the tests of runtest.py now that QMTest is no longer being used by default. Fix use of subprocess in Python 2.4+ and exit statuses of popen'ed scripts in earlier versions of Python. Support the ability to execute a directory's tests by naming the directory as a command- line argument. git-svn-id: http://scons.tigris.org/svn/scons/trunk@4554 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/runtest.py b/runtest.py index 731f36f2..a4dcee41 100644 --- a/runtest.py +++ b/runtest.py @@ -373,6 +373,8 @@ except ImportError: self.status = childerr.close() if not self.status: self.status = 0 + else: + self.status = self.status >> 8 else: class PopenExecutor(Base): def execute(self): @@ -381,13 +383,16 @@ except ImportError: self.stdout = p.fromchild.read() self.stderr = p.childerr.read() self.status = p.wait() + self.status = self.status >> 8 else: class PopenExecutor(Base): def execute(self): - p = subprocess.Popen(self.command_str, shell=True) - p.stdin.close() + p = subprocess.Popen(self.command_str, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True) self.stdout = p.stdout.read() - self.stdout = p.stderr.read() + self.stderr = p.stderr.read() self.status = p.wait() class Aegis(SystemExecutor): @@ -575,6 +580,25 @@ if old_pythonpath: tests = [] +def find_Tests_py(tdict, dirname, names): + for n in filter(lambda n: n[-8:] == "Tests.py", names): + tdict[os.path.join(dirname, n)] = 1 + +def find_py(tdict, dirname, names): + tests = filter(lambda n: n[-3:] == ".py", names) + try: + excludes = open(os.path.join(dirname,".exclude_tests")).readlines() + except (OSError, IOError): + pass + else: + for exclude in excludes: + exclude = string.split(exclude, '#' , 1)[0] + exclude = string.strip(exclude) + if not exclude: continue + tests = filter(lambda n, ex = exclude: n != ex, tests) + for n in tests: + tdict[os.path.join(dirname, n)] = 1 + if args: if spe: for a in args: @@ -589,7 +613,18 @@ if args: break else: for a in args: - tests.extend(glob.glob(a)) + for path in glob.glob(a): + if os.path.isdir(path): + tdict = {} + if path[:3] == 'src': + os.path.walk(path, find_Tests_py, tdict) + elif path[:4] == 'test': + os.path.walk(path, find_py, tdict) + t = tdict.keys() + t.sort() + tests.extend(t) + else: + tests.append(path) elif testlistfile: tests = open(testlistfile, 'r').readlines() tests = filter(lambda x: x[0] != '#', tests) @@ -607,28 +642,8 @@ elif all and not qmtest: # by the Aegis packaging build to make sure that we're building # things correctly.) tdict = {} - - def find_Tests_py(tdict, dirname, names): - for n in filter(lambda n: n[-8:] == "Tests.py", names): - tdict[os.path.join(dirname, n)] = 1 os.path.walk('src', find_Tests_py, tdict) - - def find_py(tdict, dirname, names): - tests = filter(lambda n: n[-3:] == ".py", names) - try: - excludes = open(os.path.join(dirname,".exclude_tests")).readlines() - except (OSError, IOError): - pass - else: - for exclude in excludes: - exclude = string.split(exclude, '#' , 1)[0] - exclude = string.strip(exclude) - if not exclude: continue - tests = filter(lambda n, ex = exclude: n != ex, tests) - for n in tests: - tdict[os.path.join(dirname, n)] = 1 os.path.walk('test', find_py, tdict) - if format == '--aegis' and aegis: cmd = "aegis -list -unf pf 2>/dev/null" for line in os.popen(cmd, "r").readlines(): @@ -716,6 +731,7 @@ class Unbuffered: return getattr(self.file, attr) sys.stdout = Unbuffered(sys.stdout) +sys.stderr = Unbuffered(sys.stderr) if list_only: for t in tests: diff --git a/test/runtest/aegis/batch-output.py b/test/runtest/aegis/batch-output.py index bb2aa1ed..e2f00ee7 100644 --- a/test/runtest/aegis/batch-output.py +++ b/test/runtest/aegis/batch-output.py @@ -40,7 +40,13 @@ test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) -test.run(arguments = '-o aegis.out --aegis test', status=1) +expect_stderr = """\ +FAILING TEST STDERR +NO RESULT TEST STDERR +PASSING TEST STDERR +""" + +test.run(arguments = '-o aegis.out --aegis test', stderr=expect_stderr) expect = """\ test_result = [ diff --git a/test/runtest/baseline/combined.py b/test/runtest/baseline/combined.py index bd479087..02f3f53e 100644 --- a/test/runtest/baseline/combined.py +++ b/test/runtest/baseline/combined.py @@ -34,6 +34,7 @@ import os.path import TestRuntest +python = TestRuntest.python test_fail_py = os.path.join('test', 'fail.py') test_no_result_py = os.path.join('test', 'no_result.py') test_pass_py = os.path.join('test', 'pass.py') @@ -48,41 +49,31 @@ test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) -# NOTE: The "test/fail.py : FAIL" and "test/pass.py : PASS" lines both -# have spaces at the end. +expect_stdout = """\ +%(python)s -tt test/fail.py +FAILING TEST STDOUT +%(python)s -tt test/no_result.py +NO RESULT TEST STDOUT +%(python)s -tt test/pass.py +PASSING TEST STDOUT -expect = r"""qmtest run --output baseline.qmr --format none --result-stream="scons_tdb.AegisBaselineStream" test ---- TEST RESULTS ------------------------------------------------------------- +Failed the following test: +\ttest/fail.py - %(test_fail_py)s : FAIL - - FAILING TEST STDOUT - - FAILING TEST STDERR - - %(test_no_result_py)s : NO_RESULT - - NO RESULT TEST STDOUT - - NO RESULT TEST STDERR - - %(test_pass_py)s : PASS - ---- TESTS WITH UNEXPECTED OUTCOMES ------------------------------------------- - - %(test_no_result_py)s : NO_RESULT - - %(test_pass_py)s : PASS - - ---- STATISTICS --------------------------------------------------------------- - - 1 ( 33%%) tests as expected - 1 ( 33%%) tests unexpected PASS - 1 ( 33%%) tests unexpected NO_RESULT +NO RESULT from the following test: +\ttest/no_result.py """ % locals() -test.run(arguments = '-b . test', status = 1, stdout = expect) +expect_stderr = """\ +FAILING TEST STDERR +NO RESULT TEST STDERR +PASSING TEST STDERR +""" + +test.run(arguments='-b . test', + status=1, + stdout=expect_stdout, + stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/baseline/fail.py b/test/runtest/baseline/fail.py index bd52a182..fb7265e5 100644 --- a/test/runtest/baseline/fail.py +++ b/test/runtest/baseline/fail.py @@ -30,34 +30,27 @@ Test how we handle a failing test specified on the command line. import TestRuntest +python = TestRuntest.python + test = TestRuntest.TestRuntest() test.subdir('test') test.write_failing_test(['test', 'fail.py']) -# NOTE: The "test/fail.py : FAIL" line has spaces at the end. - -expect = r"""qmtest run --output baseline.qmr --format none --result-stream="scons_tdb.AegisBaselineStream" test/fail.py ---- TEST RESULTS ------------------------------------------------------------- - - test/fail.py : FAIL - - FAILING TEST STDOUT - - FAILING TEST STDERR - ---- TESTS WITH UNEXPECTED OUTCOMES ------------------------------------------- - - None. - - ---- STATISTICS --------------------------------------------------------------- +expect_stdout = """\ +%(python)s -tt test/fail.py +FAILING TEST STDOUT +""" % locals() - 1 (100%) tests as expected +expect_stderr = """\ +FAILING TEST STDERR """ -test.run(arguments = '-b . test/fail.py', status = 1, stdout = expect) +test.run(arguments='-b . test/fail.py', + status=1, + stdout=expect_stdout, + stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/baseline/no_result.py b/test/runtest/baseline/no_result.py index d1c0f759..8641c907 100644 --- a/test/runtest/baseline/no_result.py +++ b/test/runtest/baseline/no_result.py @@ -30,32 +30,27 @@ Test how we handle a no-results test specified on the command line. import TestRuntest +python = TestRuntest.python + test = TestRuntest.TestRuntest() test.subdir('test') test.write_no_result_test(['test', 'no_result.py']) -expect = r"""qmtest run --output baseline.qmr --format none --result-stream="scons_tdb.AegisBaselineStream" test/no_result.py ---- TEST RESULTS ------------------------------------------------------------- - - test/no_result.py : NO_RESULT - - NO RESULT TEST STDOUT - - NO RESULT TEST STDERR - ---- TESTS WITH UNEXPECTED OUTCOMES ------------------------------------------- - - test/no_result.py : NO_RESULT - - ---- STATISTICS --------------------------------------------------------------- +expect_stdout = """\ +%(python)s -tt test/no_result.py +NO RESULT TEST STDOUT +""" % locals() - 1 (100%) tests unexpected NO_RESULT +expect_stderr = """\ +NO RESULT TEST STDERR """ -test.run(arguments = '-b . test/no_result.py', status = 1, stdout = expect) +test.run(arguments='-b . test/no_result.py', + status=2, + stdout=expect_stdout, + stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/baseline/pass.py b/test/runtest/baseline/pass.py index 3644052b..ef3a99e1 100644 --- a/test/runtest/baseline/pass.py +++ b/test/runtest/baseline/pass.py @@ -30,30 +30,26 @@ Test how we handle a passing test specified on the command line. import TestRuntest +python = TestRuntest.python + test = TestRuntest.TestRuntest() test.subdir('test') test.write_passing_test(['test', 'pass.py']) -# NOTE: The "test/pass.py : PASS" line has spaces at the end. - -expect = r"""qmtest run --output baseline.qmr --format none --result-stream="scons_tdb.AegisBaselineStream" test/pass.py ---- TEST RESULTS ------------------------------------------------------------- - - test/pass.py : PASS - ---- TESTS WITH UNEXPECTED OUTCOMES ------------------------------------------- - - test/pass.py : PASS - - ---- STATISTICS --------------------------------------------------------------- +expect_stdout = """\ +%(python)s -tt test/pass.py +PASSING TEST STDOUT +""" % locals() - 1 (100%) tests unexpected PASS +expect_stderr = """\ +PASSING TEST STDERR """ -test.run(arguments = '-b . test/pass.py', stdout = expect) +test.run(arguments='-b . test', + stdout=expect_stdout, + stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/fallback.py b/test/runtest/fallback.py index d74ba6c9..c7354a31 100644 --- a/test/runtest/fallback.py +++ b/test/runtest/fallback.py @@ -91,8 +91,6 @@ NO RESULT from the following test: """ % locals() expect_stderr = """\ -Warning: found neither qmtest nor qmtest.py on $PATH; -\tassuming --noqmtest option. FAILING TEST STDERR NO RESULT TEST STDERR PASSING TEST STDERR diff --git a/test/runtest/print_time.py b/test/runtest/print_time.py index 38a5bc6f..54f90fe2 100644 --- a/test/runtest/print_time.py +++ b/test/runtest/print_time.py @@ -35,6 +35,7 @@ import re import TestCmd import TestRuntest +python = TestRuntest.python test_fail_py = re.escape(os.path.join('test', 'fail.py')) test_no_result_py = re.escape(os.path.join('test', 'no_result.py')) test_pass_py = re.escape(os.path.join('test', 'pass.py')) @@ -49,49 +50,35 @@ test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) -# NOTE: The "test/fail.py : FAIL" and "test/pass.py : PASS" lines both -# have spaces at the end. - -expect = r"""qmtest run --output results.qmr --format none --result-stream="scons_tdb.AegisChangeStream\(print_time='1'\)" test ---- TEST RESULTS ------------------------------------------------------------- - - %(test_fail_py)s : FAIL - - FAILING TEST STDOUT - - FAILING TEST STDERR - - Total execution time: \d+\.\d+ seconds - - %(test_no_result_py)s : NO_RESULT - - NO RESULT TEST STDOUT - - NO RESULT TEST STDERR - - Total execution time: \d+\.\d+ seconds - - %(test_pass_py)s : PASS - - Total execution time: \d+\.\d+ seconds - ---- TESTS THAT DID NOT PASS -------------------------------------------------- - - %(test_fail_py)s : FAIL - - %(test_no_result_py)s : NO_RESULT - - ---- STATISTICS --------------------------------------------------------------- - - 3 tests total - - 1 \( 33%%\) tests PASS - 1 \( 33%%\) tests FAIL - 1 \( 33%%\) tests NO_RESULT +expect_stdout = """\ +%(python)s -tt test/fail.py +FAILING TEST STDOUT +Test execution time: \\d+.\\d seconds +%(python)s -tt test/no_result.py +NO RESULT TEST STDOUT +Test execution time: \\d+.\\d seconds +%(python)s -tt test/pass.py +PASSING TEST STDOUT +Test execution time: \\d+.\\d seconds +Total execution time for all tests: \\d+.\\d seconds + +Failed the following test: +\ttest/fail.py + +NO RESULT from the following test: +\ttest/no_result.py """ % locals() -test.run(arguments = '-t test', status = 1, stdout = expect) +expect_stderr = """\ +FAILING TEST STDERR +NO RESULT TEST STDERR +PASSING TEST STDERR +""" + +test.run(arguments='-t test', + status=1, + stdout=expect_stdout, + stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/python.py b/test/runtest/python.py index 1830aa7b..e798a53d 100644 --- a/test/runtest/python.py +++ b/test/runtest/python.py @@ -48,26 +48,18 @@ test.subdir('test') test.write_passing_test(['test', 'pass.py']) -# NOTE: The "test/pass.py : PASS" line has spaces at the end. - -expect = r"""qmtest run --output results.qmr --format none --result-stream="scons_tdb.AegisChangeStream" --context python="%(mypython)s" test ---- TEST RESULTS ------------------------------------------------------------- - - %(test_pass_py)s : PASS - ---- TESTS THAT DID NOT PASS -------------------------------------------------- - - None. - - ---- STATISTICS --------------------------------------------------------------- - - 1 tests total - - 1 (100%%) tests PASS +expect_stdout = """\ +%(mypython)s -tt test/pass.py +PASSING TEST STDOUT """ % locals() -test.run(arguments = ['-P', mypython, 'test'], stdout = expect) +expect_stderr = """\ +PASSING TEST STDERR +""" + +test.run(arguments=['-P', mypython, 'test'], + stdout=expect_stdout, + stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/simple/combined.py b/test/runtest/simple/combined.py index 0c9997fd..6794ea5d 100644 --- a/test/runtest/simple/combined.py +++ b/test/runtest/simple/combined.py @@ -36,6 +36,7 @@ import TestRuntest test = TestRuntest.TestRuntest() +python = TestRuntest.python test_fail_py = os.path.join('test', 'fail.py') test_no_result_py = os.path.join('test', 'no_result.py') test_pass_py = os.path.join('test', 'pass.py') @@ -48,43 +49,31 @@ test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) -# NOTE: The "test/fail.py : FAIL" and "test/pass.py : PASS" lines both -# have spaces at the end. +expect_stdout = """\ +%(python)s -tt test/fail.py +FAILING TEST STDOUT +%(python)s -tt test/no_result.py +NO RESULT TEST STDOUT +%(python)s -tt test/pass.py +PASSING TEST STDOUT -expect = r"""qmtest run --output results.qmr --format none --result-stream="scons_tdb.AegisChangeStream" test ---- TEST RESULTS ------------------------------------------------------------- +Failed the following test: +\ttest/fail.py - %(test_fail_py)s : FAIL - - FAILING TEST STDOUT - - FAILING TEST STDERR - - %(test_no_result_py)s : NO_RESULT - - NO RESULT TEST STDOUT - - NO RESULT TEST STDERR - - %(test_pass_py)s : PASS - ---- TESTS THAT DID NOT PASS -------------------------------------------------- - - %(test_fail_py)s : FAIL - - %(test_no_result_py)s : NO_RESULT - - ---- STATISTICS --------------------------------------------------------------- - - 3 tests total - - 1 ( 33%%) tests PASS - 1 ( 33%%) tests FAIL - 1 ( 33%%) tests NO_RESULT +NO RESULT from the following test: +\ttest/no_result.py """ % locals() -test.run(arguments = 'test', status = 1, stdout = expect) +expect_stderr = """\ +FAILING TEST STDERR +NO RESULT TEST STDERR +PASSING TEST STDERR +""" + +test.run(arguments='test', + status=1, + stdout=expect_stdout, + stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/simple/fail.py b/test/runtest/simple/fail.py index f060f507..4a36c472 100644 --- a/test/runtest/simple/fail.py +++ b/test/runtest/simple/fail.py @@ -30,36 +30,27 @@ Test how we handle a failing test specified on the command line. import TestRuntest +python = TestRuntest.python + test = TestRuntest.TestRuntest() test.subdir('test') test.write_failing_test(['test', 'fail.py']) -# NOTE: The "test/fail.py : FAIL" line has spaces at the end. - -expect = r"""qmtest run --output results.qmr --format none --result-stream="scons_tdb.AegisChangeStream" test/fail.py ---- TEST RESULTS ------------------------------------------------------------- - - test/fail.py : FAIL - - FAILING TEST STDOUT - - FAILING TEST STDERR - ---- TESTS THAT DID NOT PASS -------------------------------------------------- - - test/fail.py : FAIL - - ---- STATISTICS --------------------------------------------------------------- - - 1 tests total +expect_stdout = """\ +%(python)s -tt test/fail.py +FAILING TEST STDOUT +""" % locals() - 1 (100%) tests FAIL +expect_stderr = """\ +FAILING TEST STDERR """ -test.run(arguments = 'test/fail.py', status = 1, stdout = expect) +test.run(arguments='test/fail.py', + status=1, + stdout=expect_stdout, + stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/simple/no_result.py b/test/runtest/simple/no_result.py index 55d6f0e5..475c5a8a 100644 --- a/test/runtest/simple/no_result.py +++ b/test/runtest/simple/no_result.py @@ -30,34 +30,27 @@ Test how we handle a no-results test specified on the command line. import TestRuntest +python = TestRuntest.python + test = TestRuntest.TestRuntest() test.subdir('test') test.write_no_result_test(['test', 'no_result.py']) -expect = r"""qmtest run --output results.qmr --format none --result-stream="scons_tdb.AegisChangeStream" test/no_result.py ---- TEST RESULTS ------------------------------------------------------------- - - test/no_result.py : NO_RESULT - - NO RESULT TEST STDOUT - - NO RESULT TEST STDERR - ---- TESTS THAT DID NOT PASS -------------------------------------------------- - - test/no_result.py : NO_RESULT - - ---- STATISTICS --------------------------------------------------------------- - - 1 tests total +expect_stdout = """\ +%(python)s -tt test/no_result.py +NO RESULT TEST STDOUT +""" % locals() - 1 (100%) tests NO_RESULT +expect_stderr = """\ +NO RESULT TEST STDERR """ -test.run(arguments = 'test/no_result.py', status = 1, stdout = expect) +test.run(arguments='test/no_result.py', + status=2, + stdout=expect_stdout, + stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/simple/pass.py b/test/runtest/simple/pass.py index ee7bc740..873be09f 100644 --- a/test/runtest/simple/pass.py +++ b/test/runtest/simple/pass.py @@ -30,32 +30,24 @@ Test how we handle a passing test specified on the command line. import TestRuntest +python = TestRuntest.python + test = TestRuntest.TestRuntest() test.subdir('test') test.write_passing_test(['test', 'pass.py']) -# NOTE: The "test/pass.py : PASS" line has spaces at the end. - -expect = r"""qmtest run --output results.qmr --format none --result-stream="scons_tdb.AegisChangeStream" test/pass.py ---- TEST RESULTS ------------------------------------------------------------- - - test/pass.py : PASS - ---- TESTS THAT DID NOT PASS -------------------------------------------------- - - None. - - ---- STATISTICS --------------------------------------------------------------- - - 1 tests total +expect_stdout = """\ +%(python)s -tt test/pass.py +PASSING TEST STDOUT +""" % locals() - 1 (100%) tests PASS +expect_stderr = """\ +PASSING TEST STDERR """ -test.run(arguments = 'test/pass.py', stdout = expect) +test.run(arguments='test/pass.py', stdout=expect_stdout, stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/src.py b/test/runtest/src.py index 70d10f0d..18db972a 100644 --- a/test/runtest/src.py +++ b/test/runtest/src.py @@ -33,11 +33,12 @@ import os.path import TestRuntest -test = TestRuntest.TestRuntest(verbose=1) +test = TestRuntest.TestRuntest() test.subdir(['src'], ['src', 'suite']) +python = TestRuntest.python src_passTests_py = os.path.join('src', 'passTests.py') src_suite_passTests_py = os.path.join('src', 'suite', 'passTests.py') @@ -49,29 +50,19 @@ test.write_passing_test(['src', 'suite', 'pass.py']) test.write_passing_test(['src', 'suite', 'passTests.py']) -# NOTE: The "test/pass.py : PASS" and "test/passTests.py : PASS" lines -# both have spaces at the end. - -expect = r"""qmtest run --output results.qmr --format none --result-stream="scons_tdb.AegisChangeStream" src ---- TEST RESULTS ------------------------------------------------------------- - - %(src_passTests_py)s : PASS - - %(src_suite_passTests_py)s : PASS - ---- TESTS THAT DID NOT PASS -------------------------------------------------- - - None. - - ---- STATISTICS --------------------------------------------------------------- - - 2 tests total +expect_stdout = """\ +%(python)s -tt src/passTests.py +PASSING TEST STDOUT +%(python)s -tt src/suite/passTests.py +PASSING TEST STDOUT +""" % locals() - 2 (100%%) tests PASS +expect_stderr = """\ +PASSING TEST STDERR +PASSING TEST STDERR """ % locals() -test.run(arguments = 'src', stdout = expect) +test.run(arguments='src', stdout=expect_stdout, stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/testlistfile.py b/test/runtest/testlistfile.py index a9d2565b..dc78c296 100644 --- a/test/runtest/testlistfile.py +++ b/test/runtest/testlistfile.py @@ -32,6 +32,7 @@ import os.path import TestRuntest +python = TestRuntest.python test_fail_py = os.path.join('test', 'fail.py') test_no_result_py = os.path.join('test', 'no_result.py') test_pass_py = os.path.join('test', 'pass.py') @@ -51,27 +52,16 @@ test.write('t.txt', """\ %(test_pass_py)s """ % locals()) -# NOTE: The "test/fail.py : FAIL" and "test/pass.py : PASS" lines both -# have spaces at the end. - -expect = """qmtest run --output results.qmr --format none --result-stream="scons_tdb.AegisChangeStream" %(test_pass_py)s ---- TEST RESULTS ------------------------------------------------------------- - - %(test_pass_py)s : PASS - ---- TESTS THAT DID NOT PASS -------------------------------------------------- - - None. - - ---- STATISTICS --------------------------------------------------------------- - - 1 tests total - - 1 (100%%) tests PASS +expect_stdout = """\ +%(python)s -tt test/pass.py +PASSING TEST STDOUT """ % locals() -test.run(arguments = '-f t.txt', stdout = expect) +expect_stderr = """\ +PASSING TEST STDERR +""" + +test.run(arguments='-f t.txt', stdout=expect_stdout, stderr=expect_stderr) test.pass_test() diff --git a/test/runtest/xml/output.py b/test/runtest/xml/output.py index 52b718a2..3641d22f 100644 --- a/test/runtest/xml/output.py +++ b/test/runtest/xml/output.py @@ -32,10 +32,12 @@ import os.path import re import sys +import TestCmd import TestRuntest -test = TestRuntest.TestRuntest() +test = TestRuntest.TestRuntest(match = TestCmd.match_re) +python = TestRuntest.python test_fail_py = re.escape(os.path.join('test', 'fail.py')) test_no_result_py = re.escape(os.path.join('test', 'no_result.py')) test_pass_py = re.escape(os.path.join('test', 'pass.py')) @@ -58,135 +60,45 @@ test.write_no_result_test(['test', 'no_result.py']) test.write_passing_test(['test', 'pass.py']) -test.run(arguments = '-o xml.out --xml test', status = 1) - -expect_engine = """\ - - __build__='D456' - __buildsys__='another_fake_system' - __date__='Dec 31 1999' - __developer__='John Doe' - __version__='4\\.5\\.6' - -""" - -expect_script = """\ - - __build__='D123' - __buildsys__='fake_system' - __date__='Jan 1 1970' - __developer__='Anonymous' - __version__='1\\.2\\.3' - -""" - -# The actual values printed for sys and os.environ will be completely -# dependent on the local values. Don't bother trying to match, just -# look to see if the opening tag exists. - -expect_sys = """\ - -""" - -expect_os_environ = """\ - -""" - -expect_fail = """\ - - - "1" - - - "<pre>FAILING TEST STDERR%(cr)s -</pre>" - - - "<pre>FAILING TEST STDOUT%(cr)s -</pre>" - - - "Non-zero exit_code\\." - - - "[\\d.]+" - - - "[\\d.]+" - - - "local" - - -""" % locals() - -expect_no_result = """\ - - - "2" - - - "<pre>NO RESULT TEST STDERR%(cr)s -</pre>" - - - "<pre>NO RESULT TEST STDOUT%(cr)s -</pre>" - - - "Non-zero exit_code\\." - - - "[\\d.]+" - - - "[\\d.]+" - - - "local" - - -""" % locals() - -expect_pass = """\ - - - "[\\d.]+" - - - "[\\d.]+" - - - "local" - - +test.run(arguments = '-o xml.out --xml test', status=1) + +expect = """\ + + + test/fail.py + %(python)s -tt test/fail.py + 1 + FAILING TEST STDOUT + + FAILING TEST STDERR + + + + + test/no_result.py + %(python)s -tt test/no_result.py + 2 + NO RESULT TEST STDOUT + + NO RESULT TEST STDERR + + + + + test/pass.py + %(python)s -tt test/pass.py + 0 + PASSING TEST STDOUT + + PASSING TEST STDERR + + + + + """ % locals() -xml_out = test.read('xml.out', 'r') - -expect = [ - expect_engine, - expect_script, - expect_sys, - expect_os_environ, - expect_fail, - expect_no_result, - expect_pass, -] - -non_matches = [] - -for e in expect: - if not re.search(e, xml_out): - non_matches.append(e) - -if non_matches: - for n in non_matches: - print "DID NOT MATCH " + '='*60 - print n - print "ACTUAL XML OUTPUT " + '='*60 - print xml_out - test.fail_test() +test.must_match('xml.out', expect) test.pass_test()