Why does ignore crate behaviors differently by walking and matching paths individually? #3128
-
Hey, I'm using the Filesystem structure: ignore-test-fs/
├── .gitignore
└── target/
└── file.txt .gitignore content /target tests #[cfg(test)]
mod tests {
use ignore::{Walk, gitignore::Gitignore};
#[test]
fn ignore_by_walking() {
assert_eq!(Walk::new("./ignore-test-fs").count(), 1);
}
#[test]
fn ignore_by_matching() {
let (gi, _) = Gitignore::new("./ignore-test-fs/.gitignore");
assert!(gi.matched("./ignore-test-fs/target", true).is_ignore());
assert!(
gi.matched("./ignore-test-fs/target/file.txt", false)
.is_ignore()
);
}
} output: running 2 tests
test application::ignore::tests::ignore_by_walking ... ok
test application::ignore::tests::ignore_by_matching ... FAILED The If I edit the .gitignore file to the example below, all tests pass correctly: /target
/target/* I started a discussion because I understand this crate was specifically created for ripgrep and I'm using it out of context, but is this intended behavior for the Gitignore matcher or a bug? The crate version is 0.4.23. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In the future, please provide a more straight-forward MRE. And in particular, you don't include output that shows how your test failed. Just that it did. For example:
And then:
And then finally:
That's what an MRE looks like. It provides complete information as to how the test has been set up and executed. And it shows the output that I see, which lets you compare it against what you see. The goal of an MRE is to eliminate as much guesswork as possible. Notice, for example, that both tests fail for me. That's because my example is outside of a git repository, and #[cfg(test)]
mod tests {
use ignore::{gitignore::Gitignore, WalkBuilder};
#[test]
fn ignore_by_walking() {
assert_eq!(
WalkBuilder::new("./ignore-test-fs")
.require_git(false)
.build()
.count(),
1
);
}
#[test]
fn ignore_by_matching() {
let (gi, _) = Gitignore::new("./ignore-test-fs/.gitignore");
assert!(gi.matched("./ignore-test-fs/target", true).is_ignore());
assert!(gi
.matched("./ignore-test-fs/target/file.txt", false)
.is_ignore());
}
} Now I get:
Now that I can actually see the test failure, the problem is much more obvious to me: the walker is ignoring The |
Beta Was this translation helpful? Give feedback.
In the future, please provide a more straight-forward MRE. And in particular, you don't include output that shows how your test failed. Just that it did. For example:
And then: