Skip to content

Commit 64df8c4

Browse files
ksew1franciszekjob
andauthored
Allow comments in coverage validation (#2884)
<!-- Reference any GitHub issues resolved by this PR --> ## Introduced changes There was an issue where, when validating `Scarb.toml` and calling `.to_string()`, comments were included in the resulting string, causing validation to fail. This PR resolves the issue. ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md` --------- Co-authored-by: Franciszek Job <[email protected]>
1 parent ebde2bb commit 64df8c4

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Forge
11+
12+
#### Fixed
13+
14+
- coverage validation now supports comments in `Scarb.toml`
15+
1016
## [0.36.0] - 2025-01-15
1117

1218
### Forge

crates/forge-runner/src/coverage_api.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const MINIMAL_SCARB_VERSION: Version = Version::new(2, 8, 0);
1717
const CAIRO_COVERAGE_REQUIRED_ENTRIES: [(&str, &str); 3] = [
1818
("unstable-add-statements-functions-debug-info", "true"),
1919
("unstable-add-statements-code-locations-debug-info", "true"),
20-
("inlining-strategy", "\"avoid\""),
20+
("inlining-strategy", "avoid"),
2121
];
2222

2323
pub fn run_coverage(saved_trace_data_paths: &[PathBuf], coverage_args: &[OsString]) -> Result<()> {
@@ -104,8 +104,16 @@ pub fn can_coverage_be_generated(scarb_metadata: &Metadata) -> Result<()> {
104104
Ok(())
105105
}
106106

107+
/// Check if the table contains an entry with the given key and value.
108+
/// Accepts only bool and string values.
107109
fn contains_entry_with_value(table: &Table, key: &str, value: &str) -> bool {
108-
table
109-
.get(key)
110-
.is_some_and(|entry| entry.to_string().trim() == value)
110+
table.get(key).is_some_and(|entry| {
111+
if let Some(entry) = entry.as_bool() {
112+
entry.to_string() == value
113+
} else if let Some(entry) = entry.as_str() {
114+
entry == value
115+
} else {
116+
false
117+
}
118+
})
111119
}

crates/forge/tests/data/coverage_project/Scarb.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ snforge_std = { path = "../../../../../snforge_std" }
1515
sierra = true
1616

1717
[profile.dev.cairo]
18-
unstable-add-statements-functions-debug-info = true
18+
unstable-add-statements-functions-debug-info = true # Comment
1919
unstable-add-statements-code-locations-debug-info = true
20-
inlining-strategy= "avoid"
20+
inlining-strategy= "avoid" # Comment

0 commit comments

Comments
 (0)