llvm.org GIT mirror llvm / 7feb37b
Use quoteattr to ensure we make well formed attributes We were making malformed XML on tests with ' in the name. Switch to using saxutils to set all of our attributes, so it can handle quotes etc correctly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333249 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Matthews 1 year, 4 months ago
4 changed file(s) with 40 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
0 import os
1 from xml.sax.saxutils import escape
1 from xml.sax.saxutils import quoteattr
22 from json import JSONEncoder
33
44 from lit.BooleanExpression import BooleanExpression
361361
362362 def writeJUnitXML(self, fil):
363363 """Write the test's report xml representation to a file handle."""
364 test_name = escape(self.path_in_suite[-1])
364 test_name = quoteattr(self.path_in_suite[-1])
365365 test_path = self.path_in_suite[:-1]
366366 safe_test_path = [x.replace(".","_") for x in test_path]
367367 safe_name = self.suite.name.replace(".","-")
370370 class_name = safe_name + "." + "/".join(safe_test_path)
371371 else:
372372 class_name = safe_name + "." + safe_name
373 testcase_template = "
373 class_name = quoteattr(class_name)
374 testcase_template = '
374375 elapsed_time = self.result.elapsed if self.result.elapsed is not None else 0.0
375376 testcase_xml = testcase_template.format(class_name=class_name, test_name=test_name, time=elapsed_time)
376377 fil.write(testcase_xml)
387388 elif self.result.code == UNSUPPORTED:
388389 unsupported_features = self.getMissingRequiredFeatures()
389390 if unsupported_features:
390 skip_message = escape("Skipping because of: " + ", ".join(unsupported_features))
391 skip_message = "Skipping because of: " + ", ".join(unsupported_features)
391392 else:
392393 skip_message = "Skipping because of configuration."
393394
394 fil.write(">\n\t\"{}\" />\n\n".format(skip_message))
395 fil.write(">\n\t{} />\n\n".format(quoteattr(skip_message)))
395396 else:
396397 fil.write("/>")
1515 import argparse
1616 import tempfile
1717 import shutil
18 from xml.sax.saxutils import quoteattr
1819
1920 import lit.ProgressBar
2021 import lit.LitConfig
609610 xunit_output_file.write("\n")
610611 xunit_output_file.write("\n")
611612 for suite_name, suite in by_suite.items():
612 safe_suite_name = suite_name.replace(".", "-")
613 xunit_output_file.write("
614 xunit_output_file.write(" tests='" + str(suite['passes'] +
615 suite['failures'] + suite['skipped']) + "'")
616 xunit_output_file.write(" failures='" + str(suite['failures']) + "'")
617 xunit_output_file.write(" skipped='" + str(suite['skipped']) +
618 "'>\n")
613 safe_suite_name = quoteattr(suite_name.replace(".", "-"))
614 xunit_output_file.write("615 xunit_output_file.write(" tests=\"" + str(suite['passes'] +
616 suite['failures'] + suite['skipped']) + "\"")
617 xunit_output_file.write(" failures=\"" + str(suite['failures']) + "\"")
618 xunit_output_file.write(" skipped=\"" + str(suite['skipped']) +
619 "\">\n")
619620
620621 for result_test in suite['tests']:
621622 result_test.writeJUnitXML(xunit_output_file)
33
44 # CHECK:
55 # CHECK-NEXT:
6 # CHECK-NEXT: 'shtest-format' tests='23' failures='7' skipped='5'>
6 # CHECK-NEXT: "shtest-format" tests="23" failures="7" skipped="5">
77
8 # CHECK: 'shtest-format.shtest-format' name='argv0.txt' time='{{[0-9]+\.[0-9]+}}'/>
8 # CHECK: "shtest-format.shtest-format" name="argv0.txt" time="{{[0-9]+\.[0-9]+}}"/>
99
10 # CHECK: 'shtest-format.external_shell' name='fail.txt' time='{{[0-9]+\.[0-9]+}}'>
10 # CHECK: "shtest-format.external_shell" name="fail.txt" time="{{[0-9]+\.[0-9]+}}">
1111 # CHECK-NEXT:
1212 # CHECK:
1313 # CHECK-NEXT:
1414
1515
16 # CHECK: 'shtest-format.external_shell' name='fail_with_bad_encoding.txt' time='{{[0-9]+\.[0-9]+}}'>
16 # CHECK: "shtest-format.external_shell" name="fail_with_bad_encoding.txt" time="{{[0-9]+\.[0-9]+}}">
1717 # CHECK-NEXT:
1818 # CHECK:
1919 # CHECK-NEXT:
2020
21 # CHECK: 'shtest-format.external_shell' name='pass.txt' time='{{[0-9]+\.[0-9]+}}'/>
21 # CHECK: "shtest-format.external_shell" name="pass.txt" time="{{[0-9]+\.[0-9]+}}"/>
2222
23 # CHECK: 'shtest-format.shtest-format' name='fail.txt' time='{{[0-9]+\.[0-9]+}}'>
23 # CHECK: "shtest-format.shtest-format" name="fail.txt" time="{{[0-9]+\.[0-9]+}}">
2424 # CHECK-NEXT:
2525 # CHECK:
2626 # CHECK-NEXT:
2727
28 # CHECK: 'shtest-format.shtest-format' name='no-test-line.txt' time='{{[0-9]+\.[0-9]+}}'>
28 # CHECK: "shtest-format.shtest-format" name="no-test-line.txt" time="{{[0-9]+\.[0-9]+}}">
2929 # CHECK-NEXT:
3030 # CHECK:
3131 # CHECK-NEXT:
3232
33 # CHECK: 'shtest-format.shtest-format' name='pass.txt' time='{{[0-9]+\.[0-9]+}}'/>
33 # CHECK: "shtest-format.shtest-format" name="pass.txt" time="{{[0-9]+\.[0-9]+}}"/>
3434
35 # CHECK: 'shtest-format.shtest-format' name='requires-any-missing.txt' time='{{[0-9]+\.[0-9]+}}'>
35 # CHECK: "shtest-format.shtest-format" name="requires-any-missing.txt" time="{{[0-9]+\.[0-9]+}}">
3636 # CHECK-NEXT:
3737
38 # CHECK: 'shtest-format.shtest-format' name='requires-any-present.txt' time='{{[0-9]+\.[0-9]+}}'/>
38 # CHECK: "shtest-format.shtest-format" name="requires-any-present.txt" time="{{[0-9]+\.[0-9]+}}"/>
3939
40 # CHECK: 'shtest-format.shtest-format' name='requires-missing.txt' time='{{[0-9]+\.[0-9]+}}'>
40 # CHECK: "shtest-format.shtest-format" name="requires-missing.txt" time="{{[0-9]+\.[0-9]+}}">
4141 # CHECK-NEXT:
4242
43 # CHECK: 'shtest-format.shtest-format' name='requires-present.txt' time='{{[0-9]+\.[0-9]+}}'/>
43 # CHECK: "shtest-format.shtest-format" name="requires-present.txt" time="{{[0-9]+\.[0-9]+}}"/>
4444
45 # CHECK: 'shtest-format.shtest-format' name='requires-star.txt' time='{{[0-9]+\.[0-9]+}}'>
45 # CHECK: "shtest-format.shtest-format" name="requires-star.txt" time="{{[0-9]+\.[0-9]+}}">
4646 # CHECK-NEXT:
4747 # CHECK:
4848 # CHECK-NEXT:
4949
5050
51 # CHECK: 'shtest-format.shtest-format' name='requires-triple.txt' time='{{[0-9]+\.[0-9]+}}'>
51 # CHECK: "shtest-format.shtest-format" name="requires-triple.txt" time="{{[0-9]+\.[0-9]+}}">
5252 # CHECK-NEXT:
5353
54 # CHECK: 'shtest-format.shtest-format' name='unsupported-expr-false.txt' time='{{[0-9]+\.[0-9]+}}'/>
54 # CHECK: "shtest-format.shtest-format" name="unsupported-expr-false.txt" time="{{[0-9]+\.[0-9]+}}"/>
5555
56 # CHECK: 'shtest-format.shtest-format' name='unsupported-expr-true.txt' time='{{[0-9]+\.[0-9]+}}'>
56 # CHECK: "shtest-format.shtest-format" name="unsupported-expr-true.txt" time="{{[0-9]+\.[0-9]+}}">
5757 # CHECK-NEXT:
5858
59 # CHECK: 'shtest-format.shtest-format' name='unsupported-star.txt' time='{{[0-9]+\.[0-9]+}}'>
59 # CHECK: "shtest-format.shtest-format" name="unsupported-star.txt" time="{{[0-9]+\.[0-9]+}}">
6060 # CHECK-NEXT:
6161 # CHECK:
6262 # CHECK-NEXT:
6363
64 # CHECK: 'shtest-format.unsupported_dir' name='some-test.txt' time='{{[0-9]+\.[0-9]+}}'>
64 # CHECK: "shtest-format.unsupported_dir" name="some-test.txt" time="{{[0-9]+\.[0-9]+}}">
6565 # CHECK-NEXT:
6666
67 # CHECK: 'shtest-format.shtest-format' name='xfail-expr-false.txt' time='{{[0-9]+\.[0-9]+}}'/>
67 # CHECK: "shtest-format.shtest-format" name="xfail-expr-false.txt" time="{{[0-9]+\.[0-9]+}}"/>
6868
69 # CHECK: 'shtest-format.shtest-format' name='xfail-expr-true.txt' time='{{[0-9]+\.[0-9]+}}'/>
69 # CHECK: "shtest-format.shtest-format" name="xfail-expr-true.txt" time="{{[0-9]+\.[0-9]+}}"/>
7070
71 # CHECK: 'shtest-format.shtest-format' name='xfail-feature.txt' time='{{[0-9]+\.[0-9]+}}'/>
71 # CHECK: "shtest-format.shtest-format" name="xfail-feature.txt" time="{{[0-9]+\.[0-9]+}}"/>
7272
73 # CHECK: 'shtest-format.shtest-format' name='xfail-target.txt' time='{{[0-9]+\.[0-9]+}}'/>
73 # CHECK: "shtest-format.shtest-format" name="xfail-target.txt" time="{{[0-9]+\.[0-9]+}}"/>
7474
75 # CHECK: 'shtest-format.shtest-format' name='xfail.txt' time='{{[0-9]+\.[0-9]+}}'/>
75 # CHECK: "shtest-format.shtest-format" name="xfail.txt" time="{{[0-9]+\.[0-9]+}}"/>
7676
77 # CHECK: 'shtest-format.shtest-format' name='xpass.txt' time='{{[0-9]+\.[0-9]+}}'>
77 # CHECK: "shtest-format.shtest-format" name="xpass.txt" time="{{[0-9]+\.[0-9]+}}">
7878 # CHECK-NEXT:
7979 # CHECK:
8080 # CHECK-NEXT:
88
99 # CHECK:
1010 # CHECK:
11 # CHECK:
12 # CHECK: case classname='test-data.test-data' name='bad&name.ini' time='{{[0-1]}}.{{[0-9]+}}'>
11 # CHECK: suite name="test-data" tests="1" failures="1" skipped="0">
12 # CHECK:
1313 # CHECK-NEXT: ]]]]> &"]]>
1414 # CHECK:
1515 # CHECK: