Skip to content

Commit 17f4900

Browse files
Add --report-failures-only option for lit test reports
Co-authored-by: Greg Bedwell <[email protected]>
1 parent 37b4df4 commit 17f4900

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

llvm/utils/lit/lit/cl_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ def parse_args():
165165
type=lit.reports.XunitReport,
166166
help="Write XUnit-compatible XML test reports to the specified file",
167167
)
168+
execution_group.add_argument(
169+
"--report-failures-only",
170+
help="When writing a test report, do not include results for "
171+
"tests that completed successfully or were not run",
172+
action="store_true"
173+
)
168174
execution_group.add_argument(
169175
"--resultdb-output",
170176
type=lit.reports.ResultDBReport,

llvm/utils/lit/lit/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ def main(builtin_params={}):
137137
print_results(discovered_tests, elapsed, opts)
138138

139139
tests_for_report = selected_tests if opts.shard else discovered_tests
140+
if opts.report_failures_only:
141+
# Only report tests that failed
142+
tests_for_report = [t for t in tests_for_report if t.isFailure()]
143+
140144
for report in opts.reports:
141145
report.write_results(tests_for_report, elapsed)
142146

llvm/utils/lit/lit/reports.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def __init__(self, output_file):
2222
self.output_file = output_file
2323
# Set by the option parser later.
2424
self.use_unique_output_file_name = False
25+
self.skipped_codes = {lit.Test.EXCLUDED,
26+
lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
2527

2628
def write_results(self, tests, elapsed):
2729
if self.use_unique_output_file_name:
@@ -114,8 +116,6 @@ def remove_invalid_xml_chars(s):
114116

115117

116118
class XunitReport(Report):
117-
skipped_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
118-
119119
def _write_results_to_file(self, tests, elapsed, file):
120120
tests.sort(key=by_suite_and_test_path)
121121
tests_by_suite = itertools.groupby(tests, lambda t: t.suite)
@@ -273,8 +273,6 @@ def _write_results_to_file(self, tests, elapsed, file):
273273

274274

275275
class TimeTraceReport(Report):
276-
skipped_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
277-
278276
def _write_results_to_file(self, tests, elapsed, file):
279277
# Find when first test started so we can make start times relative.
280278
first_start_time = min([t.result.start for t in tests])
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# UNSUPPORTED: system-windows
2+
3+
# Check xunit output
4+
# RUN: rm -rf %t.xunit.xml
5+
# RUN: not %{lit} --report-failures-only --xunit-xml-output %t.xunit.xml %{inputs}/xunit-output
6+
# If xmllint is installed verify that the generated xml is well-formed
7+
# RUN: sh -c 'if command -v xmllint 2>/dev/null; then xmllint --noout %t.xunit.xml; fi'
8+
# RUN: FileCheck < %t.xunit.xml %s
9+
10+
# CHECK: <?xml version="1.0" encoding="UTF-8"?>
11+
# CHECK-NEXT: <testsuites time="{{[0-9.]+}}">
12+
# CHECK-NEXT: <testsuite name="test-data" tests="5" failures="1" skipped="3" time="{{[0-9.]+}}">
13+
# CHECK-NEXT: <testcase classname="test-data.test-data" name="bad&amp;name.ini" time="{{[0-1]\.[0-9]+}}">
14+
# CHECK-NEXT: <failure><![CDATA[& < > ]]]]><![CDATA[> &"]]></failure>
15+
# CHECK-NEXT: </testcase>
16+
# CHECK-NEXT: </testsuite>
17+
# CHECK-NEXT: </testsuites>

0 commit comments

Comments
 (0)