summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-10-11 19:57:09 -0400
committerAndrew Gallant <jamslam@gmail.com>2016-10-29 20:48:59 -0400
commitd79add341ba4be10bb3459877318b9c5a30f5db3 (patch)
treea6c5222c63d53522635bc847c6ac2cf2e000ff7f /tests
parent12b2b1f6242e0c9082e93111ffef24a93fea5f6e (diff)
Move all gitignore matching to separate crate.
This PR introduces a new sub-crate, `ignore`, which primarily provides a fast recursive directory iterator that respects ignore files like gitignore and other configurable filtering rules based on globs or even file types. This results in a substantial source of complexity moved out of ripgrep's core and into a reusable component that others can now (hopefully) benefit from. While much of the ignore code carried over from ripgrep's core, a substantial portion of it was rewritten with the following goals in mind: 1. Reuse matchers built from gitignore files across directory iteration. 2. Design the matcher data structure to be amenable for parallelizing directory iteration. (Indeed, writing the parallel iterator is the next step.) Fixes #9, #44, #45
Diffstat (limited to 'tests')
-rw-r--r--tests/tests.rs82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
index a559045c..795c0996 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -54,6 +54,20 @@ fn path(unix: &str) -> String {
}
}
+fn paths(unix: &[&str]) -> Vec<String> {
+ let mut xs: Vec<_> = unix.iter().map(|s| path(s)).collect();
+ xs.sort();
+ xs
+}
+
+fn paths_from_stdout(stdout: String) -> Vec<String> {
+ let mut paths: Vec<_> = stdout.lines().map(|s| {
+ s.split(":").next().unwrap().to_string()
+ }).collect();
+ paths.sort();
+ paths
+}
+
fn sort_lines(lines: &str) -> String {
let mut lines: Vec<String> =
lines.trim().lines().map(|s| s.to_owned()).collect();
@@ -864,6 +878,74 @@ be, to a very large extent, the result of luck. Sherlock Holmes
assert_eq!(lines, expected);
});
+// See: https://github.com/BurntSushi/ripgrep/issues/45
+sherlock!(feature_45_relative_cwd, "test", ".",
+|wd: WorkDir, mut cmd: Command| {
+ wd.create(".not-an-ignore", "foo\n/bar");
+ wd.create_dir("bar");
+ wd.create_dir("baz/bar");
+ wd.create_dir("baz/baz/bar");
+ wd.create("bar/test", "test");
+ wd.create("baz/bar/test", "test");
+ wd.create("baz/baz/bar/test", "test");
+ wd.create("baz/foo", "test");
+ wd.create("baz/test", "test");
+ wd.create("foo", "test");
+ wd.create("test", "test");
+
+ // First, get a baseline without applying ignore rules.
+ let lines = paths_from_stdout(wd.stdout(&mut cmd));
+ assert_eq!(lines, paths(&[
+ "bar/test", "baz/bar/test", "baz/baz/bar/test", "baz/foo",
+ "baz/test", "foo", "test",
+ ]));
+
+ // Now try again with the ignore file activated.
+ cmd.arg("--ignore-file").arg(".not-an-ignore");
+ let lines = paths_from_stdout(wd.stdout(&mut cmd));
+ assert_eq!(lines, paths(&[
+ "baz/bar/test", "baz/baz/bar/test", "baz/test", "test",
+ ]));
+
+ // Now do it again, but inside the baz directory.
+ // Since the ignore file is interpreted relative to the CWD, this will
+ // cause the /bar anchored pattern to filter out baz/bar, which is a
+ // subtle difference between true parent ignore files and manually
+ // specified ignore files.
+ let mut cmd = wd.command();
+ cmd.arg("test").arg(".").arg("--ignore-file").arg("../.not-an-ignore");
+ cmd.current_dir(wd.path().join("baz"));
+ let lines = paths_from_stdout(wd.stdout(&mut cmd));
+ assert_eq!(lines, paths(&["baz/bar/test", "test"]));
+});
+
+// See: https://github.com/BurntSushi/ripgrep/issues/45
+sherlock!(feature_45_precedence_with_others, "test", ".",
+|wd: WorkDir, mut cmd: Command| {
+ wd.create(".not-an-ignore", "*.log");
+ wd.create(".ignore", "!imp.log");
+ wd.create("imp.log", "test");
+ wd.create("wat.log", "test");
+
+ cmd.arg("--ignore-file").arg(".not-an-ignore");
+ let lines: String = wd.stdout(&mut cmd);
+ assert_eq!(lines, "imp.log:test\n");
+});
+
+// See: https://github.com/BurntSushi/ripgrep/issues/45
+sherlock!(feature_45_precedence_internal, "test", ".",
+|wd: WorkDir, mut cmd: Command| {
+ wd.create(".not-an-ignore1", "*.log");
+ wd.create(".not-an-ignore2", "!imp.log");
+ wd.create("imp.log", "test");
+ wd.create("wat.log", "test");
+
+ cmd.arg("--ignore-file").arg(".not-an-ignore1");
+ cmd.arg("--ignore-file").arg(".not-an-ignore2");
+ let lines: String = wd.stdout(&mut cmd);
+ assert_eq!(lines, "imp.log:test\n");
+});
+
// See: https://github.com/BurntSushi/ripgrep/issues/68
clean!(feature_68_no_ignore_vcs, "test", ".", |wd: WorkDir, mut cmd: Command| {
wd.create(".gitignore", "foo");