From 6d61da55ee4635c51a65fbbc7d508fdd17cc5e5c Mon Sep 17 00:00:00 2001 From: saba Date: Fri, 20 Jun 2025 10:56:41 +0200 Subject: [PATCH] Allow multiple input files for coverage report generation Updated CLI to accept zero or more input log files instead of one. Added logic to merge results from multiple files, with deduplication of test names. Default behavior falls back to reading from stdin if no files are provided. --- .../_core/cli/arg/handlers/report/coverage.py | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/testflows/_core/cli/arg/handlers/report/coverage.py b/testflows/_core/cli/arg/handlers/report/coverage.py index 8906f03..ea9d84a 100644 --- a/testflows/_core/cli/arg/handlers/report/coverage.py +++ b/testflows/_core/cli/arg/handlers/report/coverage.py @@ -265,9 +265,9 @@ def add_command(cls, commands): "input", metavar="input", type=argtype.logfile("r", bufsize=1, encoding="utf-8"), - nargs="?", - help="input log, default: stdin", - default="-", + nargs="*", # Change from "+" to "*" to accept zero or more files + help="input log files, default: stdin if no files provided", + default=None, # Don't set a default here ) parser.add_argument( "output", @@ -508,8 +508,34 @@ def generate(self, formatter, results, args): output.write(formatter.format(self.data(args.requirements, results, args))) output.write("\n") + def merge(self, results, new_results): + if not results.get("tests"): + results.update(new_results) + return + + # Merge tests with deduplication + for test_name, test_data in new_results["tests"].items(): + unique_name = test_name + counter = 1 + while unique_name in results["tests"]: + unique_name = f"{test_name} ~{counter}" + counter += 1 + results["tests"][unique_name] = test_data + + results["tests_by_id"].update(new_results["tests_by_id"]) + results["tests_by_parent"].update(new_results["tests_by_parent"]) + def handle(self, args): results = {} formatter = Formatter() - ResultsLogPipeline(args.input, results).run() + + if not args.input: # If no input files are provided, read from stdin + args.input = [argtype.logfile("r", bufsize=1, encoding="utf-8")("-")] + + for input_file in args.input: + new_results = {} + ResultsLogPipeline(input_file, new_results).run() + self.merge(results, new_results) + self.generate(formatter, results, args) +