coverage: make crate_features key optional

Currently, if a crate wishes to run the coverage test with some cargo
features enabled, it must explicitly list them out in the
`crate_features` key of the coverage json files.

Change this so that if this key is omitted from the json file, then
test_coverage.py passes `--all-features` to cargo.

No functional change, as currently `crate_features` is a mandatory key,
so to opt-in to this new behavior, crates must remove this key from
their coverage json file(s).

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
This commit is contained in:
Patrick Roy
2025-03-17 10:52:21 +00:00
parent 8ae03e5c36
commit e94bff4ff5

View File

@@ -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
@@ -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.