Skip to content

Commit 59e06a7

Browse files
authored
Run tests for different scarb versions (#165)
**Stack**: - #168 - #167 - #166 - #165 ⬅ - #164 - #163 - #160 - #159 - #158 ⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do not merge manually using the UI - doing so may have unexpected results.*
1 parent 27e62a6 commit 59e06a7

File tree

17 files changed

+55
-17
lines changed

17 files changed

+55
-17
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
- main
88

99
jobs:
10-
tests:
11-
name: Tests
10+
test-disabling-macros:
11+
name: Tests (2.8.5) - support for disabling macros
1212
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
@@ -20,6 +20,23 @@ jobs:
2020
- uses: hrishikesh-kadam/setup-lcov@6c1aa0cc9e1c02f9f58f01ac599f1064ccc83470 # v1.1.0
2121
- uses: software-mansion/setup-scarb@22f50f68eb6ffacfc173786dab19aa7d49b43441 # v1.5.0
2222
- uses: foundry-rs/setup-snfoundry@ee00ea3f026379008ca40a54448d4059233d06cc # v4.0.0
23+
- run: cargo test --release --features allows-excluding-macros
24+
25+
test:
26+
name: Tests
27+
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
version: [2.9.1, 2.10.1]
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: dtolnay/rust-toolchain@stable
34+
- uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
35+
- uses: hrishikesh-kadam/setup-lcov@6c1aa0cc9e1c02f9f58f01ac599f1064ccc83470 # v1.1.0
36+
- uses: software-mansion/setup-scarb@22f50f68eb6ffacfc173786dab19aa7d49b43441 # v1.5.0
37+
with:
38+
scarb-version: ${{ matrix.version }}
39+
- uses: foundry-rs/setup-snfoundry@ee00ea3f026379008ca40a54448d4059233d06cc # v4.0.0
2340
- run: cargo test --release
2441

2542
rustfmt:

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
starknet-foundry 0.37.0
1+
starknet-foundry 0.38.0
22
scarb 2.8.5

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
#### Added
11+
- warning if the current scarb version doesn't support not including macros in the coverage report
12+
1013
#### Changed
1114
- macros are now by default included in the coverage report. If you want to exclude them, use the `--include` without the
1215
`macros` option (can also have empty value)

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ serde = "1.0.218"
2828
serde_json = "1.0.139"
2929
scarb-metadata = "1.13.0"
3030
snapbox = "0.6.21"
31+
semver = "1.0.25"
3132
indoc = "2.0.5"
3233
regex = "1.11.1"
3334
rayon = "1.10.0"

crates/cairo-coverage-core/src/build/statement_information.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ impl IntoIterator for &LineRange {
5959
type IntoIter = iter::Map<RangeInclusive<usize>, fn(usize) -> LineNumber>;
6060

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

crates/cairo-coverage/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ console.workspace = true
99
camino.workspace = true
1010
anyhow.workspace = true
1111
scarb-metadata.workspace = true
12+
semver.workspace = true
1213
clap.workspace = true
1314
walkdir.workspace = true
1415

@@ -18,3 +19,6 @@ cairo-coverage-test-utils = { path = "../cairo-coverage-test-utils" }
1819
assert_fs.workspace = true
1920
snapbox.workspace = true
2021
which.workspace = true
22+
23+
[features]
24+
allows-excluding-macros = []

crates/cairo-coverage/src/commands/run.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::args::run::{IncludedComponent, RunArgs};
2-
use anyhow::{Context, Result};
2+
use anyhow::{Context, Result, ensure};
33
use cairo_coverage_core::args::{IncludedComponent as CoreIncludedComponent, RunOptions};
44
use scarb_metadata::{Metadata, MetadataCommand};
5+
use semver::Version;
56
use std::fs::OpenOptions;
67
use std::io::Write;
78

@@ -16,11 +17,16 @@ pub fn run(
1617
no_truncation,
1718
}: RunArgs,
1819
) -> Result<()> {
19-
let project_path = if let Some(project_path) = project_path {
20-
project_path
21-
} else {
22-
scarb_metadata()?.workspace.root
23-
};
20+
let metadata = scarb_metadata()?;
21+
22+
if !include.contains(&IncludedComponent::Macros) {
23+
ensure!(
24+
metadata.app_version_info.version <= Version::new(2, 8, 5),
25+
"excluding macros is only supported for Scarb versions <= 2.8.5"
26+
);
27+
}
28+
29+
let project_path = project_path.unwrap_or(metadata.workspace.root);
2430

2531
let options = RunOptions {
2632
include: include.into_iter().map(Into::into).collect(),

crates/cairo-coverage/tests/data/complex_calculator/Scarb.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2024_07"
77
starknet = ">=2.8.0"
88

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

1212
[profile.dev.cairo]
1313
unstable-add-statements-functions-debug-info = true

crates/cairo-coverage/tests/data/coverage_ignore/Scarb.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2024_07"
77
starknet = ">=2.8.0"
88

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

1212
[profile.dev.cairo]
1313
unstable-add-statements-functions-debug-info = true

0 commit comments

Comments
 (0)