Small improvements #44

Merged
muellerr merged 2 commits from smaller-improvements into main 2023-12-01 18:33:46 +01:00
2 changed files with 21 additions and 4 deletions

View File

@ -56,6 +56,7 @@ already, install the `llvm-tools-preview`:
```sh ```sh
rustup component add llvm-tools-preview 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 After that, you can simply run `coverage.py` to test the project with coverage. You can optionally

View File

@ -7,15 +7,25 @@ import webbrowser
_LOGGER = logging.getLogger() _LOGGER = logging.getLogger()
def generate_cov_report(open_report: bool):
def generate_cov_report(open_report: bool, format: str):
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
os.environ["RUSTFLAGS"] = "-Cinstrument-coverage" os.environ["RUSTFLAGS"] = "-Cinstrument-coverage"
os.environ["LLVM_PROFILE_FILE"] = "target/coverage/%p-%m.profraw" os.environ["LLVM_PROFILE_FILE"] = "target/coverage/%p-%m.profraw"
_LOGGER.info("Executing tests with coverage") _LOGGER.info("Executing tests with coverage")
os.system("cargo test") os.system("cargo test")
out_path = "./target/debug/coverage"
if format == "lcov":
out_path = "./target/debug/lcov.info"
os.system( os.system(
"grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing " f"grcov . -s . --binary-path ./target/debug/ -t {format} --branch --ignore-not-existing "
"-o ./target/debug/coverage/" 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: if open_report:
coverage_report_path = os.path.abspath("./target/debug/coverage/index.html") coverage_report_path = os.path.abspath("./target/debug/coverage/index.html")
@ -30,8 +40,14 @@ def main():
parser.add_argument( parser.add_argument(
"--open", action="store_true", help="Open the coverage report in a browser" "--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() args = parser.parse_args()
generate_cov_report(args.open) generate_cov_report(args.open, args.format)
if __name__ == "__main__": if __name__ == "__main__":