Skip to content
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
21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- main

jobs:
tests:
name: Tests
test-disabling-macros:
name: Tests (2.8.5) - support for disabling macros
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -20,6 +20,23 @@ jobs:
- uses: hrishikesh-kadam/setup-lcov@6c1aa0cc9e1c02f9f58f01ac599f1064ccc83470 # v1.1.0
- uses: software-mansion/setup-scarb@22f50f68eb6ffacfc173786dab19aa7d49b43441 # v1.5.0
- uses: foundry-rs/setup-snfoundry@ee00ea3f026379008ca40a54448d4059233d06cc # v4.0.0
- run: cargo test --release --features allows-excluding-macros

test:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
version: [2.9.1, 2.10.1]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
- uses: hrishikesh-kadam/setup-lcov@6c1aa0cc9e1c02f9f58f01ac599f1064ccc83470 # v1.1.0
- uses: software-mansion/setup-scarb@22f50f68eb6ffacfc173786dab19aa7d49b43441 # v1.5.0
with:
scarb-version: ${{ matrix.version }}
- uses: foundry-rs/setup-snfoundry@ee00ea3f026379008ca40a54448d4059233d06cc # v4.0.0
- run: cargo test --release

rustfmt:
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
starknet-foundry 0.37.0
starknet-foundry 0.38.0
scarb 2.8.5
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ 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

#### 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)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ serde = "1.0.218"
serde_json = "1.0.139"
scarb-metadata = "1.13.0"
snapbox = "0.6.21"
semver = "1.0.25"
indoc = "2.0.5"
regex = "1.11.1"
rayon = "1.10.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl IntoIterator for &LineRange {
type IntoIter = iter::Map<RangeInclusive<usize>, fn(usize) -> LineNumber>;

fn into_iter(self) -> Self::IntoIter {
(self.start.0..=self.end.0).map(LineNumber)
// FIXME: Use the whole range instead of the start once we drop support for scarb 2.8.*
(self.start.0..=self.start.0).map(LineNumber)
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/cairo-coverage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ console.workspace = true
camino.workspace = true
anyhow.workspace = true
scarb-metadata.workspace = true
semver.workspace = true
clap.workspace = true
walkdir.workspace = true

Expand All @@ -18,3 +19,6 @@ cairo-coverage-test-utils = { path = "../cairo-coverage-test-utils" }
assert_fs.workspace = true
snapbox.workspace = true
which.workspace = true

[features]
allows-excluding-macros = []
18 changes: 12 additions & 6 deletions crates/cairo-coverage/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::args::run::{IncludedComponent, RunArgs};
use anyhow::{Context, Result};
use anyhow::{Context, Result, ensure};
use cairo_coverage_core::args::{IncludedComponent as CoreIncludedComponent, RunOptions};
use scarb_metadata::{Metadata, MetadataCommand};
use semver::Version;
use std::fs::OpenOptions;
use std::io::Write;

Expand All @@ -16,11 +17,16 @@ pub fn run(
no_truncation,
}: RunArgs,
) -> Result<()> {
let project_path = if let Some(project_path) = project_path {
project_path
} else {
scarb_metadata()?.workspace.root
};
let metadata = scarb_metadata()?;

if !include.contains(&IncludedComponent::Macros) {
ensure!(
metadata.app_version_info.version <= Version::new(2, 8, 5),
"excluding macros is only supported for Scarb versions <= 2.8.5"
);
}

let project_path = project_path.unwrap_or(metadata.workspace.root);

let options = RunOptions {
include: include.into_iter().map(Into::into).collect(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024_07"
starknet = ">=2.8.0"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.37.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.38.0" }

[profile.dev.cairo]
unstable-add-statements-functions-debug-info = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024_07"
starknet = ">=2.8.0"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.37.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.38.0" }

[profile.dev.cairo]
unstable-add-statements-functions-debug-info = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-coverage/tests/data/macros/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024_07"
starknet = ">=2.8.0"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.37.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.38.0" }

[profile.dev.cairo]
unstable-add-statements-functions-debug-info = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024_07"
starknet = ">=2.8.0"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.37.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.38.0" }

[profile.dev.cairo]
unstable-add-statements-functions-debug-info = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024_07"
starknet = ">=2.8.0"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.37.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.38.0" }

[profile.dev.cairo]
unstable-add-statements-functions-debug-info = true
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-coverage/tests/data/simple/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2024_07"
starknet = ">=2.8.0"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.37.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.38.0" }

[profile.dev.cairo]
unstable-add-statements-functions-debug-info = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2023_11"
starknet = ">=2.8.0"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.37.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.38.0" }

[[target.starknet-contract]]
sierra = true
Expand Down
3 changes: 3 additions & 0 deletions crates/cairo-coverage/tests/e2e/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn simple() {
}

#[test]
#[cfg(feature = "allows-excluding-macros")]
fn simple_with_tests() {
TestProject::new("simple")
.coverage_args(&["--include", "test-functions"])
Expand Down Expand Up @@ -59,6 +60,7 @@ fn macros() {
}

#[test]
#[cfg(feature = "allows-excluding-macros")]
fn macros_not_included() {
TestProject::new("macros")
.coverage_args(&["--include"])
Expand All @@ -74,6 +76,7 @@ fn snforge_template() {
}

#[test]
#[cfg(feature = "allows-excluding-macros")]
fn snforge_template_macros_not_included() {
TestProject::new("snforge_template")
.coverage_args(&["--include"])
Expand Down
2 changes: 2 additions & 0 deletions crates/cairo-coverage/tests/helpers/test_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl TestProject {
.output()
}

#[cfg(feature = "allows-excluding-macros")]
pub fn run_without_genhtml(self) -> TestProjectOutput {
self.generate_trace_files().run_coverage().output()
}
Expand Down Expand Up @@ -130,6 +131,7 @@ impl TestProjectOutput {
assert_eq!(content, expected);
}

#[cfg(feature = "allows-excluding-macros")]
pub fn assert_empty_output(self) {
assert!(self.read_output().is_empty());
}
Expand Down
Loading