From 7a8c3784f5d7428374523dc5f903cffe4f0f17d5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 1 Dec 2023 17:19:58 +0100 Subject: [PATCH 1/2] improve coverage python script --- coverage.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/coverage.py b/coverage.py index 8e1b845..73b81e9 100755 --- a/coverage.py +++ b/coverage.py @@ -7,16 +7,26 @@ import webbrowser _LOGGER = logging.getLogger() -def generate_cov_report(open_report: bool): + +def generate_cov_report(open_report: bool, format: str): logging.basicConfig(level=logging.INFO) os.environ["RUSTFLAGS"] = "-Cinstrument-coverage" os.environ["LLVM_PROFILE_FILE"] = "target/coverage/%p-%m.profraw" _LOGGER.info("Executing tests with coverage") os.system("cargo test") + + out_path = "./target/debug/coverage" + if format == "lcov": + out_path = "./target/debug/lcov.info" os.system( - "grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing " - "-o ./target/debug/coverage/" + f"grcov . -s . --binary-path ./target/debug/ -t {format} --branch --ignore-not-existing " + f"-o {out_path}" ) + if format == "lcov": + os.system( + "genhtml -o ./target/debug/coverage/ --show-details --highlight --ignore-errors source " + "--legend ./target/debug/lcov.info" + ) if open_report: coverage_report_path = os.path.abspath("./target/debug/coverage/index.html") webbrowser.open_new_tab(coverage_report_path) @@ -30,8 +40,14 @@ def main(): parser.add_argument( "--open", action="store_true", help="Open the coverage report in a browser" ) + parser.add_argument( + "--format", + choices=["html", "lcov"], + default="html", + help="Choose report format (html or lcov)", + ) args = parser.parse_args() - generate_cov_report(args.open) + generate_cov_report(args.open, args.format) if __name__ == "__main__": -- 2.43.0 From 60a00bae996ff0b42d1f4e1c74cbafb75ffeed7c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 1 Dec 2023 17:21:36 +0100 Subject: [PATCH 2/2] README update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d71ed81..72096bf 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ already, install the `llvm-tools-preview`: ```sh rustup component add llvm-tools-preview +cargo install grcov --locked ``` After that, you can simply run `coverage.py` to test the project with coverage. You can optionally -- 2.43.0