spacepackets/coverage.py

39 lines
1.1 KiB
Python
Raw Normal View History

2023-12-01 10:22:44 +01:00
#!/usr/bin/env python3
import os
2023-12-01 16:00:29 +01:00
import logging
2023-12-01 10:22:44 +01:00
import argparse
import webbrowser
2023-12-01 16:00:29 +01:00
_LOGGER = logging.getLogger()
2023-12-01 10:22:44 +01:00
def generate_cov_report(open_report: bool):
2023-12-01 16:00:29 +01:00
logging.basicConfig(level=logging.INFO)
2023-12-01 10:22:44 +01:00
os.environ["RUSTFLAGS"] = "-Cinstrument-coverage"
os.environ["LLVM_PROFILE_FILE"] = "target/coverage/%p-%m.profraw"
2023-12-01 16:00:29 +01:00
_LOGGER.info("Executing tests with coverage")
2023-12-01 10:22:44 +01:00
os.system("cargo test")
os.system(
"grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing "
"-o ./target/debug/coverage/"
)
if open_report:
coverage_report_path = os.path.abspath("./target/debug/coverage/index.html")
webbrowser.open_new_tab(coverage_report_path)
2023-12-01 16:00:29 +01:00
_LOGGER.info("Done")
2023-12-01 10:22:44 +01:00
def main():
2023-12-01 15:35:09 +01:00
parser = argparse.ArgumentParser(
description="Generate coverage report and optionally open it in a browser"
)
parser.add_argument(
"--open", action="store_true", help="Open the coverage report in a browser"
)
2023-12-01 10:22:44 +01:00
args = parser.parse_args()
generate_cov_report(args.open)
if __name__ == "__main__":
main()