Skip to content

Commit

Permalink
Fix ignore-filename-regex for tests/examples/benches
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jul 7, 2022
1 parent 4dffb10 commit 2778129
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 115 deletions.
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,6 @@ fn ignore_filename_regex(cx: &Context) -> Option<String> {
#[cfg(windows)]
const SEPARATOR: &str = "\\\\"; // On windows, we should escape the separator.

fn default_ignore_filename_regex() -> String {
// TODO: Should we use the actual target path instead of using `tests|examples|benches`?
// We may have a directory like tests/support, so maybe we need both?
format!(r"(^|{0})(rustc{0}[0-9a-f]+|tests|examples|benches){0}", SEPARATOR)
}

#[derive(Default)]
struct Out(String);

Expand All @@ -830,7 +824,17 @@ fn ignore_filename_regex(cx: &Context) -> Option<String> {
out.push(ignore_filename);
}
if !cx.cov.disable_default_ignore_filename_regex {
out.push(default_ignore_filename_regex());
// TODO: Should we use the actual target path instead of using `tests|examples|benches`?
// We may have a directory like tests/support, so maybe we need both?
if cx.build.remap_path_prefix {
out.push(format!(r"(^|{0})(rustc{0}[0-9a-f]+|tests|examples|benches){0}", SEPARATOR));
} else {
out.push(format!(
r"{0}rustc{0}[0-9a-f]+{0}|^{1}({0}.*)?{0}(tests|examples|benches){0}",
SEPARATOR,
regex::escape(cx.ws.metadata.workspace_root.as_str())
));
}
out.push_abs_path(&cx.ws.target_dir);
if cx.build.remap_path_prefix {
for path in [home::home_dir(), home::cargo_home().ok(), home::rustup_home().ok()]
Expand Down
54 changes: 29 additions & 25 deletions tests/fixtures/coverage-reports/real1/all.hide-instantiations.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
member1/member2/src/lib.rs:
1| 1|pub fn func(x: u32) {pub fn func(x: u32) {
2| 1| match x {
3| 1| 0 => {}
1| 2|pub fn func(x: u32) {pub fn func(x: u32) {
^1
2| 2| match x {
3| 2| 0 => {}
4| 0| 1 => {}
5| 0| 2 => {}
6| 0| _ => {}
7| | }
8| 1|}
8| 2|}

member1/src/lib.rs:
1| 1|pub fn func(x: u32) {pub fn func(x: u32) {
2| 1| match x {
3| 1| 0 => {}
4| 0| 1 => {}
5| 0| 2 => {}
6| 0| _ => {}
7| | }
8| 1|}

src/lib.rs:
1| 2|pub fn func(x: u32) {pub fn func(x: u32) {
^1
2| 2| match x {
3| 0| 0 => {}
4| 1| 1 => {}
3| 2| 0 => {}
4| 0| 1 => {}
5| 0| 2 => {}
6| 1| _ => {}
6| 0| _ => {}
7| | }
8| 2|}
9| |
10| 1|#[test]
11| 1|fn test() {
12| 1| func(1);
13| 1| func(3);
14| 1| member1::func(0);
15| 1| member2::func(0);
16| 1|}

src/lib.rs:
1| 1|#[cfg(test)]#[cfg(test)]
2| |mod tests;
3| |
4| 4|pub fn func(x: u32) {
5| 4| match x {
6| 0| 0 => {}
7| 2| 1 => {}
8| 0| 2 => {}
9| 2| _ => {}
10| | }
11| 4|}
12| |
13| 1|#[test]
14| 1|fn test() {
15| 1| func(1);
16| 1| func(3);
17| 1| member1::func(0);
18| 1| member2::func(0);
19| 1|}
70 changes: 37 additions & 33 deletions tests/fixtures/coverage-reports/real1/all.txt
Original file line number Diff line number Diff line change
@@ -1,64 +1,68 @@
member1/member2/src/lib.rs:
1| 1|pub fn func(x: u32) {pub fn func(x: u32) {
2| 1| match x {
3| 1| 0 => {}
1| 2|pub fn func(x: u32) {pub fn func(x: u32) {
^1
2| 2| match x {
3| 2| 0 => {}
4| 0| 1 => {}
5| 0| 2 => {}
6| 0| _ => {}
7| | }
8| 1|}
8| 2|}
------------------
| member2::func:
| 1| 1|pub fn func(x: u32) {
| 2| 1| match x {
| 3| 1| 0 => {}
| 1| 2|pub fn func(x: u32) {
| 2| 2| match x {
| 3| 2| 0 => {}
| 4| 0| 1 => {}
| 5| 0| 2 => {}
| 6| 0| _ => {}
| 7| | }
| 8| 1|}
| 8| 2|}
------------------
| Unexecuted instantiation: member2::func
------------------

member1/src/lib.rs:
1| 1|pub fn func(x: u32) {pub fn func(x: u32) {
2| 1| match x {
3| 1| 0 => {}
1| 2|pub fn func(x: u32) {pub fn func(x: u32) {
^1
2| 2| match x {
3| 2| 0 => {}
4| 0| 1 => {}
5| 0| 2 => {}
6| 0| _ => {}
7| | }
8| 1|}
8| 2|}
------------------
| member1::func:
| 1| 1|pub fn func(x: u32) {
| 2| 1| match x {
| 3| 1| 0 => {}
| 1| 2|pub fn func(x: u32) {
| 2| 2| match x {
| 3| 2| 0 => {}
| 4| 0| 1 => {}
| 5| 0| 2 => {}
| 6| 0| _ => {}
| 7| | }
| 8| 1|}
| 8| 2|}
------------------
| Unexecuted instantiation: member1::func
------------------

src/lib.rs:
1| 2|pub fn func(x: u32) {pub fn func(x: u32) {
^1
2| 2| match x {
3| 0| 0 => {}
4| 1| 1 => {}
5| 0| 2 => {}
6| 1| _ => {}
7| | }
8| 2|}
9| |
10| 1|#[test]
11| 1|fn test() {
12| 1| func(1);
13| 1| func(3);
14| 1| member1::func(0);
15| 1| member2::func(0);
16| 1|}
1| 1|#[cfg(test)]#[cfg(test)]
2| |mod tests;
3| |
4| 4|pub fn func(x: u32) {
5| 4| match x {
6| 0| 0 => {}
7| 2| 1 => {}
8| 0| 2 => {}
9| 2| _ => {}
10| | }
11| 4|}
12| |
13| 1|#[test]
14| 1|fn test() {
15| 1| func(1);
16| 1| func(3);
17| 1| member1::func(0);
18| 1| member2::func(0);
19| 1|}
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
member1/member2/src/lib.rs:
1| 1|pub fn func(x: u32) {
2| 1| match x {
3| 1| 0 => {}
1| 2|pub fn func(x: u32) {
2| 2| match x {
3| 2| 0 => {}
4| 0| 1 => {}
5| 0| 2 => {}
6| 0| _ => {}
7| | }
8| 1|}
8| 2|}

member1/src/lib.rs:
1| 1|pub fn func(x: u32) {
2| 1| match x {
3| 1| 0 => {}
1| 2|pub fn func(x: u32) {
2| 2| match x {
3| 2| 0 => {}
4| 0| 1 => {}
5| 0| 2 => {}
6| 0| _ => {}
7| | }
8| 1|}
8| 2|}

src/lib.rs:
1| 2|pub fn func(x: u32) {pub fn func(x: u32) {
^1
2| 2| match x {
3| 0| 0 => {}
4| 1| 1 => {}
5| 0| 2 => {}
6| 1| _ => {}
7| | }
8| 2|}
9| |
10| 1|#[test]
11| 1|fn test() {
12| 1| func(1);
13| 1| func(3);
14| 1| member1::func(0);
15| 1| member2::func(0);
16| 1|}
1| 1|#[cfg(test)]#[cfg(test)]
2| |mod tests;
3| |
4| 4|pub fn func(x: u32) {
5| 4| match x {
6| 0| 0 => {}
7| 2| 1 => {}
8| 0| 2 => {}
9| 2| _ => {}
10| | }
11| 4|}
12| |
13| 1|#[test]
14| 1|fn test() {
15| 1| func(1);
16| 1| func(3);
17| 1| member1::func(0);
18| 1| member2::func(0);
19| 1|}
52 changes: 27 additions & 25 deletions tests/fixtures/coverage-reports/real1/workspace_root.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
member1/member2/src/lib.rs:
1| 1|pub fn func(x: u32) {
2| 1| match x {
3| 1| 0 => {}
1| 2|pub fn func(x: u32) {
2| 2| match x {
3| 2| 0 => {}
4| 0| 1 => {}
5| 0| 2 => {}
6| 0| _ => {}
7| | }
8| 1|}
8| 2|}

member1/src/lib.rs:
1| 1|pub fn func(x: u32) {
2| 1| match x {
3| 1| 0 => {}
1| 2|pub fn func(x: u32) {
2| 2| match x {
3| 2| 0 => {}
4| 0| 1 => {}
5| 0| 2 => {}
6| 0| _ => {}
7| | }
8| 1|}
8| 2|}

src/lib.rs:
1| 2|pub fn func(x: u32) {pub fn func(x: u32) {
^1
2| 2| match x {
3| 0| 0 => {}
4| 1| 1 => {}
5| 0| 2 => {}
6| 1| _ => {}
7| | }
8| 2|}
9| |
10| 1|#[test]
11| 1|fn test() {
12| 1| func(1);
13| 1| func(3);
14| 1| member1::func(0);
15| 1| member2::func(0);
16| 1|}
1| 1|#[cfg(test)]#[cfg(test)]
2| |mod tests;
3| |
4| 4|pub fn func(x: u32) {
5| 4| match x {
6| 0| 0 => {}
7| 2| 1 => {}
8| 0| 2 => {}
9| 2| _ => {}
10| | }
11| 4|}
12| |
13| 1|#[test]
14| 1|fn test() {
15| 1| func(1);
16| 1| func(3);
17| 1| member1::func(0);
18| 1| member2::func(0);
19| 1|}
3 changes: 3 additions & 0 deletions tests/fixtures/crates/real1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(test)]
mod tests;

pub fn func(x: u32) {
match x {
0 => {}
Expand Down
15 changes: 15 additions & 0 deletions tests/fixtures/crates/real1/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// src/tests is a well-known pattern: https://grep.app/search?q=%23%5Btest%5D&filter[path][0]=src/tests/&filter[lang][0]=Rust
//
// Note that to check that this pattern is properly supported,
// you need to run cargo-llvm-cov without --remap-path-prefix flag.
// (Our test suite always enables that flag.)

use super::*;

#[test]
fn test() {
func(1);
func(3);
member1::func(0);
member2::func(0);
}

0 comments on commit 2778129

Please sign in to comment.