[lit] Create report generators during argument parsing
authorJulian Lettner <julian.lettner@apple.com>
Fri, 1 May 2020 22:52:44 +0000 (15:52 -0700)
committerJulian Lettner <julian.lettner@apple.com>
Sat, 2 May 2020 00:03:55 +0000 (17:03 -0700)
llvm/utils/lit/lit/cl_arguments.py
llvm/utils/lit/lit/main.py

index 4e185de..e03e4c2 100644 (file)
@@ -3,6 +3,7 @@ import os
 import shlex
 import sys
 
+import lit.reports
 import lit.util
 
 
@@ -57,7 +58,10 @@ def parse_args():
             help="Display all commandlines and output",
             action="store_true")
     format_group.add_argument("-o", "--output",
-            dest="output_path",
+            dest="reports",
+            action="append",
+            type=lit.reports.JsonReport,
+            default=[],
             help="Write test results to the provided path",
             metavar="PATH")
     format_group.add_argument("--no-progress-bar",
@@ -98,7 +102,10 @@ def parse_args():
             help="Don't execute any tests (assume PASS)",
             action="store_true")
     execution_group.add_argument("--xunit-xml-output",
-            dest="xunit_output_file",
+            dest="reports",
+            action="append",
+            type=lit.reports.XunitReport,
+            default=[],
             help="Write XUnit-compatible XML test reports to the specified file")
     execution_group.add_argument("--timeout",
             dest="maxIndividualTestTime",
index d155b0d..c6f798d 100755 (executable)
@@ -98,11 +98,8 @@ def main(builtin_params={}):
 
     print_results(discovered_tests, elapsed, opts)
 
-    if opts.output_path:
-        #TODO(yln): pass in discovered_tests
-        write_test_results(executed_tests, lit_config, elapsed, opts.output_path)
-    if opts.xunit_output_file:
-        write_test_results_xunit(executed_tests, opts)
+    for report in opts.reports:
+        report.write_results(executed_tests, elapsed)
 
     if lit_config.numErrors:
         sys.stderr.write('\n%d error(s) in tests\n' % lit_config.numErrors)
@@ -330,16 +327,3 @@ def print_summary(tests_by_code, quiet, elapsed):
         label = label.ljust(max_label_len)
         count = str(count).rjust(max_count_len)
         print('  %s: %s' % (label, count))
-
-
-def write_test_results(tests, lit_config, elapsed, output_path):
-    import lit.reports
-    r = lit.reports.JsonReport(output_path)
-    r.write_results(tests, elapsed)
-
-
-def write_test_results_xunit(tests, opts):
-    import lit.reports
-    r = lit.reports.XunitReport(opts.xunit_output_file)
-    r.write_results(tests, 0.0)
-