From b909634d57cf1b6a5f5eb2c6ce684d83ca46db80 Mon Sep 17 00:00:00 2001 From: ksew1 Date: Tue, 25 Feb 2025 17:40:11 +0100 Subject: [PATCH 1/4] Create coverage ui and use it in binary commit-id:437da9d3 --- Cargo.lock | 26 +++++++++++++++++ Cargo.toml | 10 ++++--- crates/cairo-coverage/Cargo.toml | 1 + crates/cairo-coverage/src/args/run.rs | 10 +++---- crates/cairo-coverage/src/commands/clean.rs | 10 ++++--- crates/cairo-coverage/src/commands/run.rs | 4 +-- crates/cairo-coverage/src/main.rs | 31 +++++++++++++++------ crates/cairo-coverage/src/ui.rs | 28 +++++++++++++++++++ 8 files changed, 97 insertions(+), 23 deletions(-) create mode 100644 crates/cairo-coverage/src/ui.rs diff --git a/Cargo.lock b/Cargo.lock index 2898374..06e704c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -225,6 +225,7 @@ dependencies = [ "cairo-coverage-test-utils", "camino", "clap", + "console", "snapbox", "walkdir", "which", @@ -507,6 +508,19 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "console" +version = "0.15.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "unicode-width", + "windows-sys", +] + [[package]] name = "const-fnv1a-hash" version = "1.1.0" @@ -724,6 +738,12 @@ dependencies = [ "log", ] +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + [[package]] name = "env_home" version = "0.1.0" @@ -1986,6 +2006,12 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +[[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + [[package]] name = "unicode-xid" version = "0.2.6" diff --git a/Cargo.toml b/Cargo.toml index a75eb7e..6b04242 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,15 +11,17 @@ version = "0.4.0" edition = "2024" [workspace.dependencies] +cairo-lang-sierra = "2.10.1" +cairo-lang-sierra-to-casm = "2.10.1" +cairo-lang-starknet-classes = "2.10.1" +cairo-annotations = "0.2.2" + anyhow = "1.0.96" assert_fs = "1.1.2" camino = "1.1.9" clap = { version = "4.5.30", features = ["derive"] } criterion = "0.5" -cairo-annotations = "0.2.2" -cairo-lang-sierra = "2.10.1" -cairo-lang-sierra-to-casm = "2.10.1" -cairo-lang-starknet-classes = "2.10.1" +console = "0.15.10" itertools = "0.14.0" ignore = "0.4.23" serde = "1.0.218" diff --git a/crates/cairo-coverage/Cargo.toml b/crates/cairo-coverage/Cargo.toml index fc5b454..ad8057b 100644 --- a/crates/cairo-coverage/Cargo.toml +++ b/crates/cairo-coverage/Cargo.toml @@ -5,6 +5,7 @@ edition.workspace = true [dependencies] cairo-coverage-core = { path = "../cairo-coverage-core" } +console.workspace = true camino.workspace = true anyhow.workspace = true clap.workspace = true diff --git a/crates/cairo-coverage/src/args/run.rs b/crates/cairo-coverage/src/args/run.rs index af3999c..fd01732 100644 --- a/crates/cairo-coverage/src/args/run.rs +++ b/crates/cairo-coverage/src/args/run.rs @@ -34,11 +34,11 @@ pub enum IncludedComponent { fn parse_trace_file(path: &str) -> Result { let trace_file = Utf8PathBuf::from(path); - ensure!(trace_file.exists(), "Trace file does not exist"); - ensure!(trace_file.is_file(), "Trace file is not a file"); + ensure!(trace_file.exists(), "trace file does not exist"); + ensure!(trace_file.is_file(), "trace file is not a file"); ensure!( matches!(trace_file.extension(), Some("json")), - "Trace file must have a JSON extension" + "trace file must have a JSON extension" ); Ok(trace_file) @@ -47,8 +47,8 @@ fn parse_trace_file(path: &str) -> Result { fn parse_project_path(path: &str) -> Result { let project_path = Utf8PathBuf::from(path); - ensure!(project_path.exists(), "Project path does not exist"); - ensure!(project_path.is_dir(), "Project path is not a directory"); + ensure!(project_path.exists(), "project path does not exist"); + ensure!(project_path.is_dir(), "project path is not a directory"); Ok(project_path) } diff --git a/crates/cairo-coverage/src/commands/clean.rs b/crates/cairo-coverage/src/commands/clean.rs index d8ea192..c65b2b4 100644 --- a/crates/cairo-coverage/src/commands/clean.rs +++ b/crates/cairo-coverage/src/commands/clean.rs @@ -1,4 +1,5 @@ use crate::args::clean::CleanArgs; +use crate::ui; use anyhow::{Context, Result}; use std::fs; use walkdir::WalkDir; @@ -13,7 +14,7 @@ pub fn run( ) -> Result<()> { let target_file_name = files_to_delete .file_name() - .context("Failed to obtain the file name from `files_to_delete`.")?; + .context("failed to obtain the file name from `--files-to-delete`")?; WalkDir::new(root_dir) .into_iter() @@ -24,16 +25,17 @@ pub fn run( if let Some(file_name) = path.file_name() { if file_name == target_file_name { - println!("Deleting file: {}", path.display()); + let path_display = path.display(); + ui::msg(format!("deleting file: {path_display}")); fs::remove_file(path) - .with_context(|| format!("Failed to delete file: {}", path.display()))?; + .with_context(|| format!("failed to delete file: {path_display}"))?; } } Ok(()) })?; - println!("Cleanup complete."); + ui::msg("cleanup complete"); Ok(()) } diff --git a/crates/cairo-coverage/src/commands/run.rs b/crates/cairo-coverage/src/commands/run.rs index 1246c34..34f0640 100644 --- a/crates/cairo-coverage/src/commands/run.rs +++ b/crates/cairo-coverage/src/commands/run.rs @@ -25,9 +25,9 @@ pub fn run( .append(true) .create(true) .open(&output_path) - .context(format!("Failed to open output file at path: {output_path}"))? + .context(format!("failed to open output file at path: {output_path}"))? .write_all(lcov.as_bytes()) - .context("Failed to write to output file")?; + .context("failed to write to output file")?; Ok(()) } diff --git a/crates/cairo-coverage/src/main.rs b/crates/cairo-coverage/src/main.rs index 2b2894f..9e07d2f 100644 --- a/crates/cairo-coverage/src/main.rs +++ b/crates/cairo-coverage/src/main.rs @@ -1,21 +1,36 @@ use crate::args::{CairoCoverageArgs, Command}; use anyhow::Result; + use clap::Parser; +use std::process::ExitCode; mod args; mod commands; +mod ui; + +fn main() -> ExitCode { + if let Err(error) = main_inner() { + ui::error(error); + ExitCode::FAILURE + } else { + ExitCode::SUCCESS + } +} -fn main() -> Result<()> { +fn main_inner() -> Result<()> { let cairo_coverage_args = CairoCoverageArgs::parse(); - let command = match cairo_coverage_args.command { - Some(command) => command, - // TODO: - // * In 0.5.0 add deprecation warning - // * In 0.6.0 remove the default command - None => Command::Run(cairo_coverage_args.run_args.unwrap_or_else(|| { + // TODO: + // * In 0.6.0 remove the default command + let command = if let Some(command) = cairo_coverage_args.command { + command + } else { + ui::warning("running `cairo-coverage` without a subcommand is deprecated"); + ui::help("consider using `cairo-coverage run`"); + + Command::Run(cairo_coverage_args.run_args.unwrap_or_else(|| { unreachable!("`run_args` should be set when no subcommand is provided") - })), + })) }; commands::run(command) diff --git a/crates/cairo-coverage/src/ui.rs b/crates/cairo-coverage/src/ui.rs new file mode 100644 index 0000000..a9e157f --- /dev/null +++ b/crates/cairo-coverage/src/ui.rs @@ -0,0 +1,28 @@ +//! UI utilities for the Cairo coverage tool. +//! All human-oriented messaging must use this module to communicate with the user. +//! Messages should be lowercased and should not end with a period. +use console::style; +use std::fmt::Display; + +/// Print a warning message. +pub fn warning(message: impl Display) { + let tag = style("warning").yellow(); + println!("{tag}: {message}"); +} + +/// Print an error message. +pub fn error(message: impl Display) { + let tag = style("error").red(); + println!("{tag}: {message}"); +} + +/// Print a help message. +pub fn help(message: impl Display) { + let tag = style("help").bold(); + println!("{tag}: {message}"); +} + +/// Print a message. +pub fn msg(message: impl Display) { + println!("{message}"); +} From cba9f8c07cb8cf21b06c486a796fef0b92298058 Mon Sep 17 00:00:00 2001 From: ksew1 Date: Tue, 25 Feb 2025 17:57:45 +0100 Subject: [PATCH 2/4] Fix error messages in core commit-id:e6561ac2 --- crates/cairo-coverage-core/src/build/coverage_input.rs | 2 +- crates/cairo-coverage-core/src/lib.rs | 4 ++-- crates/cairo-coverage-core/src/loading/enriched_program.rs | 6 +++--- crates/cairo-coverage-core/src/loading/mod.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/cairo-coverage-core/src/build/coverage_input.rs b/crates/cairo-coverage-core/src/build/coverage_input.rs index 11c983d..cf48e15 100644 --- a/crates/cairo-coverage-core/src/build/coverage_input.rs +++ b/crates/cairo-coverage-core/src/build/coverage_input.rs @@ -33,7 +33,7 @@ pub fn build( }: ExecutionData, filter: &StatementCategoryFilter, ) -> CoverageInput { - let casm_debug_info = compile(&program).expect("Failed to compile program to casm"); + let casm_debug_info = compile(&program).expect("failed to compile program to casm"); let statement_information_map = statement_information::build_map(coverage_annotations, profiler_annotations, filter); diff --git a/crates/cairo-coverage-core/src/lib.rs b/crates/cairo-coverage-core/src/lib.rs index 59a01c0..99f3684 100644 --- a/crates/cairo-coverage-core/src/lib.rs +++ b/crates/cairo-coverage-core/src/lib.rs @@ -55,7 +55,7 @@ pub fn run( // Versioned programs and contract classes can represent the same piece of code, // so we merge the file coverage after processing them to avoid duplicate entries. .reduce(merge) - .context("At least one trace file must be provided")?; + .context("at least one trace file must be provided")?; Ok(lcov::fmt_string(&coverage_data)) } @@ -66,5 +66,5 @@ fn scarb_metadata() -> Result { .inherit_stderr() .inherit_stdout() .exec() - .context("error: could not gather project metadata from Scarb due to previous error") + .context("could not gather project metadata from Scarb due to previous error") } diff --git a/crates/cairo-coverage-core/src/loading/enriched_program.rs b/crates/cairo-coverage-core/src/loading/enriched_program.rs index 9b58509..c9eaa6d 100644 --- a/crates/cairo-coverage-core/src/loading/enriched_program.rs +++ b/crates/cairo-coverage-core/src/loading/enriched_program.rs @@ -67,7 +67,7 @@ fn extract_versioned_program( ) -> Result<(Program, DebugInfo)> { Ok(( program, - debug_info.context("Debug info not found in program")?, + debug_info.context("debug info not found in program")?, )) } @@ -76,7 +76,7 @@ fn extract_contract_class(contract_class: ContractClass) -> Result<(Program, Deb let program = contract_class.extract_sierra_program()?; let debug_info = contract_class .sierra_program_debug_info - .context("Debug info not found in contract")?; + .context("debug info not found in contract")?; Ok((program, debug_info)) } @@ -96,7 +96,7 @@ fn deserialize_annotations>( ) -> Result { const RECOMMENDED_CAIRO_PROFILE_TOML: &str = indoc! { r#" - Perhaps you are missing the following entries in Scarb.toml: + perhaps you are missing the following entries in Scarb.toml: [profile.dev.cairo] unstable-add-statements-functions-debug-info = true diff --git a/crates/cairo-coverage-core/src/loading/mod.rs b/crates/cairo-coverage-core/src/loading/mod.rs index 6e12e41..0d48d86 100644 --- a/crates/cairo-coverage-core/src/loading/mod.rs +++ b/crates/cairo-coverage-core/src/loading/mod.rs @@ -24,9 +24,9 @@ mod execution_infos; /// Utility function to read and deserialize a JSON file. fn read_and_deserialize(file_path: &Utf8PathBuf) -> Result { let content = fs::read_to_string(file_path) - .context(format!("Failed to read file at path: {file_path}"))?; + .context(format!("failed to read file at path: {file_path}"))?; serde_json::from_str(&content).context(format!( - "Failed to deserialize JSON content from file at path: {file_path}" + "failed to deserialize JSON content from file at path: {file_path}" )) } From 56d7ac124a1bb7ec5453e8d6803aa1ecc55f38ff Mon Sep 17 00:00:00 2001 From: ksew1 Date: Tue, 25 Feb 2025 18:00:32 +0100 Subject: [PATCH 3/4] Move scarb metadata call to binary commit-id:de98a44d --- Cargo.lock | 2 +- crates/cairo-coverage-core/Cargo.toml | 1 - .../benches/benchmarks/mod.rs | 13 +++------- .../benches/benchmarks/starknet_staking.rs | 7 ++++-- crates/cairo-coverage-core/src/args.rs | 5 ---- crates/cairo-coverage-core/src/lib.rs | 24 +++---------------- crates/cairo-coverage/Cargo.toml | 1 + crates/cairo-coverage/src/args/run.rs | 2 +- crates/cairo-coverage/src/commands/run.rs | 18 ++++++++++++-- 9 files changed, 30 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06e704c..7cd6c49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -226,6 +226,7 @@ dependencies = [ "camino", "clap", "console", + "scarb-metadata", "snapbox", "walkdir", "which", @@ -249,7 +250,6 @@ dependencies = [ "itertools 0.14.0", "rayon", "regex", - "scarb-metadata", "serde", "serde_json", ] diff --git a/crates/cairo-coverage-core/Cargo.toml b/crates/cairo-coverage-core/Cargo.toml index 1cbbafb..c591d6d 100644 --- a/crates/cairo-coverage-core/Cargo.toml +++ b/crates/cairo-coverage-core/Cargo.toml @@ -14,7 +14,6 @@ itertools.workspace = true ignore.workspace = true serde.workspace = true serde_json.workspace = true -scarb-metadata.workspace = true regex.workspace = true indoc.workspace = true rayon.workspace = true diff --git a/crates/cairo-coverage-core/benches/benchmarks/mod.rs b/crates/cairo-coverage-core/benches/benchmarks/mod.rs index 65bb37b..f21282f 100644 --- a/crates/cairo-coverage-core/benches/benchmarks/mod.rs +++ b/crates/cairo-coverage-core/benches/benchmarks/mod.rs @@ -1,4 +1,3 @@ -use cairo_coverage_core::args::RunOptions; use cairo_coverage_test_utils::read_files_from_dir; use camino::Utf8PathBuf; use criterion::Criterion; @@ -11,17 +10,11 @@ fn trace_files_for_benches(dir_name: &str) -> Vec { read_files_from_dir(format!("benches/project-traces/{dir_name}/trace")) } -/// Create [`RunOptions`] with set `project_path` and empty `include`. -/// If we leave the `project_path` as `None`, the `scarb_metadata` will fail. -fn run_options(dir_name: &str) -> RunOptions { - let project_path = Utf8PathBuf::from(format!("benches/project-traces/{dir_name}")) +/// Return `project_path` and for the benchmark project. +fn project_path(dir_name: &str) -> Utf8PathBuf { + Utf8PathBuf::from(format!("benches/project-traces/{dir_name}")) .canonicalize_utf8() .unwrap() - .into(); - RunOptions { - include: Vec::default(), - project_path, - } } /// Config of [`Criterion`] that should be used for all benchmarks. diff --git a/crates/cairo-coverage-core/benches/benchmarks/starknet_staking.rs b/crates/cairo-coverage-core/benches/benchmarks/starknet_staking.rs index af0bb37..8103c71 100644 --- a/crates/cairo-coverage-core/benches/benchmarks/starknet_staking.rs +++ b/crates/cairo-coverage-core/benches/benchmarks/starknet_staking.rs @@ -1,4 +1,5 @@ -use crate::benchmarks::{config, run_options, trace_files_for_benches}; +use crate::benchmarks::{config, project_path, trace_files_for_benches}; +use cairo_coverage_core::args::RunOptions; use criterion::{Criterion, criterion_group}; use std::hint::black_box; @@ -8,11 +9,13 @@ const PROJECT_NAME: &str = "starknet-staking"; /// The trace files should be generated using `download_bench_project.sh` script. fn starknet_staking_benchmark(c: &mut Criterion) { let trace_files = trace_files_for_benches(PROJECT_NAME); - let run_options = run_options(PROJECT_NAME); + let project_path = project_path(PROJECT_NAME); + let run_options = RunOptions::default(); c.bench_function("starknet-staking", |b| { b.iter(|| { cairo_coverage_core::run( black_box(trace_files.clone()), + black_box(project_path.clone()), black_box(run_options.clone()), ) }); diff --git a/crates/cairo-coverage-core/src/args.rs b/crates/cairo-coverage-core/src/args.rs index bb8f6d9..4cd6fe6 100644 --- a/crates/cairo-coverage-core/src/args.rs +++ b/crates/cairo-coverage-core/src/args.rs @@ -1,13 +1,8 @@ -use camino::Utf8PathBuf; - /// Options accepted by `cairo_coverage_core` `run` function. #[derive(Default, Clone)] pub struct RunOptions { /// Include additional components in the coverage report. pub include: Vec, - - /// Path to the project directory. If not provided, the project directory is inferred from the trace. - pub project_path: Option, } /// Additional components that can be included in the coverage report. diff --git a/crates/cairo-coverage-core/src/lib.rs b/crates/cairo-coverage-core/src/lib.rs index 99f3684..f30bebb 100644 --- a/crates/cairo-coverage-core/src/lib.rs +++ b/crates/cairo-coverage-core/src/lib.rs @@ -15,26 +15,17 @@ use crate::output::lcov; use anyhow::{Context, Result}; use camino::Utf8PathBuf; use rayon::iter::{IntoParallelIterator, ParallelIterator}; -use scarb_metadata::{Metadata, MetadataCommand}; -/// Run the core logic of `cairo-coverage` with the provided trace files and [`RunOptions`]. +/// Run the core logic of `cairo-coverage` with the provided trace files, project path and [`RunOptions`]. /// This function generates a coverage report in the LCOV format. /// # Errors /// Fails if it can't produce the coverage report with the error message explaining the reason. #[expect(clippy::needless_pass_by_value)] // In case if we ever needed to take ownership of the arguments. pub fn run( trace_files: Vec, - RunOptions { - include, - project_path, - }: RunOptions, + project_path: Utf8PathBuf, + RunOptions { include }: RunOptions, ) -> Result { - let project_path = if let Some(project_path) = project_path { - project_path - } else { - scarb_metadata()?.workspace.root - }; - let ignore_matcher = ignore_matcher::build(&project_path)?; let coverage_data = execution_data::load(&trace_files)? @@ -59,12 +50,3 @@ pub fn run( Ok(lcov::fmt_string(&coverage_data)) } - -/// Run `scarb metadata` command and return the metadata. -fn scarb_metadata() -> Result { - MetadataCommand::new() - .inherit_stderr() - .inherit_stdout() - .exec() - .context("could not gather project metadata from Scarb due to previous error") -} diff --git a/crates/cairo-coverage/Cargo.toml b/crates/cairo-coverage/Cargo.toml index ad8057b..b4192e2 100644 --- a/crates/cairo-coverage/Cargo.toml +++ b/crates/cairo-coverage/Cargo.toml @@ -8,6 +8,7 @@ cairo-coverage-core = { path = "../cairo-coverage-core" } console.workspace = true camino.workspace = true anyhow.workspace = true +scarb-metadata.workspace = true clap.workspace = true walkdir.workspace = true diff --git a/crates/cairo-coverage/src/args/run.rs b/crates/cairo-coverage/src/args/run.rs index fd01732..08b6381 100644 --- a/crates/cairo-coverage/src/args/run.rs +++ b/crates/cairo-coverage/src/args/run.rs @@ -17,7 +17,7 @@ pub struct RunArgs { #[arg(long, short, num_args = 1..)] pub include: Vec, - /// Path to the project directory. If not provided, the project directory is inferred from the trace. + /// 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 34f0640..1dd6342 100644 --- a/crates/cairo-coverage/src/commands/run.rs +++ b/crates/cairo-coverage/src/commands/run.rs @@ -1,6 +1,7 @@ use crate::args::run::{IncludedComponent, RunArgs}; use anyhow::{Context, Result}; use cairo_coverage_core::args::{IncludedComponent as CoreIncludedComponent, RunOptions}; +use scarb_metadata::{Metadata, MetadataCommand}; use std::fs::OpenOptions; use std::io::Write; @@ -14,12 +15,17 @@ pub fn run( trace_files, }: RunArgs, ) -> Result<()> { + let project_path = if let Some(project_path) = project_path { + project_path + } else { + scarb_metadata()?.workspace.root + }; + let options = RunOptions { include: include.into_iter().map(Into::into).collect(), - project_path, }; - let lcov = cairo_coverage_core::run(trace_files, options)?; + let lcov = cairo_coverage_core::run(trace_files, project_path, options)?; OpenOptions::new() .append(true) @@ -32,6 +38,14 @@ pub fn run( Ok(()) } +/// Run `scarb metadata` command and return the metadata. +fn scarb_metadata() -> Result { + MetadataCommand::new() + .inherit_stderr() + .exec() + .context("could not gather project metadata from Scarb due to previous error") +} + impl From for CoreIncludedComponent { fn from(component: IncludedComponent) -> Self { match component { From c303a5a7f0f8d43b56013652c176760e96c98897 Mon Sep 17 00:00:00 2001 From: ksew1 Date: Wed, 26 Feb 2025 10:33:08 +0100 Subject: [PATCH 4/4] Include macros by default commit-id:8e17a8e6 --- CHANGELOG.md | 4 +++ crates/cairo-coverage/src/args/run.rs | 2 +- crates/cairo-coverage/tests/e2e/general.rs | 10 +++++++- .../expected_output/snforge_template.lcov | 23 ++++++++++++++--- .../snforge_template_macros_not_included.lcov | 25 +++++++++++++++++++ 5 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 crates/cairo-coverage/tests/expected_output/snforge_template_macros_not_included.lcov diff --git a/CHANGELOG.md b/CHANGELOG.md index 38988a4..6c298bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +#### 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) + ## [0.4.0] - 2025-01-03 #### Added diff --git a/crates/cairo-coverage/src/args/run.rs b/crates/cairo-coverage/src/args/run.rs index 08b6381..ceef6e6 100644 --- a/crates/cairo-coverage/src/args/run.rs +++ b/crates/cairo-coverage/src/args/run.rs @@ -14,7 +14,7 @@ pub struct RunArgs { pub output_path: Utf8PathBuf, /// Include additional components in the coverage report. - #[arg(long, short, num_args = 1..)] + #[arg(long, short, num_args = 0.., default_value = "macros")] pub include: Vec, /// Path to the project directory. If not provided, the project directory is inferred using `scarb metadata`. diff --git a/crates/cairo-coverage/tests/e2e/general.rs b/crates/cairo-coverage/tests/e2e/general.rs index 585f6d0..2caee2f 100644 --- a/crates/cairo-coverage/tests/e2e/general.rs +++ b/crates/cairo-coverage/tests/e2e/general.rs @@ -54,7 +54,6 @@ fn readme_example() { #[test] fn macros() { TestProject::new("macros") - .coverage_args(&["--include", "macros"]) .run() .output_same_as_in_file("macros.lcov"); } @@ -62,6 +61,7 @@ fn macros() { #[test] fn macros_not_included() { TestProject::new("macros") + .coverage_args(&["--include"]) .run_without_genhtml() .assert_empty_output(); } @@ -72,3 +72,11 @@ fn snforge_template() { .run() .output_same_as_in_file("snforge_template.lcov"); } + +#[test] +fn snforge_template_macros_not_included() { + TestProject::new("snforge_template") + .coverage_args(&["--include"]) + .run() + .output_same_as_in_file("snforge_template_macros_not_included.lcov"); +} diff --git a/crates/cairo-coverage/tests/expected_output/snforge_template.lcov b/crates/cairo-coverage/tests/expected_output/snforge_template.lcov index 46988cf..0a70bf4 100644 --- a/crates/cairo-coverage/tests/expected_output/snforge_template.lcov +++ b/crates/cairo-coverage/tests/expected_output/snforge_template.lcov @@ -4,13 +4,28 @@ FN:22,snforge_template::HelloStarknet::HelloStarknetImpl::get_balance FNDA:9,snforge_template::HelloStarknet::HelloStarknetImpl::get_balance FN:17,snforge_template::HelloStarknet::HelloStarknetImpl::increase_balance FNDA:8,snforge_template::HelloStarknet::HelloStarknetImpl::increase_balance -FNF:2 -FNH:2 +FN:21,snforge_template::HelloStarknet::__wrapper__HelloStarknetImpl__get_balance +FNDA:27,snforge_template::HelloStarknet::__wrapper__HelloStarknetImpl__get_balance +FN:16,snforge_template::HelloStarknet::__wrapper__HelloStarknetImpl__increase_balance +FNDA:19,snforge_template::HelloStarknet::__wrapper__HelloStarknetImpl__increase_balance +FN:1,snforge_template::IHelloStarknetDispatcherImpl::get_balance +FNDA:16,snforge_template::IHelloStarknetDispatcherImpl::get_balance +FN:1,snforge_template::IHelloStarknetDispatcherImpl::increase_balance +FNDA:6,snforge_template::IHelloStarknetDispatcherImpl::increase_balance +FN:1,snforge_template::IHelloStarknetSafeDispatcherImpl::get_balance +FNDA:5,snforge_template::IHelloStarknetSafeDispatcherImpl::get_balance +FN:1,snforge_template::IHelloStarknetSafeDispatcherImpl::increase_balance +FNDA:3,snforge_template::IHelloStarknetSafeDispatcherImpl::increase_balance +FNF:8 +FNH:8 +DA:1,30 +DA:16,19 DA:17,7 DA:18,8 +DA:21,27 DA:22,9 -LF:3 -LH:3 +LF:6 +LH:6 end_of_record TN: SF:{dir}/tests/test_contract.cairo diff --git a/crates/cairo-coverage/tests/expected_output/snforge_template_macros_not_included.lcov b/crates/cairo-coverage/tests/expected_output/snforge_template_macros_not_included.lcov new file mode 100644 index 0000000..46988cf --- /dev/null +++ b/crates/cairo-coverage/tests/expected_output/snforge_template_macros_not_included.lcov @@ -0,0 +1,25 @@ +TN: +SF:{dir}/src/lib.cairo +FN:22,snforge_template::HelloStarknet::HelloStarknetImpl::get_balance +FNDA:9,snforge_template::HelloStarknet::HelloStarknetImpl::get_balance +FN:17,snforge_template::HelloStarknet::HelloStarknetImpl::increase_balance +FNDA:8,snforge_template::HelloStarknet::HelloStarknetImpl::increase_balance +FNF:2 +FNH:2 +DA:17,7 +DA:18,8 +DA:22,9 +LF:3 +LH:3 +end_of_record +TN: +SF:{dir}/tests/test_contract.cairo +FN:11,snforge_template_integrationtest::test_contract::deploy_contract +FNDA:10,snforge_template_integrationtest::test_contract::deploy_contract +FNF:1 +FNH:1 +DA:11,10 +DA:12,10 +LF:2 +LH:2 +end_of_record