diff --git a/utils/lit/lit/Test.py b/utils/lit/lit/Test.py index 38bb41b025..2354e4ee77 100644 --- a/utils/lit/lit/Test.py +++ b/utils/lit/lit/Test.py @@ -234,7 +234,7 @@ def isExpectedToFail(self): return False - def getJUnitXML(self): + def getJUnitXML(self, includeAllTestOutput=False): test_name = self.path_in_suite[-1] test_path = self.path_in_suite[:-1] safe_test_path = [x.replace(".","_") for x in test_path] @@ -252,5 +252,10 @@ def getJUnitXML(self): xml += ">\n\t\n" + escape(self.result.output) xml += "\n\t\n" else: - xml += "/>" + if includeAllTestOutput: + xml += ">" + xml += "\n\t\n" + escape(self.result.output) + xml += "\n\t\n" + else: + xml += "/>" return xml \ No newline at end of file diff --git a/utils/lit/lit/main.py b/utils/lit/lit/main.py index 1e66fb80d5..c46116b320 100755 --- a/utils/lit/lit/main.py +++ b/utils/lit/lit/main.py @@ -244,6 +244,9 @@ def main(builtinParameters = {}): group.add_option("", "--use-threads", dest="useProcesses", help="Run tests in parallel with threads (not processes)", action="store_false", default=useProcessesIsDefault) + group.add_option("", "--xml-include-test-output", dest="xmlIncludeTestOutput", + help="Include system out in xml output for all tests", + action="store_true", default=False) parser.add_option_group(group) (opts, args) = parser.parse_args() @@ -447,7 +450,7 @@ def main(builtinParameters = {}): by_suite[suite]['failures'] += 1 else: by_suite[suite]['passes'] += 1 - xunit_output_file = open(opts.xunit_output_file, "w") + xunit_output_file = open(opts.xunit_output_file, "w", encoding="utf-8", errors="xmlcharrefreplace") xunit_output_file.write("\n") xunit_output_file.write("\n") for suite_name, suite in by_suite.items(): @@ -458,7 +461,7 @@ def main(builtinParameters = {}): xunit_output_file.write(" failures='" + str(suite['failures']) + "'>\n") for result_test in suite['tests']: - xunit_output_file.write(result_test.getJUnitXML() + "\n") + xunit_output_file.write(result_test.getJUnitXML(opts.xmlIncludeTestOutput) + "\n") xunit_output_file.write("\n") xunit_output_file.write("") xunit_output_file.close() diff --git a/utils/lit/tests/Inputs/test-data/lit.cfg b/utils/lit/tests/Inputs/test-data/lit.cfg index f5aba7b217..8f47e28783 100644 --- a/utils/lit/tests/Inputs/test-data/lit.cfg +++ b/utils/lit/tests/Inputs/test-data/lit.cfg @@ -15,7 +15,7 @@ class DummyFormat(lit.formats.FileBasedTest): source_path = test.getSourcePath() cfg = ConfigParser.ConfigParser() - cfg.read(source_path) + cfg.read(source_path, encoding="utf-8") # Create the basic test result. result_code = cfg.get('global', 'result_code') diff --git a/utils/lit/tests/Inputs/test-data/utf8_output_message.ini b/utils/lit/tests/Inputs/test-data/utf8_output_message.ini new file mode 100644 index 0000000000..0d73675c0e --- /dev/null +++ b/utils/lit/tests/Inputs/test-data/utf8_output_message.ini @@ -0,0 +1,6 @@ +[global] +result_code = PASS +result_output = This test is 🔥 + +[results] +value0 = 1 diff --git a/utils/lit/tests/xunit-output.py b/utils/lit/tests/xunit-output.py index 3f49395363..0e1a7fb8b4 100644 --- a/utils/lit/tests/xunit-output.py +++ b/utils/lit/tests/xunit-output.py @@ -1,10 +1,18 @@ # Check xunit output -# RUN: %{lit} --xunit-xml-output %t.xunit.xml %{inputs}/test-data +# RUN: %{lit} --xunit-xml-output %t.xunit.xml --xml-include-test-output %{inputs}/test-data # RUN: FileCheck < %t.xunit.xml %s # CHECK: # CHECK: -# CHECK: -# CHECK: +# CHECK: +# CHECK: +# CHECK: +# CHECK: Test passed. +# CHECK: +# CHECK: +# CHECK: +# CHECK: This test is 🔥 +# CHECK: +# CHECK: # CHECK: # CHECK: