-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Reference any GitHub issues resolved by this PR --> Closes software-mansion/cairo-coverage#5 ## Introduced changes <!-- A brief description of the changes --> - Added a flag `--coverage` to `test` command that creates coverage report of all non-fuzz tests that passed, using the `cairo-coverage` binary ## 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 - [ ] Added changes to `CHANGELOG.md` --------- Co-authored-by: Karol Sewiło <[email protected]> Co-authored-by: Arcticae <[email protected]> Co-authored-by: Karol Sewilo <[email protected]> Co-authored-by: Tomasz Rejowski <[email protected]>
- Loading branch information
1 parent
02aa76a
commit 84cb598
Showing
20 changed files
with
207 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use anyhow::{Context, Result}; | ||
use shared::command::CommandExt; | ||
use std::process::Stdio; | ||
use std::{env, fs, path::PathBuf, process::Command}; | ||
|
||
pub const COVERAGE_DIR: &str = "coverage"; | ||
pub const OUTPUT_FILE_NAME: &str = "coverage.lcov"; | ||
|
||
pub fn run_coverage(saved_trace_data_paths: &[PathBuf]) -> Result<()> { | ||
let coverage = env::var("CAIRO_COVERAGE") | ||
.map(PathBuf::from) | ||
.ok() | ||
.unwrap_or_else(|| PathBuf::from("cairo-coverage")); | ||
|
||
let dir_to_save_coverage = PathBuf::from(COVERAGE_DIR); | ||
fs::create_dir_all(&dir_to_save_coverage).context("Failed to create a coverage dir")?; | ||
let path_to_save_coverage = dir_to_save_coverage.join(OUTPUT_FILE_NAME); | ||
|
||
let trace_files: Vec<&str> = saved_trace_data_paths | ||
.iter() | ||
.map(|trace_data_path| { | ||
trace_data_path | ||
.to_str() | ||
.expect("Failed to convert trace data path to string") | ||
}) | ||
.collect(); | ||
|
||
Command::new(coverage) | ||
.arg("--output-path") | ||
.arg(&path_to_save_coverage) | ||
.args(trace_files) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.output_checked() | ||
.with_context(|| { | ||
"cairo-coverage failed to generate coverage - inspect the errors above for more info" | ||
})?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "coverage_project" | ||
version = "0.1.0" | ||
|
||
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html | ||
|
||
[dependencies] | ||
starknet = "2.4.0" | ||
|
||
[dev-dependencies] | ||
snforge_std = { path = "../../../../../snforge_std" } | ||
|
||
[[target.starknet-contract]] | ||
sierra = true | ||
|
||
[cairo] | ||
unstable-add-statements-functions-debug-info = true | ||
unstable-add-statements-code-locations-debug-info = true | ||
inlining-strategy= "avoid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub fn increase_by_two(arg: u8) -> u8 { | ||
assert(2 == 2, ''); | ||
increase_by_one(arg + 1) | ||
} | ||
|
||
pub fn increase_by_one(arg: u8) -> u8 { | ||
assert(1 == 1, ''); | ||
arg + 1 | ||
} |
Oops, something went wrong.