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

Improve ignore-filename-regex heuristic #191

Merged
merged 1 commit into from
Jul 7, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Fix an issue where some files were incorrectly ignored in reports. ([#191](https://github.com/taiki-e/cargo-llvm-cov/pull/191))

## [0.4.8] - 2022-06-16

- Correctly escape regular expressions passed to `-ignore-filename-regex`. ([#188](https://github.com/taiki-e/cargo-llvm-cov/pull/188), thanks @rhysd)
Expand Down
35 changes: 20 additions & 15 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,20 +824,31 @@ 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());
out.push_abs_path(&cx.ws.target_dir);
// 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 {
for path in [home::home_dir(), home::cargo_home().ok(), home::rustup_home().ok()]
.iter()
.flatten()
{
out.push_abs_path(path);
}
out.push(format!(r"(^|{0})(rustc{0}[0-9a-f]+|tests|examples|benches){0}", SEPARATOR));
} else {
for path in [home::cargo_home().ok(), home::rustup_home().ok()].iter().flatten() {
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 {
if let Some(path) = home::home_dir() {
out.push_abs_path(path);
}
}
if let Ok(path) = home::cargo_home() {
let path = regex::escape(path.as_os_str().to_string_lossy().as_ref());
let path = format!("^{1}{0}(registry|git){0}", SEPARATOR, path);
out.push(path);
}
if let Ok(path) = home::rustup_home() {
out.push_abs_path(path.join("toolchains"));
}
for path in resolve_excluded_paths(cx) {
out.push_abs_path(path);
}
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);
}