#!/usr/bin/env python
#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
"""
Test writing XML output to a file.
"""
import os.path
import re
import sys
import TestRuntest
test = TestRuntest.TestRuntest()
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_failing_test(['test', 'fail.py'])
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"
""" % 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.pass_test()