Skip to content

Commit

Permalink
Merge #171
Browse files Browse the repository at this point in the history
171: Add test for coverage-helper r=taiki-e a=taiki-e

https://github.com/taiki-e/coverage-helper

cc #123

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e authored May 29, 2022
2 parents 8d63c9f + 5380716 commit b4ff984
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ cfgs are set under the following conditions:
- `cfg(coverage)` is always set when using cargo-llvm-cov (unless `--no-cfg-coverage` flag passed)
- `cfg(coverage_nightly)` is set when using cargo-llvm-cov with nightly toolchain (unless `--no-cfg-coverage-nightly` flag passed)

If you want ignore all `#[test]`-related code, consider using [coverage-helper] crate.

### Continuous Integration

Here is an example of GitHub Actions workflow that uploads coverage to [Codecov].
Expand Down Expand Up @@ -493,6 +495,7 @@ See also [the code-coverage-related issues reported in rust-lang/rust](https://g

## Related Projects

- [coverage-helper]: Helper for [#123].
- [cargo-hack]: Cargo subcommand to provide various options useful for testing and continuous integration.
- [cargo-minimal-versions]: Cargo subcommand for proper use of `-Z minimal-versions`.

Expand All @@ -501,9 +504,11 @@ See also [the code-coverage-related issues reported in rust-lang/rust](https://g
[#8]: https://github.com/taiki-e/cargo-llvm-cov/issues/8
[#12]: https://github.com/taiki-e/cargo-llvm-cov/issues/12
[#20]: https://github.com/taiki-e/cargo-llvm-cov/issues/20
[#123]: https://github.com/taiki-e/cargo-llvm-cov/issues/123
[cargo-hack]: https://github.com/taiki-e/cargo-hack
[cargo-minimal-versions]: https://github.com/taiki-e/cargo-minimal-versions
[codecov]: https://codecov.io
[coverage-helper]: https://github.com/taiki-e/coverage-helper
[instrument-coverage]: https://doc.rust-lang.org/stable/rustc/instrument-coverage.html
[nextest]: https://nexte.st
[rust-lang/rust#79417]: https://github.com/rust-lang/rust/issues/79417
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
1| 1|#![cfg_attr(coverage_nightly, feature(no_coverage))]#![cfg_attr(coverage_nightly, feature(no_coverage))]
2| |
3| |use coverage_helper::test;
4| |
5| 2|fn func(x: i32) {
6| 2| match x {
7| 1| 0 => {}
8| 0| 1 => {}
9| 1| 2 => {}
10| 0| 3 => {}
11| 0| _ => {}
12| | }
13| 2|}
14| |
15| 1|#[test]
16| |fn test() {
17| | func(0);
18| |
19| | if false {
20| | func(1);
21| | } else {
22| | func(2);
23| | }
24| |}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"data": [
{
"files": [
{
"filename": "src/lib.rs",
"summary": {
"branches": {
"count": 0,
"covered": 0,
"notcovered": 0,
"percent": 0.0
},
"functions": {
"count": 3,
"covered": 3,
"percent": 100.0
},
"instantiations": {
"count": 3,
"covered": 3,
"percent": 100.0
},
"lines": {
"count": 10,
"covered": 7,
"percent": 70.0
},
"regions": {
"count": 9,
"covered": 6,
"notcovered": 3,
"percent": 66.66666666666666
}
}
}
],
"totals": {
"branches": {
"count": 0,
"covered": 0,
"notcovered": 0,
"percent": 0
},
"functions": {
"count": 3,
"covered": 3,
"percent": 100
},
"instantiations": {
"count": 3,
"covered": 3,
"percent": 100
},
"lines": {
"count": 10,
"covered": 7,
"percent": 70
},
"regions": {
"count": 9,
"covered": 6,
"notcovered": 3,
"percent": 66.66666666666666
}
}
}
],
"type": "llvm.coverage.json.export",
"version": "2.0.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SF:src/lib.rs
FNF:3
FNH:3
BRF:0
BRH:0
LF:10
LH:7
end_of_record
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
src/lib.rs 9 3 66.67% 3 0 100.00% 10 3 70.00% 0 0 -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL 9 3 66.67% 3 0 100.00% 10 3 70.00% 0 0 -
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
1| 1|#![cfg_attr(coverage_nightly, feature(no_coverage))]#![cfg_attr(coverage_nightly, feature(no_coverage))]
2| |
3| |use coverage_helper::test;
4| |
5| 2|fn func(x: i32) {
6| 2| match x {
7| 1| 0 => {}
8| 0| 1 => {}
9| 1| 2 => {}
10| 0| 3 => {}
11| 0| _ => {}
12| | }
13| 2|}
14| |
15| 1|#[test]
16| |fn test() {
17| | func(0);
18| |
19| | if false {
20| | func(1);
21| | } else {
22| | func(2);
23| | }
24| |}
9 changes: 9 additions & 0 deletions tests/fixtures/crates/coverage_helper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "no_coverage_coverage_helper"
version = "0.0.0"
edition = "2018"

[workspace]

[dependencies]
coverage-helper = "0.1"
24 changes: 24 additions & 0 deletions tests/fixtures/crates/coverage_helper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![cfg_attr(coverage_nightly, feature(no_coverage))]

use coverage_helper::test;

fn func(x: i32) {
match x {
0 => {}
1 => {}
2 => {}
3 => {}
_ => {}
}
}

#[test]
fn test() {
func(0);

if false {
func(1);
} else {
func(2);
}
}
14 changes: 14 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ fn no_coverage() {
}
}

#[rustversion::attr(not(nightly), ignore)]
#[test]
fn coverage_helper() {
let model = "coverage_helper";
let id = format!("{model}/{model}");
for (extension, args2) in test_set() {
// TODO: On windows, the order of the instantiations in the generated coverage report will be different.
if extension == "full.json" && cfg!(windows) {
continue;
}
test_report(model, model, extension, None, args2, &[]).context(id.clone()).unwrap();
}
}

#[test]
fn merge() {
let output_dir = FIXTURES_PATH.join("coverage-reports").join("merge");
Expand Down

0 comments on commit b4ff984

Please sign in to comment.