From 0b012631e5bac6695576a948f3750fc6ae08d239 Mon Sep 17 00:00:00 2001 From: ksew1 Date: Sun, 2 Mar 2025 23:13:21 +0100 Subject: [PATCH 1/2] Categorize to stable and unstable commit-id:cc497b8f --- CHANGELOG.md | 1 + README.md | 13 +++++++++++++ crates/cairo-coverage/src/args/run.rs | 8 ++++++-- crates/cairo-coverage/src/commands/run.rs | 1 + crates/cairo-coverage/tests/e2e/general.rs | 6 +++--- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b1846d..d92cb17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Added - warning if the current scarb version doesn't support not including macros in the coverage report +- `--unstable` flag to enable unstable features. Read more about it [here](./README.md#coverage-across-different-scarb-versions) #### Changed - macros are now by default included in the coverage report. If you want to exclude them, use the `--include` without the diff --git a/README.md b/README.md index a28b771..7ac930c 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,19 @@ Using the `--help` flag with any command will display additional information abo cairo-coverage clean --help ``` +### Coverage Across Different Scarb Versions + +`cairo-coverage` relies heavily on `scarb` and the internal workings of the `cairo` compiler, which can lead to variations in behavior depending on the `scarb` version used. + +To ensure consistency in coverage reports across different versions of `scarb`, we have categorized features into **stable** and **unstable**: + +- **Stable features** provide consistent results across all versions of `scarb`. +- **Unstable features** may produce different results depending on the `scarb` version. + +A feature is considered **stable** if it produces the same results across all minor versions of `scarb` from `2.8.*` onward, using the latest patch version. + +To enable unstable features, use the `--unstable` flag. + ### `.cairo-coverage-ignore` File You can create a `.cairo-coverage-ignore` file in the root of your project to specify the files or directories that you diff --git a/crates/cairo-coverage/src/args/run.rs b/crates/cairo-coverage/src/args/run.rs index 30dfac1..b175aa5 100644 --- a/crates/cairo-coverage/src/args/run.rs +++ b/crates/cairo-coverage/src/args/run.rs @@ -14,13 +14,17 @@ pub struct RunArgs { pub output_path: Utf8PathBuf, /// Include additional components in the coverage report. - #[arg(long, short, num_args = 0.., default_value = "macros")] + #[arg(long, short, num_args = 0.., default_value = "macros", requires = "unstable")] pub include: Vec, /// If set, the hit count of the lines will not be truncated to 1. - #[arg(long)] + #[arg(long, requires = "unstable")] pub no_truncation: bool, + /// If set, the unstable features are enabled. + #[arg(long)] + pub unstable: bool, + /// Path to the project directory. If not provided, the project directory is inferred using `scarb metadata`. #[arg(value_parser = parse_project_path, long)] pub project_path: Option, diff --git a/crates/cairo-coverage/src/commands/run.rs b/crates/cairo-coverage/src/commands/run.rs index f1ec96c..6de0ebc 100644 --- a/crates/cairo-coverage/src/commands/run.rs +++ b/crates/cairo-coverage/src/commands/run.rs @@ -15,6 +15,7 @@ pub fn run( output_path, trace_files, no_truncation, + unstable: _, }: RunArgs, ) -> Result<()> { let metadata = scarb_metadata()?; diff --git a/crates/cairo-coverage/tests/e2e/general.rs b/crates/cairo-coverage/tests/e2e/general.rs index 0d7753a..9c162e3 100644 --- a/crates/cairo-coverage/tests/e2e/general.rs +++ b/crates/cairo-coverage/tests/e2e/general.rs @@ -12,7 +12,7 @@ fn simple() { #[cfg(feature = "allows-excluding-macros")] fn simple_with_tests() { TestProject::new("simple") - .coverage_args(&["--include", "test-functions"]) + .coverage_args(&["--unstable", "--include", "test-functions"]) .run() .output_same_as_in_file("simple_with_tests.lcov"); } @@ -63,7 +63,7 @@ fn macros() { #[cfg(feature = "allows-excluding-macros")] fn macros_not_included() { TestProject::new("macros") - .coverage_args(&["--include"]) + .coverage_args(&["--unstable", "--include"]) .run_without_genhtml() .assert_empty_output(); } @@ -79,7 +79,7 @@ fn snforge_template() { #[cfg(feature = "allows-excluding-macros")] fn snforge_template_macros_not_included() { TestProject::new("snforge_template") - .coverage_args(&["--include"]) + .coverage_args(&["--unstable", "--include"]) .run() .output_same_as_in_file("snforge_template_macros_not_included.lcov"); } From c89a22899b4ee92be02830e5c562a757b8c27544 Mon Sep 17 00:00:00 2001 From: ksew1 Date: Wed, 5 Mar 2025 12:56:10 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d92cb17..2ab6920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,13 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] #### Added + - warning if the current scarb version doesn't support not including macros in the coverage report -- `--unstable` flag to enable unstable features. Read more about it [here](./README.md#coverage-across-different-scarb-versions) +- `--unstable` flag to enable unstable features. Read more about + it [here](./README.md#coverage-across-different-scarb-versions) #### Changed -- macros are now by default included in the coverage report. If you want to exclude them, use the `--include` without the - `macros` option (can also have empty value) -- by default, the hit count of the lines will be truncated to 1. This can be changed with the `--no-truncation` flag + +- macros are now by default included in the coverage report. If you want to exclude them, use the `--include` without + the `macros` option (can also have empty value). This is due to a new stability policy. Read more about + it [here](./README.md#coverage-across-different-scarb-versions) +- by default, the hit count of the lines will be truncated to 1. This can be changed with the `--no-truncation` flag. + This is due to a new stability policy. Read more about it [here](./README.md#coverage-across-different-scarb-versions) ## [0.4.0] - 2025-01-03