diff --git a/.gitignore b/.gitignore index a74e7b4f..247fff7b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,9 @@ devenv.local.nix # direnv .direnv -.pre-commit-config.yaml \ No newline at end of file +.pre-commit-config.yaml + +# Coverage reports +.coverage +coverage.xml +lcov.info diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index fa652e55..3453c3b1 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -95,6 +95,24 @@ We also check for clippy warnings, which are a set of linting rules for rust. To cargo clippy --all-targets ``` +## 📈 Code Coverage + +We run coverage checks on the CI. Once you submit a PR, you can review the +line-by-line coverage report on +[codecov](https://app.codecov.io/gh/CQCL/tket2/commits?branch=All%20branches). + +To run the rust coverage checks locally, install `cargo-llvm-cov`, generate the report with: +```bash +cargo llvm-cov --lcov > lcov.info +``` +and open it with your favourite coverage viewer. In VSCode, you can use +[`coverage-gutters`](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters). + +Similarly, to run the python coverage checks locally, install `pytest-cov` and run: +```bash +pytest --cov=./ --cov-report=xml +``` + ## 🌐 Contributing to tket2 We welcome contributions to tket2! Please open [an issue](https://github.com/CQCL/tket2/issues/new) or [pull request](https://github.com/CQCL/tket2/compare) if you have any questions or suggestions. diff --git a/justfile b/justfile index a190bde1..6d4df756 100644 --- a/justfile +++ b/justfile @@ -29,4 +29,12 @@ check: # Format the code format: cargo fmt - ruff format . \ No newline at end of file + ruff format . + +# Generate a test coverage report +coverage: + cargo llvm-cov --lcov > lcov.info + +# Generate a python test coverage report +pycoverage: pydevelop + pytest --cov=./ --cov-report=html \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 58b7864b..09ae849c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ python = ">=3.10" maturin = "^1.3.0" pytket = "*" pytest = "^7.1.2" +pytest-cov = "^4.1.0" ruff = "^0.1.3" [build-system]