Test writing XML output to a file.
"""
-import os.path
+import os
import re
-import sys
+import string
+import TestCmd
import TestRuntest
-test = TestRuntest.TestRuntest()
+test = TestRuntest.TestRuntest(match = TestCmd.match_re)
+pythonstring = re.escape(TestRuntest.pythonstring)
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'))
-# sys.stdout and sys.stderr are open non-binary ('w' instead of 'wb')
-# so the lines written on Windows are terminated \r\n, not just \n. The
-# expressions below use 'cr' as the optional carriage return character.
-if sys.platform in ['win32']:
- cr = '\r'
-else:
- cr = ''
-
test.subdir('test')
test.write_fake_scons_source_tree()
test.write_passing_test(['test', 'pass.py'])
-test.run(arguments = '-o xml.out --xml test', status = 1)
-
-expect_engine = """\
-<annotation key="scons_test\\.engine">
- __build__='D456'
- __buildsys__='another_fake_system'
- __date__='Dec 31 1999'
- __developer__='John Doe'
- __version__='4\\.5\\.6'
-</annotation>
-"""
-
-expect_script = """\
-<annotation key="scons_test\\.script">
- __build__='D123'
- __buildsys__='fake_system'
- __date__='Jan 1 1970'
- __developer__='Anonymous'
- __version__='1\\.2\\.3'
-</annotation>
-"""
-
-# 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 = """\
-<annotation key="scons_test\\.sys">
-"""
-
-expect_os_environ = """\
-<annotation key="scons_test\\.os\\.environ">
-"""
-
-expect_fail = """\
- <result id="%(test_fail_py)s" kind="test" outcome="FAIL">
- <annotation name="Test\\.exit_code">
- "1"
- </annotation>
- <annotation name="Test\\.stderr">
- "<pre>FAILING TEST STDERR%(cr)s
-</pre>"
- </annotation>
- <annotation name="Test\\.stdout">
- "<pre>FAILING TEST STDOUT%(cr)s
-</pre>"
- </annotation>
- <annotation name="qmtest\\.cause">
- "Non-zero exit_code\\."
- </annotation>
- <annotation name="qmtest\\.end_time">
- "[\\d.]+"
- </annotation>
- <annotation name="qmtest\\.start_time">
- "[\\d.]+"
- </annotation>
- <annotation name="qmtest\\.target">
- "local"
- </annotation>
- </result>
-""" % locals()
-
-expect_no_result = """\
- <result id="%(test_no_result_py)s" kind="test" outcome="FAIL">
- <annotation name="Test.exit_code">
- "2"
- </annotation>
- <annotation name="Test\\.stderr">
- "<pre>NO RESULT TEST STDERR%(cr)s
-</pre>"
- </annotation>
- <annotation name="Test\\.stdout">
- "<pre>NO RESULT TEST STDOUT%(cr)s
-</pre>"
- </annotation>
- <annotation name="qmtest\\.cause">
- "Non-zero exit_code\\."
- </annotation>
- <annotation name="qmtest\\.end_time">
- "[\\d.]+"
- </annotation>
- <annotation name="qmtest\\.start_time">
- "[\\d.]+"
- </annotation>
- <annotation name="qmtest\\.target">
- "local"
- </annotation>
- </result>
-""" % locals()
-
-expect_pass = """\
- <result id="%(test_pass_py)s" kind="test" outcome="PASS">
- <annotation name="qmtest\\.end_time">
- "[\\d.]+"
- </annotation>
- <annotation name="qmtest\\.start_time">
- "[\\d.]+"
- </annotation>
- <annotation name="qmtest\\.target">
- "local"
- </annotation>
- </result>
+test.run(arguments = '-o xml.out --xml test', status=1)
+
+expect = """\
+ <results>
+ <test>
+ <file_name>%(test_fail_py)s</file_name>
+ <command_line>%(pythonstring)s -tt %(test_fail_py)s</command_line>
+ <exit_status>1</exit_status>
+ <stdout>FAILING TEST STDOUT
+</stdout>
+ <stderr>FAILING TEST STDERR
+</stderr>
+ <time>\\d+\.\d</time>
+ </test>
+ <test>
+ <file_name>%(test_no_result_py)s</file_name>
+ <command_line>%(pythonstring)s -tt %(test_no_result_py)s</command_line>
+ <exit_status>2</exit_status>
+ <stdout>NO RESULT TEST STDOUT
+</stdout>
+ <stderr>NO RESULT TEST STDERR
+</stderr>
+ <time>\\d+\.\d</time>
+ </test>
+ <test>
+ <file_name>%(test_pass_py)s</file_name>
+ <command_line>%(pythonstring)s -tt %(test_pass_py)s</command_line>
+ <exit_status>0</exit_status>
+ <stdout>PASSING TEST STDOUT
+</stdout>
+ <stderr>PASSING TEST STDERR
+</stderr>
+ <time>\\d+\.\d</time>
+ </test>
+ <time>\\d+\.\d</time>
+ </results>
""" % 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()