Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
commit-id:f6098cdc
  • Loading branch information
ksew1 committed Dec 4, 2024
1 parent a6ff35b commit 542df8e
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 0 deletions.
22 changes: 22 additions & 0 deletions crates/cairo-coverage/tests/data/coverage_ignore/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "coverage_ignore"
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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod simple;
mod multiply;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub fn multiply(a: i32, b: i32) -> i32 {
a * b
}

#[cfg(test)]
mod tests {
use super::multiply;

#[test]
fn it_works() {
assert(multiply(2, 1) == 2, '');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod add;
mod subtract;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub fn add(a: i32, b: i32) -> i32 {
a + b
}


#[cfg(test)]
mod tests {
use super::add;

#[test]
fn it_works() {
assert(add(1, 2) == 3, '');
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn subtract(a: i32, b: i32) -> i32 {
a - b
}


#[cfg(test)]
mod tests {
use super::subtract;

#[test]
fn it_works() {
assert(subtract(2, 1) == 1, '');
}
}
16 changes: 16 additions & 0 deletions crates/cairo-coverage/tests/e2e/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,19 @@ fn snforge_template() {
.run()
.output_same_as_in_file("snforge_template.lcov");
}

#[test]
fn coverage_ignore_dir() {
TestProject::new("coverage_ignore")
.create_cairo_coverage_ignore("*/simple/*")
.run()
.output_same_as_in_file("coverage_ignore_dir.lcov");
}

#[test]
fn coverage_ignore_files() {
TestProject::new("coverage_ignore")
.create_cairo_coverage_ignore("multiply.cairo\nadd.cairo")
.run()
.output_same_as_in_file("coverage_ignore_file.lcov");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TN:
SF:{dir}/src/multiply.cairo
FN:2,coverage_ignore::multiply::multiply
FNDA:1,coverage_ignore::multiply::multiply
FNF:1
FNH:1
DA:2,1
LF:1
LH:1
end_of_record
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TN:
SF:{dir}/src/simple/subtract.cairo
FN:2,coverage_ignore::simple::subtract::subtract
FNDA:1,coverage_ignore::simple::subtract::subtract
FNF:1
FNH:1
DA:2,1
LF:1
LH:1
end_of_record

0 comments on commit 542df8e

Please sign in to comment.