diff options
| author | bors <bors@rust-lang.org> | 2023-11-08 03:00:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-08 03:00:14 +0000 |
| commit | 91cfcb021935853caa06698b759c293c09d1e96a (patch) | |
| tree | d5dd983288727ef2905faaea5636e416ac86766e /tests/coverage/no_cov_crate.rs | |
| parent | 0d5ec963bb9f3e481bca1d0149d26f1688784341 (diff) | |
| parent | 4e6f438d2ace2f5297cea2d3e331c6dccd4e18c2 (diff) | |
| download | rust-91cfcb021935853caa06698b759c293c09d1e96a.tar.gz rust-91cfcb021935853caa06698b759c293c09d1e96a.zip | |
Auto merge of #117484 - Zalathar:tests, r=cjgillot
coverage: Unify `tests/coverage-map` and `tests/run-coverage` into `tests/coverage` Ever since the introduction of the `coverage-map` suite, it's been awkward to have to manage two separate coverage test directories containing dozens of mostly-identical files. However, those two suites were separate for good reasons. They have very different requirements (since only one of them requires actually running the test program), running only one suite is noticeably faster than running both, and having separate suites allows them to be blessed separately if desired. So while unifying them was an obvious idea, actually doing so was non-trivial. --- Nevertheless, this PR finds a way to merge the two suites into one directory while retaining almost all of the developer-experience benefits of having two suites. This required non-trivial implementations of `Step`, but the end result works very smoothly. --- The first 5 commits are a copy of #117340, which has been closed in favour of this PR.
Diffstat (limited to 'tests/coverage/no_cov_crate.rs')
| -rw-r--r-- | tests/coverage/no_cov_crate.rs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/coverage/no_cov_crate.rs b/tests/coverage/no_cov_crate.rs new file mode 100644 index 00000000000..e12e4bc55e3 --- /dev/null +++ b/tests/coverage/no_cov_crate.rs @@ -0,0 +1,88 @@ +// Enables `coverage(off)` on the entire crate +#![feature(coverage_attribute)] + +#[coverage(off)] +fn do_not_add_coverage_1() { + println!("called but not covered"); +} + +fn do_not_add_coverage_2() { + #![coverage(off)] + println!("called but not covered"); +} + +#[coverage(off)] +#[allow(dead_code)] +fn do_not_add_coverage_not_called() { + println!("not called and not covered"); +} + +fn add_coverage_1() { + println!("called and covered"); +} + +fn add_coverage_2() { + println!("called and covered"); +} + +#[allow(dead_code)] +fn add_coverage_not_called() { + println!("not called but covered"); +} + +// FIXME: These test-cases illustrate confusing results of nested functions. +// See https://github.com/rust-lang/rust/issues/93319 +mod nested_fns { + #[coverage(off)] + pub fn outer_not_covered(is_true: bool) { + fn inner(is_true: bool) { + if is_true { + println!("called and covered"); + } else { + println!("absolutely not covered"); + } + } + println!("called but not covered"); + inner(is_true); + } + + pub fn outer(is_true: bool) { + println!("called and covered"); + inner_not_covered(is_true); + + #[coverage(off)] + fn inner_not_covered(is_true: bool) { + if is_true { + println!("called but not covered"); + } else { + println!("absolutely not covered"); + } + } + } + + pub fn outer_both_covered(is_true: bool) { + println!("called and covered"); + inner(is_true); + + fn inner(is_true: bool) { + if is_true { + println!("called and covered"); + } else { + println!("absolutely not covered"); + } + } + } +} + +fn main() { + let is_true = std::env::args().len() == 1; + + do_not_add_coverage_1(); + do_not_add_coverage_2(); + add_coverage_1(); + add_coverage_2(); + + nested_fns::outer_not_covered(is_true); + nested_fns::outer(is_true); + nested_fns::outer_both_covered(is_true); +} |
