Skip to content

coverage: make crate_features key optional #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ The json must have the following fields:
if multiple files are to be skipped, they must be separated with `|`).
It should be used to exclude autogenerated files. If the repository does not
have any autogenerated files, `exclude_path` should be an empty string.
- `crate_features`: `cargo kcov` does not build crate features by default. To
get the coverage report including optional features, these need to be
specified in `crate_features` separated by comma. If the crate does not have
any features, this field should be empty.

Additionally, the following optional fields are available:

- `crate_features`: By default, we pass `--all-features` to cargo when collecting
coverage. To have the coverage report only include a subset of features (in addition
to default features, which are always enabled), specify them in this field
as a comma-separated string.

This file is required for the coverage integration so it needs to be added
to the repository as well.
Expand Down
12 changes: 7 additions & 5 deletions integration_tests/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def _read_test_config():

assert "coverage_score" in coverage_config
assert "exclude_path" in coverage_config
assert "crate_features" in coverage_config

assert (
" " not in coverage_config["crate_features"]
), "spaces are not allowed in crate_features value"
if "crate_features" in coverage_config:
assert (
" " not in coverage_config["crate_features"]
), "spaces are not allowed in crate_features value"

return coverage_config

Expand Down Expand Up @@ -87,9 +87,11 @@ def _get_current_coverage(coverage_config, no_cleanup, test_scope):
if test_scope == pytest.workspace:
llvm_cov_command += " --workspace "

crate_features = coverage_config["crate_features"]
crate_features = coverage_config.get("crate_features")
if crate_features:
llvm_cov_command += " --features=" + crate_features
if crate_features is None:
llvm_cov_command += " --all-features"

# Pytest closes stdin by default, but some tests might need it to be open.
# In the future, should the need arise, we can feed custom data to stdin.
Expand Down