-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to not include macros in their coverage report
commit-id:dd9032f3
- Loading branch information
Showing
14 changed files
with
220 additions
and
79 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
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,90 @@ | ||
use crate::cli::IncludedComponent; | ||
use crate::data_loader::LoadedData; | ||
use crate::input::sierra_to_cairo_map::StatementOrigin; | ||
use regex::Regex; | ||
use std::collections::HashSet; | ||
use std::iter::once; | ||
use std::sync::LazyLock; | ||
|
||
pub static VIRTUAL_FILE_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\[.*?]").unwrap()); | ||
const SNFORGE_TEST_EXECUTABLE: &str = "snforge_internal_test_executable"; | ||
|
||
#[derive(Eq, PartialEq, Hash)] | ||
enum ItemLabel { | ||
TestFunction, | ||
UserFunction, | ||
NonUserFunction, | ||
Macro, | ||
} | ||
|
||
impl From<IncludedComponent> for ItemLabel { | ||
fn from(included_component: IncludedComponent) -> Self { | ||
match included_component { | ||
IncludedComponent::TestFunctions => ItemLabel::TestFunction, | ||
IncludedComponent::Macros => ItemLabel::Macro, | ||
} | ||
} | ||
} | ||
|
||
pub struct Filter { | ||
allowed_labels: HashSet<ItemLabel>, | ||
test_functions: HashSet<String>, | ||
} | ||
|
||
impl Filter { | ||
pub fn new(included_component: &[IncludedComponent], loaded_data: &LoadedData) -> Self { | ||
let test_functions = loaded_data | ||
.debug_info | ||
.executables | ||
.get(SNFORGE_TEST_EXECUTABLE) | ||
.unwrap_or(&Vec::new()) | ||
.iter() | ||
.map(ToString::to_string) | ||
.collect(); | ||
|
||
let allowed_labels = included_component | ||
.iter() | ||
.cloned() | ||
.map(ItemLabel::from) | ||
.chain(once(ItemLabel::UserFunction)) | ||
.collect(); | ||
|
||
Self { | ||
allowed_labels, | ||
test_functions, | ||
} | ||
} | ||
|
||
pub fn should_include(&self, statement_origin: &StatementOrigin) -> bool { | ||
self.labels(statement_origin) | ||
.is_subset(&self.allowed_labels) | ||
} | ||
|
||
fn labels( | ||
&self, | ||
StatementOrigin { | ||
function_name, | ||
file_location, | ||
.. | ||
}: &StatementOrigin, | ||
) -> HashSet<ItemLabel> { | ||
let mut labels = HashSet::new(); | ||
|
||
if self.test_functions.contains(function_name) { | ||
labels.insert(ItemLabel::TestFunction); | ||
} else if VIRTUAL_FILE_REGEX.is_match(file_location) { | ||
labels.insert(ItemLabel::Macro); | ||
} | ||
|
||
// TODO(#55) | ||
// TODO: We should probably filter by path to user project not by path to cache | ||
// TODO: Can get this from source_sierra_path in call trace | ||
if file_location.contains("com.swmansion.scarb") || file_location.contains(".cache/scarb") { | ||
labels.insert(ItemLabel::NonUserFunction); | ||
} else { | ||
labels.insert(ItemLabel::UserFunction); | ||
} | ||
|
||
labels | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
mod data; | ||
mod filter; | ||
mod sierra_to_cairo_map; | ||
mod test_function_filter; | ||
mod unique_executed_sierra_ids; | ||
|
||
pub use data::InputData; | ||
pub use filter::Filter; | ||
pub use sierra_to_cairo_map::{create_sierra_to_cairo_map, SierraToCairoMap}; | ||
pub use unique_executed_sierra_ids::UniqueExecutedSierraIds; |
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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
[package] | ||
name = "macros" | ||
version = "0.1.0" | ||
edition = "2024_07" | ||
|
||
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html | ||
[dependencies] | ||
starknet = ">=2.8.0" | ||
|
||
[dev-dependencies] | ||
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.29.0" } | ||
|
||
[[target.starknet-contract]] | ||
sierra = true | ||
|
||
[scripts] | ||
test = "snforge test" | ||
|
||
[profile.dev.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,13 @@ | ||
fn function_with_macro() { | ||
assert!(1 == 1); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::function_with_macro; | ||
|
||
#[test] | ||
fn function_with_macro_test() { | ||
function_with_macro() | ||
} | ||
} |
Oops, something went wrong.