Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not include end of the function in coverage report #63

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### Added

- Option to not include macros in coverage report. To get the same behavior as before use `--include macros`.
- Option to not include macros in coverage report. To get the same behavior as before use `--include macros`

#### Fixed

Expand All @@ -18,4 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### Changed

- `--include-test-functions` was remove in favor of `--include`. To get same behavior as before use `--include tests-functions`.
- `--include-test-functions` was remove in favor of `--include`. To get same behavior as before
use `--include tests-functions`
- Only the start of the function is now included in the report. The end of the function is optional in the lcov format
and would produce a warning in tools like `genhtml` when two or more functions are declared on the same line
5 changes: 0 additions & 5 deletions crates/cairo-coverage/src/coverage_data/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ pub trait FunctionCoverageDataOps {
fn hit(&self) -> bool;
fn hit_count(&self) -> HitCount;
fn starts_at(&self) -> LineNumber;
fn ends_at(&self) -> LineNumber;
}

impl FunctionCoverageDataOps for FunctionCoverageData {
Expand All @@ -94,10 +93,6 @@ impl FunctionCoverageDataOps for FunctionCoverageData {
fn starts_at(&self) -> LineNumber {
self.keys().min().copied().unwrap_or_default()
}

fn ends_at(&self) -> LineNumber {
self.keys().max().copied().unwrap_or_default()
}
}

impl From<LineRange> for FunctionCoverageData {
Expand Down
8 changes: 1 addition & 7 deletions crates/cairo-coverage/src/output/lcov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub struct LcovData {
struct LcovDetails {
name: FunctionName,
starts_at: LineNumber,
ends_at: LineNumber,
hit_count: HitCount,
}

Expand Down Expand Up @@ -63,7 +62,6 @@ impl From<(&FunctionName, &FunctionCoverageData)> for LcovDetails {
Self {
name: name.to_owned(),
starts_at: function_coverage_data.starts_at(),
ends_at: function_coverage_data.ends_at(),
hit_count: function_coverage_data.hit_count(),
}
}
Expand All @@ -83,11 +81,7 @@ impl Display for LcovFormat {
impl Display for LcovData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for function in &self.functions {
writeln!(
f,
"FN:{},{},{}",
function.starts_at, function.ends_at, function.name
)?;
writeln!(f, "FN:{},{}", function.starts_at, function.name)?;
writeln!(f, "FNDA:{},{}", function.hit_count, function.name)?;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
TN:
SF:{dir}/src/lib.cairo
FN:2,2,complex_calculator::add
FN:2,complex_calculator::add
FNDA:2,complex_calculator::add
FN:17,21,complex_calculator::divide
FN:17,complex_calculator::divide
FNDA:1,complex_calculator::divide
FN:25,30,complex_calculator::factorial
FN:25,complex_calculator::factorial
FNDA:12,complex_calculator::factorial
FN:45,49,complex_calculator::fibonacci
FN:45,complex_calculator::fibonacci
FNDA:2,complex_calculator::fibonacci
FN:53,63,complex_calculator::is_prime
FN:53,complex_calculator::is_prime
FNDA:84,complex_calculator::is_prime
FN:10,10,complex_calculator::multiply
FN:10,complex_calculator::multiply
FNDA:2,complex_calculator::multiply
FN:35,40,complex_calculator::power
FN:35,complex_calculator::power
FNDA:10,complex_calculator::power
FN:6,6,complex_calculator::subtract
FN:6,complex_calculator::subtract
FNDA:2,complex_calculator::subtract
FN:14,14,complex_calculator::unsafe_divide
FN:14,complex_calculator::unsafe_divide
FNDA:0,complex_calculator::unsafe_divide
FNF:9
FNH:8
Expand Down
6 changes: 3 additions & 3 deletions crates/cairo-coverage/tests/expected_output/macros.lcov
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
TN:
SF:{dir}/src/lib.cairo
FN:2,2,macros::assert_macro
FN:2,macros::assert_macro
FNDA:1,macros::assert_macro
FN:1,1,macros::function_with_macro
FN:1,macros::function_with_macro
FNDA:1,macros::function_with_macro
FN:2,2,macros::write_macro
FN:2,macros::write_macro
FNDA:0,macros::write_macro
FNF:3
FNH:2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TN:
SF:{dir}/src/lib.cairo
FN:1,1,macros::function_with_macro
FN:1,macros::function_with_macro
FNDA:1,macros::function_with_macro
FNF:1
FNH:1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
TN:
SF:{dir}/src/lib.cairo
FN:8,8,readme_example::add
FN:8,readme_example::add
FNDA:4,readme_example::add
FN:16,18,readme_example::calculator
FN:16,readme_example::calculator
FNDA:4,readme_example::calculator
FN:12,12,readme_example::multiply
FN:12,readme_example::multiply
FNDA:0,readme_example::multiply
FNF:3
FNH:2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TN:
SF:{dir}/src/lib.cairo
FN:5,11,scarb_template::fib
FN:5,scarb_template::fib
FNDA:34,scarb_template::fib
FNF:1
FNH:1
Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-coverage/tests/expected_output/simple.lcov
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
TN:
SF:{dir}/src/lib.cairo
FN:7,8,simple::increase_by_one
FN:7,simple::increase_by_one
FNDA:4,simple::increase_by_one
FN:2,3,simple::increase_by_two
FN:2,simple::increase_by_two
FNDA:3,simple::increase_by_two
FNF:2
FNH:2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
TN:
SF:{dir}/src/lib.cairo
FN:7,8,simple::increase_by_one
FN:7,simple::increase_by_one
FNDA:4,simple::increase_by_one
FN:2,3,simple::increase_by_two
FN:2,simple::increase_by_two
FNDA:3,simple::increase_by_two
FNF:2
FNH:2
Expand All @@ -15,7 +15,7 @@ LH:4
end_of_record
TN:
SF:{dir}/tests/test_call.cairo
FN:2,2,simple_tests::test_call::my_test
FN:2,simple_tests::test_call::my_test
FNDA:4,simple_tests::test_call::my_test
FNF:1
FNH:1
Expand Down
18 changes: 9 additions & 9 deletions lcov.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ When running with `cairo-coverage` you will get a coverage report in `.lcov` for
```lcov
TN:
SF:/path/to/your/project/src/lib.rs
FN:8,8,readme_example::add
FN:8,readme_example::add
FNDA:4,readme_example::add
FN:16,18,readme_example::calculator
FN:16,readme_example::calculator
FNDA:4,readme_example::calculator
FN:12,12,readme_example::multiply
FN:12,readme_example::multiply
FNDA:0,readme_example::multiply
FNF:3
FNH:2
Expand All @@ -68,9 +68,9 @@ Let's break it down
- **SF**: Source File path `/path/to/your/project/src/lib.rs`

2. **Function Details**
- **FN:8,8,readme_example::add**: The `add` function starts at line 8 and ends at line 8.
- **FN:12,12,readme_example::multiply**: The `multiply` function starts at line 12 and ends at line 12.
- **FN:16,18,readme_example::calculator**: The `calculator` function starts at line 16 and ends at line 18.
- **FN:8,readme_example::add**: The `add` function starts at line 8.
- **FN:12,readme_example::multiply**: The `multiply` function starts at line 12.
- **FN:16,readme_example::calculator**: The `calculator` function starts at line 16.

3. **Function Hit Details**
- **FNDA:4,readme_example::add**: The `add` function was executed 4 times (Currently not accurate as expected is to
Expand Down Expand Up @@ -124,15 +124,15 @@ Let's break it down
> ```lcov
> TN:
> SF:/path/to/your/project/src/operations.cairo
> FN:8,8,readme_example::add
> FN:8,readme_example::add
> FNDA:4,readme_example::add
> FN:12,12,readme_example::multiply
> FN:12,readme_example::multiply
> FNDA:0,readme_example::multiply
> ... other metrics ...
> end_of_record
> TN:
> SF:/path/to/your/project/src/lib.cairo
> FN:16,18,readme_example::calculator
> FN:16,readme_example::calculator
> FNDA:4,readme_example::calculator
> ... other metrics ...
> LH:10
Expand Down
Loading