From 932a36971b848c7ad78a8d3832e54fb52166f3a8 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 19 Dec 2024 04:50:57 +0900 Subject: [PATCH] coverage_attribute has been stabilized --- README.md | 33 ++++--- .../coverage_helper.codecov.json | 2 +- .../coverage_helper.hide-instantiations.txt | 44 +++++----- .../coverage_helper/coverage_helper.txt | 44 +++++----- .../no_coverage/no_cfg_coverage.codecov.json | 2 +- .../no_cfg_coverage.hide-instantiations.txt | 85 +++++++++---------- .../no_coverage/no_cfg_coverage.json | 44 +++++----- .../no_coverage/no_cfg_coverage.lcov.info | 8 +- .../no_coverage/no_cfg_coverage.summary.txt | 4 +- .../no_coverage/no_cfg_coverage.txt | 85 +++++++++---------- .../no_coverage/no_coverage.codecov.json | 2 +- .../no_coverage.hide-instantiations.txt | 85 +++++++++---------- .../no_coverage/no_coverage.txt | 85 +++++++++---------- .../crates/coverage_helper/src/lib.rs | 2 - tests/fixtures/crates/no_coverage/src/lib.rs | 9 +- tests/test.rs | 8 +- 16 files changed, 265 insertions(+), 277 deletions(-) diff --git a/README.md b/README.md index d346bedd..9abf4a44 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This is a wrapper around rustc [`-C instrument-coverage`][instrument-coverage] a - [Get coverage of C/C++ code linked to Rust library/binary](#get-coverage-of-cc-code-linked-to-rust-librarybinary) - [Get coverage of external tests](#get-coverage-of-external-tests) - [Exclude file from coverage](#exclude-file-from-coverage) - - [Exclude function from coverage](#exclude-function-from-coverage) + - [Exclude code from coverage](#exclude-code-from-coverage) - [Continuous Integration](#continuous-integration) - [Display coverage in VS Code](#display-coverage-in-vs-code) - [Environment variables](#environment-variables) @@ -485,17 +485,22 @@ To exclude specific file patterns from the report, use the `--ignore-filename-re cargo llvm-cov --open --ignore-filename-regex build ``` -### Exclude function from coverage +### Exclude code from coverage -To exclude the specific function from coverage, use the [`#[coverage(off)]` attribute][rust-lang/rust#84605]. +To exclude the specific function or module from coverage, use the [`#[coverage(off)]` attribute][rust-lang/rust#84605]. -Since `#[coverage(off)]` is unstable, it is recommended to use it together with `cfg(coverage)` or `cfg(coverage_nightly)` set by cargo-llvm-cov. +Since `#[coverage(off)]` attribute stabilized in Rust 1.85, it is recommended to use it together with `cfg(coverage)` or `cfg(coverage_nightly)` set by cargo-llvm-cov for compatibility with old Rust. ```rust -#![cfg_attr(coverage_nightly, feature(coverage_attribute))] +// function +#[cfg_attr(coverage, coverage(off))] +fn exclude_fn_from_coverage() { + // ... +} -#[cfg_attr(coverage_nightly, coverage(off))] -fn exclude_from_coverage() { +// module +#[cfg_attr(coverage, coverage(off))] +mod exclude_mod_from_coverage { // ... } ``` @@ -512,11 +517,17 @@ Rust 1.80+ warns the above cfgs as `unexpected_cfgs`. The recommended way to add unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage,coverage_nightly)'] } ``` -If you want to ignore all `#[test]`-related code, consider using [coverage-helper] crate version 0.2+. +If you want to ignore all `#[test]`-related code, you can use module-level `#[coverage(off)]` attribute: -cargo-llvm-cov excludes code contained in the directory named `tests` from the report by default, so you can also use it instead of coverage-helper crate. +```rust +#[cfg(test)] +#[cfg_attr(coverage, coverage(off))] +mod tests { + // ... +} +``` -**Note:** `#[coverage(off)]` was previously named `#[no_coverage]`. When using `#[no_coverage]` in the old nightly, replace `feature(coverage_attribute)` with `feature(no_coverage)`, `coverage(off)` with `no_coverage`, and `coverage-helper` 0.2+ with `coverage-helper` 0.1. +cargo-llvm-cov excludes code contained in the directory named `tests` from the report by default, so you can also use it instead of `#[coverage(off)]` attribute. ### Continuous Integration @@ -716,7 +727,6 @@ See also [the code-coverage-related issues reported in rust-lang/rust](https://g ## Related Projects -- [coverage-helper]: Helper for [#123]. - [cargo-config2]: Library to load and resolve Cargo configuration. cargo-llvm-cov uses this library. - [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`. @@ -730,7 +740,6 @@ See also [the code-coverage-related issues reported in rust-lang/rust](https://g [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/rustc/instrument-coverage.html [nextest]: https://nexte.st/book/test-coverage.html [rust-lang/rust#79417]: https://github.com/rust-lang/rust/issues/79417 diff --git a/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.codecov.json b/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.codecov.json index 0d389740..56b64540 100644 --- a/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.codecov.json +++ b/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.codecov.json @@ -1 +1 @@ -{"coverage":{"src/lib.rs":{"5":"1/1","6":"1/1","7":"1/1","8":"0/1","9":"1/1","10":"0/1","11":"0/1","13":"1/1"}}} \ No newline at end of file +{"coverage":{"src/lib.rs":{"3":"1/1","4":"1/1","5":"1/1","6":"0/1","7":"1/1","8":"0/1","9":"0/1","11":"1/1"}}} \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.hide-instantiations.txt b/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.hide-instantiations.txt index 52b8f3cf..311db5b2 100644 --- a/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.hide-instantiations.txt +++ b/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.hide-instantiations.txt @@ -1,24 +1,22 @@ - 1| |#![cfg_attr(coverage_nightly, feature(coverage_attribute))] + 1| |use coverage_helper::test; 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| |#[test] - 16| |fn test() { - 17| | func(0); - 18| | - 19| | if false { - 20| | func(1); - 21| | } else { - 22| | func(2); - 23| | } - 24| |} \ No newline at end of file + 3| 2|fn func(x: i32) { + 4| 2| match x { + 5| 1| 0 => {} + 6| 0| 1 => {} + 7| 1| 2 => {} + 8| 0| 3 => {} + 9| 0| _ => {} + 10| | } + 11| 2|} + 12| | + 13| |#[test] + 14| |fn test() { + 15| | func(0); + 16| | + 17| | if false { + 18| | func(1); + 19| | } else { + 20| | func(2); + 21| | } + 22| |} \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.txt b/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.txt index 52b8f3cf..311db5b2 100644 --- a/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.txt +++ b/tests/fixtures/coverage-reports/coverage_helper/coverage_helper.txt @@ -1,24 +1,22 @@ - 1| |#![cfg_attr(coverage_nightly, feature(coverage_attribute))] + 1| |use coverage_helper::test; 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| |#[test] - 16| |fn test() { - 17| | func(0); - 18| | - 19| | if false { - 20| | func(1); - 21| | } else { - 22| | func(2); - 23| | } - 24| |} \ No newline at end of file + 3| 2|fn func(x: i32) { + 4| 2| match x { + 5| 1| 0 => {} + 6| 0| 1 => {} + 7| 1| 2 => {} + 8| 0| 3 => {} + 9| 0| _ => {} + 10| | } + 11| 2|} + 12| | + 13| |#[test] + 14| |fn test() { + 15| | func(0); + 16| | + 17| | if false { + 18| | func(1); + 19| | } else { + 20| | func(2); + 21| | } + 22| |} \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.codecov.json b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.codecov.json index 88744f49..6aee541b 100644 --- a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.codecov.json +++ b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.codecov.json @@ -1 +1 @@ -{"coverage":{"src/lib.rs":{"3":"1/1","4":"1/1","5":"1/1","6":"0/1","7":"0/1","8":"0/1","9":"0/1","11":"1/1","15":"1/1","16":"1/1","17":"1/1","18":"1/2","19":"0/1","20":"1/2","21":"1/1","26":"1/1","27":"1/2","28":"0/1","29":"0/1","30":"1/2","31":"1/1","39":"1/1","40":"1/2","41":"0/1","42":"1/2","43":"1/1"}}} \ No newline at end of file +{"coverage":{"src/lib.rs":{"1":"1/1","2":"1/1","3":"1/1","4":"0/1","5":"0/1","6":"0/1","7":"0/1","9":"1/1","24":"1/1","25":"1/2","26":"0/1","27":"0/1","28":"1/2","29":"1/1"}}} \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.hide-instantiations.txt b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.hide-instantiations.txt index f492ef1a..360264ae 100644 --- a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.hide-instantiations.txt +++ b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.hide-instantiations.txt @@ -1,44 +1,41 @@ - 1| |#![cfg_attr(coverage, feature(coverage_attribute))] - 2| | - 3| 1|fn func(x: i32) { - 4| 1| match x { - 5| 1| 0 => {} - 6| 0| 1 => {} - 7| 0| 2 => {} - 8| 0| 3 => {} - 9| 0| _ => {} - 10| | } - 11| 1|} - 12| | - 13| |#[cfg_attr(coverage, coverage(off))] - 14| |#[test] - 15| 1|fn fn_level() { - 16| 1| func(0); - 17| 1| - 18| 1| if false { - 19| 0| func(1); - 20| 1| } - 21| 1|} - 22| | - 23| |// #[coverage(off)] has no effect on expressions. - 24| |// now error by rustc: error[E0788]: attribute should be applied to a function definition or closure - 25| |#[test] - 26| 1|fn expr_level() { - 27| 1| if false { - 28| 0| // #[cfg_attr(coverage, coverage(off))] - 29| 0| func(2); - 30| 1| } - 31| 1|} - 32| | - 33| |// #[coverage(off)] has no effect on modules. - 34| |#[cfg_attr(coverage, coverage(off))] - 35| |mod mod_level { - 36| | use super::func; - 37| | - 38| | #[test] - 39| 1| fn mod_level() { - 40| 1| if false { - 41| 0| func(3); - 42| 1| } - 43| 1| } - 44| |} \ No newline at end of file + 1| 1|fn func(x: i32) { + 2| 1| match x { + 3| 1| 0 => {} + 4| 0| 1 => {} + 5| 0| 2 => {} + 6| 0| 3 => {} + 7| 0| _ => {} + 8| | } + 9| 1|} + 10| | + 11| |#[coverage(off)] + 12| |#[test] + 13| |fn fn_level() { + 14| | func(0); + 15| | + 16| | if false { + 17| | func(1); + 18| | } + 19| |} + 20| | + 21| |// #[coverage(off)] has no effect on expressions. + 22| |// now error by rustc: error[E0788]: attribute should be applied to a function definition or closure + 23| |#[test] + 24| 1|fn expr_level() { + 25| 1| if false { + 26| 0| // #[coverage(off)] + 27| 0| func(2); + 28| 1| } + 29| 1|} + 30| | + 31| |#[coverage(off)] + 32| |mod mod_level { + 33| | use super::func; + 34| | + 35| | #[test] + 36| | fn mod_level() { + 37| | if false { + 38| | func(3); + 39| | } + 40| | } + 41| |} \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.json b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.json index 0bc4cf56..e692bbf4 100644 --- a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.json +++ b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.json @@ -18,25 +18,25 @@ "percent": 0.0 }, "functions": { - "count": 4, - "covered": 4, + "count": 2, + "covered": 2, "percent": 100.0 }, "instantiations": { - "count": 4, - "covered": 4, + "count": 2, + "covered": 2, "percent": 100.0 }, "lines": { - "count": 26, - "covered": 18, - "percent": 69.23076923076923 + "count": 14, + "covered": 8, + "percent": 57.14285714285714 }, "regions": { - "count": 19, - "covered": 12, - "notcovered": 7, - "percent": 63.1578947368421 + "count": 11, + "covered": 6, + "notcovered": 5, + "percent": 54.54545454545454 } } } @@ -49,19 +49,19 @@ "percent": 0 }, "functions": { - "count": 4, - "covered": 4, + "count": 2, + "covered": 2, "percent": 100 }, "instantiations": { - "count": 4, - "covered": 4, + "count": 2, + "covered": 2, "percent": 100 }, "lines": { - "count": 26, - "covered": 18, - "percent": 69.23076923076923 + "count": 14, + "covered": 8, + "percent": 57.14285714285714 }, "mcdc": { "count": 0, @@ -70,10 +70,10 @@ "percent": 0 }, "regions": { - "count": 19, - "covered": 12, - "notcovered": 7, - "percent": 63.1578947368421 + "count": 11, + "covered": 6, + "notcovered": 5, + "percent": 54.54545454545454 } } } diff --git a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.lcov.info b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.lcov.info index a0f631a8..563e5dd6 100644 --- a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.lcov.info +++ b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.lcov.info @@ -1,8 +1,8 @@ SF:src/lib.rs -FNF:4 -FNH:4 +FNF:2 +FNH:2 BRF:0 BRH:0 -LF:26 -LH:18 +LF:14 +LH:8 end_of_record \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.summary.txt b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.summary.txt index 407bec74..8a591975 100644 --- a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.summary.txt +++ b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.summary.txt @@ -1,5 +1,5 @@ Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -src/lib.rs 19 7 63.16% 4 0 100.00% 26 8 69.23% 0 0 - +src/lib.rs 11 5 54.55% 2 0 100.00% 14 6 57.14% 0 0 - ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -TOTAL 19 7 63.16% 4 0 100.00% 26 8 69.23% 0 0 - \ No newline at end of file +TOTAL 11 5 54.55% 2 0 100.00% 14 6 57.14% 0 0 - \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.txt b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.txt index f492ef1a..360264ae 100644 --- a/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.txt +++ b/tests/fixtures/coverage-reports/no_coverage/no_cfg_coverage.txt @@ -1,44 +1,41 @@ - 1| |#![cfg_attr(coverage, feature(coverage_attribute))] - 2| | - 3| 1|fn func(x: i32) { - 4| 1| match x { - 5| 1| 0 => {} - 6| 0| 1 => {} - 7| 0| 2 => {} - 8| 0| 3 => {} - 9| 0| _ => {} - 10| | } - 11| 1|} - 12| | - 13| |#[cfg_attr(coverage, coverage(off))] - 14| |#[test] - 15| 1|fn fn_level() { - 16| 1| func(0); - 17| 1| - 18| 1| if false { - 19| 0| func(1); - 20| 1| } - 21| 1|} - 22| | - 23| |// #[coverage(off)] has no effect on expressions. - 24| |// now error by rustc: error[E0788]: attribute should be applied to a function definition or closure - 25| |#[test] - 26| 1|fn expr_level() { - 27| 1| if false { - 28| 0| // #[cfg_attr(coverage, coverage(off))] - 29| 0| func(2); - 30| 1| } - 31| 1|} - 32| | - 33| |// #[coverage(off)] has no effect on modules. - 34| |#[cfg_attr(coverage, coverage(off))] - 35| |mod mod_level { - 36| | use super::func; - 37| | - 38| | #[test] - 39| 1| fn mod_level() { - 40| 1| if false { - 41| 0| func(3); - 42| 1| } - 43| 1| } - 44| |} \ No newline at end of file + 1| 1|fn func(x: i32) { + 2| 1| match x { + 3| 1| 0 => {} + 4| 0| 1 => {} + 5| 0| 2 => {} + 6| 0| 3 => {} + 7| 0| _ => {} + 8| | } + 9| 1|} + 10| | + 11| |#[coverage(off)] + 12| |#[test] + 13| |fn fn_level() { + 14| | func(0); + 15| | + 16| | if false { + 17| | func(1); + 18| | } + 19| |} + 20| | + 21| |// #[coverage(off)] has no effect on expressions. + 22| |// now error by rustc: error[E0788]: attribute should be applied to a function definition or closure + 23| |#[test] + 24| 1|fn expr_level() { + 25| 1| if false { + 26| 0| // #[coverage(off)] + 27| 0| func(2); + 28| 1| } + 29| 1|} + 30| | + 31| |#[coverage(off)] + 32| |mod mod_level { + 33| | use super::func; + 34| | + 35| | #[test] + 36| | fn mod_level() { + 37| | if false { + 38| | func(3); + 39| | } + 40| | } + 41| |} \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/no_coverage/no_coverage.codecov.json b/tests/fixtures/coverage-reports/no_coverage/no_coverage.codecov.json index 1128259b..6aee541b 100644 --- a/tests/fixtures/coverage-reports/no_coverage/no_coverage.codecov.json +++ b/tests/fixtures/coverage-reports/no_coverage/no_coverage.codecov.json @@ -1 +1 @@ -{"coverage":{"src/lib.rs":{"3":"1/1","4":"1/1","5":"1/1","6":"0/1","7":"0/1","8":"0/1","9":"0/1","11":"1/1","26":"1/1","27":"1/2","28":"0/1","29":"0/1","30":"1/2","31":"1/1"}}} \ No newline at end of file +{"coverage":{"src/lib.rs":{"1":"1/1","2":"1/1","3":"1/1","4":"0/1","5":"0/1","6":"0/1","7":"0/1","9":"1/1","24":"1/1","25":"1/2","26":"0/1","27":"0/1","28":"1/2","29":"1/1"}}} \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/no_coverage/no_coverage.hide-instantiations.txt b/tests/fixtures/coverage-reports/no_coverage/no_coverage.hide-instantiations.txt index a567a193..360264ae 100644 --- a/tests/fixtures/coverage-reports/no_coverage/no_coverage.hide-instantiations.txt +++ b/tests/fixtures/coverage-reports/no_coverage/no_coverage.hide-instantiations.txt @@ -1,44 +1,41 @@ - 1| |#![cfg_attr(coverage, feature(coverage_attribute))] - 2| | - 3| 1|fn func(x: i32) { - 4| 1| match x { - 5| 1| 0 => {} - 6| 0| 1 => {} - 7| 0| 2 => {} - 8| 0| 3 => {} - 9| 0| _ => {} - 10| | } - 11| 1|} - 12| | - 13| |#[cfg_attr(coverage, coverage(off))] - 14| |#[test] - 15| |fn fn_level() { - 16| | func(0); - 17| | - 18| | if false { - 19| | func(1); - 20| | } - 21| |} - 22| | - 23| |// #[coverage(off)] has no effect on expressions. - 24| |// now error by rustc: error[E0788]: attribute should be applied to a function definition or closure - 25| |#[test] - 26| 1|fn expr_level() { - 27| 1| if false { - 28| 0| // #[cfg_attr(coverage, coverage(off))] - 29| 0| func(2); - 30| 1| } - 31| 1|} - 32| | - 33| |// #[coverage(off)] has no effect on modules. - 34| |#[cfg_attr(coverage, coverage(off))] - 35| |mod mod_level { - 36| | use super::func; - 37| | - 38| | #[test] - 39| | fn mod_level() { - 40| | if false { - 41| | func(3); - 42| | } - 43| | } - 44| |} \ No newline at end of file + 1| 1|fn func(x: i32) { + 2| 1| match x { + 3| 1| 0 => {} + 4| 0| 1 => {} + 5| 0| 2 => {} + 6| 0| 3 => {} + 7| 0| _ => {} + 8| | } + 9| 1|} + 10| | + 11| |#[coverage(off)] + 12| |#[test] + 13| |fn fn_level() { + 14| | func(0); + 15| | + 16| | if false { + 17| | func(1); + 18| | } + 19| |} + 20| | + 21| |// #[coverage(off)] has no effect on expressions. + 22| |// now error by rustc: error[E0788]: attribute should be applied to a function definition or closure + 23| |#[test] + 24| 1|fn expr_level() { + 25| 1| if false { + 26| 0| // #[coverage(off)] + 27| 0| func(2); + 28| 1| } + 29| 1|} + 30| | + 31| |#[coverage(off)] + 32| |mod mod_level { + 33| | use super::func; + 34| | + 35| | #[test] + 36| | fn mod_level() { + 37| | if false { + 38| | func(3); + 39| | } + 40| | } + 41| |} \ No newline at end of file diff --git a/tests/fixtures/coverage-reports/no_coverage/no_coverage.txt b/tests/fixtures/coverage-reports/no_coverage/no_coverage.txt index a567a193..360264ae 100644 --- a/tests/fixtures/coverage-reports/no_coverage/no_coverage.txt +++ b/tests/fixtures/coverage-reports/no_coverage/no_coverage.txt @@ -1,44 +1,41 @@ - 1| |#![cfg_attr(coverage, feature(coverage_attribute))] - 2| | - 3| 1|fn func(x: i32) { - 4| 1| match x { - 5| 1| 0 => {} - 6| 0| 1 => {} - 7| 0| 2 => {} - 8| 0| 3 => {} - 9| 0| _ => {} - 10| | } - 11| 1|} - 12| | - 13| |#[cfg_attr(coverage, coverage(off))] - 14| |#[test] - 15| |fn fn_level() { - 16| | func(0); - 17| | - 18| | if false { - 19| | func(1); - 20| | } - 21| |} - 22| | - 23| |// #[coverage(off)] has no effect on expressions. - 24| |// now error by rustc: error[E0788]: attribute should be applied to a function definition or closure - 25| |#[test] - 26| 1|fn expr_level() { - 27| 1| if false { - 28| 0| // #[cfg_attr(coverage, coverage(off))] - 29| 0| func(2); - 30| 1| } - 31| 1|} - 32| | - 33| |// #[coverage(off)] has no effect on modules. - 34| |#[cfg_attr(coverage, coverage(off))] - 35| |mod mod_level { - 36| | use super::func; - 37| | - 38| | #[test] - 39| | fn mod_level() { - 40| | if false { - 41| | func(3); - 42| | } - 43| | } - 44| |} \ No newline at end of file + 1| 1|fn func(x: i32) { + 2| 1| match x { + 3| 1| 0 => {} + 4| 0| 1 => {} + 5| 0| 2 => {} + 6| 0| 3 => {} + 7| 0| _ => {} + 8| | } + 9| 1|} + 10| | + 11| |#[coverage(off)] + 12| |#[test] + 13| |fn fn_level() { + 14| | func(0); + 15| | + 16| | if false { + 17| | func(1); + 18| | } + 19| |} + 20| | + 21| |// #[coverage(off)] has no effect on expressions. + 22| |// now error by rustc: error[E0788]: attribute should be applied to a function definition or closure + 23| |#[test] + 24| 1|fn expr_level() { + 25| 1| if false { + 26| 0| // #[coverage(off)] + 27| 0| func(2); + 28| 1| } + 29| 1|} + 30| | + 31| |#[coverage(off)] + 32| |mod mod_level { + 33| | use super::func; + 34| | + 35| | #[test] + 36| | fn mod_level() { + 37| | if false { + 38| | func(3); + 39| | } + 40| | } + 41| |} \ No newline at end of file diff --git a/tests/fixtures/crates/coverage_helper/src/lib.rs b/tests/fixtures/crates/coverage_helper/src/lib.rs index e9720569..73e898ce 100644 --- a/tests/fixtures/crates/coverage_helper/src/lib.rs +++ b/tests/fixtures/crates/coverage_helper/src/lib.rs @@ -1,5 +1,3 @@ -#![cfg_attr(coverage_nightly, feature(coverage_attribute))] - use coverage_helper::test; fn func(x: i32) { diff --git a/tests/fixtures/crates/no_coverage/src/lib.rs b/tests/fixtures/crates/no_coverage/src/lib.rs index 80b9d6eb..b00ebc0c 100644 --- a/tests/fixtures/crates/no_coverage/src/lib.rs +++ b/tests/fixtures/crates/no_coverage/src/lib.rs @@ -1,5 +1,3 @@ -#![cfg_attr(coverage, feature(coverage_attribute))] - fn func(x: i32) { match x { 0 => {} @@ -10,7 +8,7 @@ fn func(x: i32) { } } -#[cfg_attr(coverage, coverage(off))] +#[coverage(off)] #[test] fn fn_level() { func(0); @@ -25,13 +23,12 @@ fn fn_level() { #[test] fn expr_level() { if false { - // #[cfg_attr(coverage, coverage(off))] + // #[coverage(off)] func(2); } } -// #[coverage(off)] has no effect on modules. -#[cfg_attr(coverage, coverage(off))] +#[coverage(off)] mod mod_level { use super::func; diff --git a/tests/test.rs b/tests/test.rs index 876c4a7d..29917d9c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -121,8 +121,8 @@ fn cargo_config() { run("cargo_config_toml", "cargo_config_toml", &[], &[]); } -// feature(coverage_attribute) requires nightly -#[rustversion::attr(not(nightly), ignore)] +// coverage(off) requires Rust 1.85 +#[rustversion::attr(before(1.85), ignore)] #[test] fn no_coverage() { let model = "no_coverage"; @@ -144,8 +144,8 @@ fn no_coverage() { } } -// feature(coverage_attribute) requires nightly -#[rustversion::attr(not(nightly), ignore)] +// coverage(off) requires Rust 1.85 +#[rustversion::attr(before(1.85), ignore)] #[test] fn coverage_helper() { let model = "coverage_helper";