Merge pull request #4674 from bdbaddog/fix_2281_Aliases_ignore_pre_post_add_actions
[scons.git] / test / runtest / xml / output.py
blob66ec6562b67882b35a1bf2e0f94a90d38619ed6a
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Test writing XML output to a file.
28 """
30 import os
31 import re
33 import TestCmd
34 import TestRuntest
36 test = TestRuntest.TestRuntest(match=TestCmd.match_re, diff=TestCmd.diff_re)
38 pythonstring = re.escape(TestRuntest.pythonstring)
39 pythonflags = TestRuntest.pythonflags
40 test_fail_py = re.escape(os.path.join('test', 'fail.py'))
41 test_no_result_py = re.escape(os.path.join('test', 'no_result.py'))
42 test_pass_py = re.escape(os.path.join('test', 'pass.py'))
44 test.subdir('test')
45 test.write_fake_scons_source_tree()
46 test.write_failing_test(['test', 'fail.py'])
47 test.write_no_result_test(['test', 'no_result.py'])
48 test.write_passing_test(['test', 'pass.py'])
50 test.run(arguments='--xml xml.out test', status=1)
52 expect = f"""\
53 <results>
54 <test>
55 <file_name>{test_fail_py}</file_name>
56 <command_line>{pythonstring}{pythonflags} {test_fail_py}</command_line>
57 <exit_status>1</exit_status>
58 <stdout>FAILING TEST STDOUT
59 </stdout>
60 <stderr>FAILING TEST STDERR
61 </stderr>
62 <time>\\d+\\.\\d</time>
63 </test>
64 <test>
65 <file_name>{test_no_result_py}</file_name>
66 <command_line>{pythonstring}{pythonflags} {test_no_result_py}</command_line>
67 <exit_status>2</exit_status>
68 <stdout>NO RESULT TEST STDOUT
69 </stdout>
70 <stderr>NO RESULT TEST STDERR
71 </stderr>
72 <time>\\d+\\.\\d</time>
73 </test>
74 <test>
75 <file_name>{test_pass_py}</file_name>
76 <command_line>{pythonstring}{pythonflags} {test_pass_py}</command_line>
77 <exit_status>0</exit_status>
78 <stdout>PASSING TEST STDOUT
79 </stdout>
80 <stderr>PASSING TEST STDERR
81 </stderr>
82 <time>\\d+\\.\\d</time>
83 </test>
84 <time>\\d+\\.\\d</time>
85 </results>
86 """
88 # Just strip carriage returns so the regular expression matching works.
89 contents = test.read('xml.out')
90 contents = contents.replace(b'\r', b'')
91 test.write('xml.out', contents)
93 test.must_match('xml.out', expect)
95 test.pass_test()
97 # Local Variables:
98 # tab-width:4
99 # indent-tabs-mode:nil
100 # End:
101 # vim: set expandtab tabstop=4 shiftwidth=4: