Index: utils/lit/lit/Test.py
===================================================================
--- utils/lit/lit/Test.py
+++ utils/lit/lit/Test.py
@@ -1,4 +1,5 @@
import os
+from xml.sax.saxutils import escape
# Test result codes.
@@ -194,3 +195,14 @@
return True
return False
+
+ def getJUnitXML(self):
+ xml = "\n\t\n" + escape(self.result.output)
+ xml += "\n\t\n"
+ else:
+ xml += "/>"
+ return xml
+
Index: utils/lit/lit/main.py
===================================================================
--- utils/lit/lit/main.py
+++ utils/lit/lit/main.py
@@ -236,6 +236,9 @@
group.add_option("", "--use-threads", dest="useProcesses",
help="Run tests in parallel with threads (not processes)",
action="store_false", default=useProcessesIsDefault)
+ group.add_option("", "--junit-xml-output", dest="xmlFile",
+ help=("Write JUnit-compatible XML test reports to the"
+ " specified file"), default=None)
parser.add_option_group(group)
(opts, args) = parser.parse_args()
@@ -418,6 +421,35 @@
N = len(byCode.get(code,[]))
if N:
print(' %s: %d' % (name,N))
+ if opts.xmlFile:
+ # Collect the tests, indexed by test suite
+ bySuite = {}
+ for t in run.tests:
+ suite = t.suite.config.name
+ if suite not in bySuite:
+ bySuite[suite] = {
+ 'passes' : 0,
+ 'failures' : 0,
+ 'tests' : [] }
+ bySuite[suite]['tests'].append(t)
+ if t.result.code.isFailure:
+ bySuite[suite]['failures'] += 1
+ else:
+ bySuite[suite]['passes'] += 1
+ xmlFile = open(opts.xmlFile, "w")
+ xmlFile.write("\n")
+ xmlFile.write("\n")
+ for suiteName in bySuite:
+ s = bySuite[suiteName]
+ xmlFile.write("\n")
+ for t in s['tests']:
+ xmlFile.write(t.getJUnitXML() + "\n")
+ xmlFile.write("\n")
+ xmlFile.write("")
+ xmlFile.close()
+
# If we encountered any additional errors, exit abnormally.
if litConfig.numErrors: