mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-03 05:32:04 -07:00
Compare commits
7 Commits
ignore-0.4
...
grep-0.1.9
Author | SHA1 | Date | |
---|---|---|---|
|
0fdab0ec5e | ||
|
74ec5b8932 | ||
|
2913fc4cd0 | ||
|
7c412bb2fa | ||
|
651a0f1ddf | ||
|
45473ba48f | ||
|
0863c75a5a |
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -71,7 +71,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encoding_rs_io"
|
name = "encoding_rs_io"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"encoding_rs 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"encoding_rs 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -115,7 +115,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grep"
|
name = "grep"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -242,9 +242,9 @@ dependencies = [
|
|||||||
"bytecount 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bytecount 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"encoding_rs 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"encoding_rs 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"encoding_rs_io 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"encoding_rs_io 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"globset 0.4.1",
|
"globset 0.4.1",
|
||||||
"grep 0.1.8",
|
"grep 0.1.9",
|
||||||
"ignore 0.4.3",
|
"ignore 0.4.3",
|
||||||
"lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -254,7 +254,7 @@ dependencies = [
|
|||||||
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"termcolor 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"termcolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -287,7 +287,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "termcolor"
|
name = "termcolor"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"wincolor 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"wincolor 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -394,7 +394,7 @@ dependencies = [
|
|||||||
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
|
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
|
||||||
"checksum crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "24ce9782d4d5c53674646a6a4c1863a21a8fc0cb649b3c94dfc16e45071dea19"
|
"checksum crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "24ce9782d4d5c53674646a6a4c1863a21a8fc0cb649b3c94dfc16e45071dea19"
|
||||||
"checksum encoding_rs 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88a1b66a0d28af4b03a8c8278c6dcb90e6e600d89c14500a9e7a02e64b9ee3ac"
|
"checksum encoding_rs 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88a1b66a0d28af4b03a8c8278c6dcb90e6e600d89c14500a9e7a02e64b9ee3ac"
|
||||||
"checksum encoding_rs_io 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bcd05bae9dfcb6d689427192bdf740d92daf53ff8e4d11ae46aad626353e48a"
|
"checksum encoding_rs_io 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad0ffe753ba194ef1bc070e8d61edaadb1536c05e364fc9178ca6cbde10922c4"
|
||||||
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||||
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||||
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||||
@@ -415,7 +415,7 @@ dependencies = [
|
|||||||
"checksum simd 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ed3686dd9418ebcc3a26a0c0ae56deab0681e53fe899af91f5bbcee667ebffb1"
|
"checksum simd 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ed3686dd9418ebcc3a26a0c0ae56deab0681e53fe899af91f5bbcee667ebffb1"
|
||||||
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
||||||
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
|
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
|
||||||
"checksum termcolor 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a52c023823933499250b43960b272e25336c6e2ab8684672edc34489f049ccdd"
|
"checksum termcolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "722426c4a0539da2c4ffd9b419d90ad540b4cff4a053be9069c908d4d07e2836"
|
||||||
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||||
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
|
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
|
||||||
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
|
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "grep"
|
name = "grep"
|
||||||
version = "0.1.8" #:version
|
version = "0.1.9" #:version
|
||||||
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
Fast line oriented regex searching as a library.
|
Fast line oriented regex searching as a library.
|
||||||
|
@@ -220,6 +220,11 @@ impl Gitignore {
|
|||||||
/// determined by a common suffix of the directory containing this
|
/// determined by a common suffix of the directory containing this
|
||||||
/// gitignore) is stripped. If there is no common suffix/prefix overlap,
|
/// gitignore) is stripped. If there is no common suffix/prefix overlap,
|
||||||
/// then `path` is assumed to be relative to this matcher.
|
/// then `path` is assumed to be relative to this matcher.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This method panics if the given file path is not under the root path
|
||||||
|
/// of this matcher.
|
||||||
pub fn matched_path_or_any_parents<P: AsRef<Path>>(
|
pub fn matched_path_or_any_parents<P: AsRef<Path>>(
|
||||||
&self,
|
&self,
|
||||||
path: P,
|
path: P,
|
||||||
@@ -229,10 +234,8 @@ impl Gitignore {
|
|||||||
return Match::None;
|
return Match::None;
|
||||||
}
|
}
|
||||||
let mut path = self.strip(path.as_ref());
|
let mut path = self.strip(path.as_ref());
|
||||||
debug_assert!(
|
assert!(!path.has_root(), "path is expected to be under the root");
|
||||||
!path.has_root(),
|
|
||||||
"path is expect to be under the root"
|
|
||||||
);
|
|
||||||
match self.matched_stripped(path, is_dir) {
|
match self.matched_stripped(path, is_dir) {
|
||||||
Match::None => (), // walk up
|
Match::None => (), // walk up
|
||||||
a_match => return a_match,
|
a_match => return a_match,
|
||||||
|
@@ -1,13 +1,11 @@
|
|||||||
extern crate ignore;
|
extern crate ignore;
|
||||||
|
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use ignore::gitignore::{Gitignore, GitignoreBuilder};
|
use ignore::gitignore::{Gitignore, GitignoreBuilder};
|
||||||
|
|
||||||
|
const IGNORE_FILE: &'static str =
|
||||||
const IGNORE_FILE: &'static str = "tests/gitignore_matched_path_or_any_parents_tests.gitignore";
|
"tests/gitignore_matched_path_or_any_parents_tests.gitignore";
|
||||||
|
|
||||||
|
|
||||||
fn get_gitignore() -> Gitignore {
|
fn get_gitignore() -> Gitignore {
|
||||||
let mut builder = GitignoreBuilder::new("ROOT");
|
let mut builder = GitignoreBuilder::new("ROOT");
|
||||||
@@ -16,9 +14,8 @@ fn get_gitignore() -> Gitignore {
|
|||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "path is expect to be under the root")]
|
#[should_panic(expected = "path is expected to be under the root")]
|
||||||
fn test_path_should_be_under_root() {
|
fn test_path_should_be_under_root() {
|
||||||
let gitignore = get_gitignore();
|
let gitignore = get_gitignore();
|
||||||
let path = "/tmp/some_file";
|
let path = "/tmp/some_file";
|
||||||
@@ -26,11 +23,12 @@ fn test_path_should_be_under_root() {
|
|||||||
assert!(false);
|
assert!(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_files_in_root() {
|
fn test_files_in_root() {
|
||||||
let gitignore = get_gitignore();
|
let gitignore = get_gitignore();
|
||||||
let m = |path: &str| gitignore.matched_path_or_any_parents(Path::new(path), false);
|
let m = |path: &str| {
|
||||||
|
gitignore.matched_path_or_any_parents(Path::new(path), false)
|
||||||
|
};
|
||||||
|
|
||||||
// 0x
|
// 0x
|
||||||
assert!(m("ROOT/file_root_00").is_ignore());
|
assert!(m("ROOT/file_root_00").is_ignore());
|
||||||
@@ -61,7 +59,9 @@ fn test_files_in_root() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_files_in_deep() {
|
fn test_files_in_deep() {
|
||||||
let gitignore = get_gitignore();
|
let gitignore = get_gitignore();
|
||||||
let m = |path: &str| gitignore.matched_path_or_any_parents(Path::new(path), false);
|
let m = |path: &str| {
|
||||||
|
gitignore.matched_path_or_any_parents(Path::new(path), false)
|
||||||
|
};
|
||||||
|
|
||||||
// 0x
|
// 0x
|
||||||
assert!(m("ROOT/parent_dir/file_deep_00").is_ignore());
|
assert!(m("ROOT/parent_dir/file_deep_00").is_ignore());
|
||||||
@@ -92,8 +92,9 @@ fn test_files_in_deep() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_dirs_in_root() {
|
fn test_dirs_in_root() {
|
||||||
let gitignore = get_gitignore();
|
let gitignore = get_gitignore();
|
||||||
let m =
|
let m = |path: &str, is_dir: bool| {
|
||||||
|path: &str, is_dir: bool| gitignore.matched_path_or_any_parents(Path::new(path), is_dir);
|
gitignore.matched_path_or_any_parents(Path::new(path), is_dir)
|
||||||
|
};
|
||||||
|
|
||||||
// 00
|
// 00
|
||||||
assert!(m("ROOT/dir_root_00", true).is_ignore());
|
assert!(m("ROOT/dir_root_00", true).is_ignore());
|
||||||
@@ -196,20 +197,25 @@ fn test_dirs_in_root() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_dirs_in_deep() {
|
fn test_dirs_in_deep() {
|
||||||
let gitignore = get_gitignore();
|
let gitignore = get_gitignore();
|
||||||
let m =
|
let m = |path: &str, is_dir: bool| {
|
||||||
|path: &str, is_dir: bool| gitignore.matched_path_or_any_parents(Path::new(path), is_dir);
|
gitignore.matched_path_or_any_parents(Path::new(path), is_dir)
|
||||||
|
};
|
||||||
|
|
||||||
// 00
|
// 00
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_00", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_00", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_00/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_00/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_00/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_00/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_00/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_00/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
|
|
||||||
// 01
|
// 01
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_01", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_01", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_01/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_01/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_01/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_01/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_01/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_01/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
|
|
||||||
// 02
|
// 02
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_02", true).is_none());
|
assert!(m("ROOT/parent_dir/dir_deep_02", true).is_none());
|
||||||
@@ -251,47 +257,67 @@ fn test_dirs_in_deep() {
|
|||||||
assert!(m("ROOT/parent_dir/dir_deep_20", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_20", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_20/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_20/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_20/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_20/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_20/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_20/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
|
|
||||||
// 21
|
// 21
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_21", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_21", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_21/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_21/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_21/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_21/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_21/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_21/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
|
|
||||||
// 22
|
// 22
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_22", true).is_none()); // dir itself doesn't match
|
// dir itself doesn't match
|
||||||
|
assert!(m("ROOT/parent_dir/dir_deep_22", true).is_none());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_22/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_22/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_22/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_22/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_22/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_22/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
|
|
||||||
// 23
|
// 23
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_23", true).is_none()); // dir itself doesn't match
|
// dir itself doesn't match
|
||||||
|
assert!(m("ROOT/parent_dir/dir_deep_23", true).is_none());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_23/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_23/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_23/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_23/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_23/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_23/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
|
|
||||||
// 30
|
// 30
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_30", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_30", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_30/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_30/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_30/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_30/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_30/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_30/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
|
|
||||||
// 31
|
// 31
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_31", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_31", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_31/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_31/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_31/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_31/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_31/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_31/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
|
|
||||||
// 32
|
// 32
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_32", true).is_none()); // dir itself doesn't match
|
// dir itself doesn't match
|
||||||
|
assert!(m("ROOT/parent_dir/dir_deep_32", true).is_none());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_32/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_32/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_32/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_32/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_32/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_32/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
|
|
||||||
// 33
|
// 33
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_33", true).is_none()); // dir itself doesn't match
|
// dir itself doesn't match
|
||||||
|
assert!(m("ROOT/parent_dir/dir_deep_33", true).is_none());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_33/file", false).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_33/file", false).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_33/child_dir", true).is_ignore());
|
assert!(m("ROOT/parent_dir/dir_deep_33/child_dir", true).is_ignore());
|
||||||
assert!(m("ROOT/parent_dir/dir_deep_33/child_dir/file", false).is_ignore());
|
assert!(
|
||||||
|
m("ROOT/parent_dir/dir_deep_33/child_dir/file", false).is_ignore()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@@ -590,6 +590,7 @@ sherlock!(no_ignore_hidden, "Sherlock", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
sherlock!(ignore_git, "Sherlock", ".", |wd: WorkDir, mut cmd: Command| {
|
sherlock!(ignore_git, "Sherlock", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create_dir(".git");
|
||||||
wd.create(".gitignore", "sherlock\n");
|
wd.create(".gitignore", "sherlock\n");
|
||||||
wd.assert_err(&mut cmd);
|
wd.assert_err(&mut cmd);
|
||||||
});
|
});
|
||||||
@@ -852,6 +853,7 @@ sherlock:but Doctor Watson has to have it taken out for him and dusted,
|
|||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/16
|
// See: https://github.com/BurntSushi/ripgrep/issues/16
|
||||||
clean!(regression_16, "xyz", ".", |wd: WorkDir, mut cmd: Command| {
|
clean!(regression_16, "xyz", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create_dir(".git");
|
||||||
wd.create(".gitignore", "ghi/");
|
wd.create(".gitignore", "ghi/");
|
||||||
wd.create_dir("ghi");
|
wd.create_dir("ghi");
|
||||||
wd.create_dir("def/ghi");
|
wd.create_dir("def/ghi");
|
||||||
@@ -907,6 +909,7 @@ clean!(regression_50, "xyz", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/65
|
// See: https://github.com/BurntSushi/ripgrep/issues/65
|
||||||
clean!(regression_65, "xyz", ".", |wd: WorkDir, mut cmd: Command| {
|
clean!(regression_65, "xyz", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create_dir(".git");
|
||||||
wd.create(".gitignore", "a/");
|
wd.create(".gitignore", "a/");
|
||||||
wd.create_dir("a");
|
wd.create_dir("a");
|
||||||
wd.create("a/foo", "xyz");
|
wd.create("a/foo", "xyz");
|
||||||
@@ -916,6 +919,7 @@ clean!(regression_65, "xyz", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/67
|
// See: https://github.com/BurntSushi/ripgrep/issues/67
|
||||||
clean!(regression_67, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
clean!(regression_67, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create_dir(".git");
|
||||||
wd.create(".gitignore", "/*\n!/dir");
|
wd.create(".gitignore", "/*\n!/dir");
|
||||||
wd.create_dir("dir");
|
wd.create_dir("dir");
|
||||||
wd.create_dir("foo");
|
wd.create_dir("foo");
|
||||||
@@ -928,6 +932,7 @@ clean!(regression_67, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/87
|
// See: https://github.com/BurntSushi/ripgrep/issues/87
|
||||||
clean!(regression_87, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
clean!(regression_87, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create_dir(".git");
|
||||||
wd.create(".gitignore", "foo\n**no-vcs**");
|
wd.create(".gitignore", "foo\n**no-vcs**");
|
||||||
wd.create("foo", "test");
|
wd.create("foo", "test");
|
||||||
wd.assert_err(&mut cmd);
|
wd.assert_err(&mut cmd);
|
||||||
@@ -935,6 +940,7 @@ clean!(regression_87, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/90
|
// See: https://github.com/BurntSushi/ripgrep/issues/90
|
||||||
clean!(regression_90, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
clean!(regression_90, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create_dir(".git");
|
||||||
wd.create(".gitignore", "!.foo");
|
wd.create(".gitignore", "!.foo");
|
||||||
wd.create(".foo", "test");
|
wd.create(".foo", "test");
|
||||||
|
|
||||||
@@ -995,6 +1001,7 @@ clean!(regression_127, "Sherlock", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
// ripgrep should ignore 'foo/sherlock' giving us results only from
|
// ripgrep should ignore 'foo/sherlock' giving us results only from
|
||||||
// 'foo/watson' but on Windows ripgrep will include both 'foo/sherlock' and
|
// 'foo/watson' but on Windows ripgrep will include both 'foo/sherlock' and
|
||||||
// 'foo/watson' in the search results.
|
// 'foo/watson' in the search results.
|
||||||
|
wd.create_dir(".git");
|
||||||
wd.create(".gitignore", "foo/sherlock\n");
|
wd.create(".gitignore", "foo/sherlock\n");
|
||||||
wd.create_dir("foo");
|
wd.create_dir("foo");
|
||||||
wd.create("foo/sherlock", hay::SHERLOCK);
|
wd.create("foo/sherlock", hay::SHERLOCK);
|
||||||
@@ -1022,6 +1029,7 @@ clean!(regression_128, "x", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
// TODO(burntsushi): Darwin doesn't like this test for some reason.
|
// TODO(burntsushi): Darwin doesn't like this test for some reason.
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
clean!(regression_131, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
clean!(regression_131, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create_dir(".git");
|
||||||
wd.create(".gitignore", "TopÑapa");
|
wd.create(".gitignore", "TopÑapa");
|
||||||
wd.create("TopÑapa", "test");
|
wd.create("TopÑapa", "test");
|
||||||
wd.assert_err(&mut cmd);
|
wd.assert_err(&mut cmd);
|
||||||
@@ -1309,6 +1317,7 @@ clean!(regression_599, "^$", "input.txt", |wd: WorkDir, mut cmd: Command| {
|
|||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/807
|
// See: https://github.com/BurntSushi/ripgrep/issues/807
|
||||||
clean!(regression_807, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
clean!(regression_807, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create_dir(".git");
|
||||||
wd.create(".gitignore", ".a/b");
|
wd.create(".gitignore", ".a/b");
|
||||||
wd.create_dir(".a/b");
|
wd.create_dir(".a/b");
|
||||||
wd.create_dir(".a/c");
|
wd.create_dir(".a/c");
|
||||||
|
@@ -21,7 +21,8 @@ pub struct WorkDir {
|
|||||||
/// The directory in which this test executable is running.
|
/// The directory in which this test executable is running.
|
||||||
root: PathBuf,
|
root: PathBuf,
|
||||||
/// The directory in which the test should run. If a test needs to create
|
/// The directory in which the test should run. If a test needs to create
|
||||||
/// files, they should go in here.
|
/// files, they should go in here. This directory is also used as the CWD
|
||||||
|
/// for any processes created by the test.
|
||||||
dir: PathBuf,
|
dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,9 +32,15 @@ impl WorkDir {
|
|||||||
/// to a logical grouping of tests.
|
/// to a logical grouping of tests.
|
||||||
pub fn new(name: &str) -> WorkDir {
|
pub fn new(name: &str) -> WorkDir {
|
||||||
let id = NEXT_ID.fetch_add(1, Ordering::SeqCst);
|
let id = NEXT_ID.fetch_add(1, Ordering::SeqCst);
|
||||||
let root = env::current_exe().unwrap()
|
let root = env::current_exe()
|
||||||
.parent().expect("executable's directory").to_path_buf();
|
.unwrap()
|
||||||
let dir = root.join(TEST_DIR).join(name).join(&format!("{}", id));
|
.parent()
|
||||||
|
.expect("executable's directory")
|
||||||
|
.to_path_buf();
|
||||||
|
let dir = env::temp_dir()
|
||||||
|
.join(TEST_DIR)
|
||||||
|
.join(name)
|
||||||
|
.join(&format!("{}", id));
|
||||||
nice_err(&dir, repeat(|| fs::create_dir_all(&dir)));
|
nice_err(&dir, repeat(|| fs::create_dir_all(&dir)));
|
||||||
WorkDir {
|
WorkDir {
|
||||||
root: root,
|
root: root,
|
||||||
@@ -49,7 +56,11 @@ impl WorkDir {
|
|||||||
|
|
||||||
/// Try to create a new file with the given name and contents in this
|
/// Try to create a new file with the given name and contents in this
|
||||||
/// directory.
|
/// directory.
|
||||||
pub fn try_create<P: AsRef<Path>>(&self, name: P, contents: &str) -> io::Result<()> {
|
pub fn try_create<P: AsRef<Path>>(
|
||||||
|
&self,
|
||||||
|
name: P,
|
||||||
|
contents: &str,
|
||||||
|
) -> io::Result<()> {
|
||||||
let path = self.dir.join(name);
|
let path = self.dir.join(name);
|
||||||
self.try_create_bytes(path, contents.as_bytes())
|
self.try_create_bytes(path, contents.as_bytes())
|
||||||
}
|
}
|
||||||
@@ -70,7 +81,11 @@ impl WorkDir {
|
|||||||
|
|
||||||
/// Try to create a new file with the given name and contents in this
|
/// Try to create a new file with the given name and contents in this
|
||||||
/// directory.
|
/// directory.
|
||||||
fn try_create_bytes<P: AsRef<Path>>(&self, path: P, contents: &[u8]) -> io::Result<()> {
|
fn try_create_bytes<P: AsRef<Path>>(
|
||||||
|
&self,
|
||||||
|
path: P,
|
||||||
|
contents: &[u8],
|
||||||
|
) -> io::Result<()> {
|
||||||
let mut file = File::create(&path)?;
|
let mut file = File::create(&path)?;
|
||||||
file.write_all(contents)?;
|
file.write_all(contents)?;
|
||||||
file.flush()
|
file.flush()
|
||||||
@@ -99,28 +114,11 @@ impl WorkDir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the path to the ripgrep executable.
|
/// Returns the path to the ripgrep executable.
|
||||||
#[cfg(not(windows))]
|
|
||||||
pub fn bin(&self) -> PathBuf {
|
pub fn bin(&self) -> PathBuf {
|
||||||
let path = self.root.join("rg");
|
if cfg!(windows) {
|
||||||
if !path.is_file() {
|
|
||||||
// Looks like a recent version of Cargo changed the cwd or the
|
|
||||||
// location of the test executable.
|
|
||||||
self.root.join("../rg")
|
|
||||||
} else {
|
|
||||||
path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the path to the ripgrep executable.
|
|
||||||
#[cfg(windows)]
|
|
||||||
pub fn bin(&self) -> PathBuf {
|
|
||||||
let path = self.root.join("rg.exe");
|
|
||||||
if !path.is_file() {
|
|
||||||
// Looks like a recent version of Cargo changed the cwd or the
|
|
||||||
// location of the test executable.
|
|
||||||
self.root.join("../rg.exe")
|
self.root.join("../rg.exe")
|
||||||
} else {
|
} else {
|
||||||
path
|
self.root.join("../rg")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +188,11 @@ impl WorkDir {
|
|||||||
match stdout.parse() {
|
match stdout.parse() {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
panic!("could not convert from string: {:?}\n\n{}", err, stdout);
|
panic!(
|
||||||
|
"could not convert from string: {:?}\n\n{}",
|
||||||
|
err,
|
||||||
|
stdout
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +223,10 @@ impl WorkDir {
|
|||||||
write!(stdin, "{}", input)
|
write!(stdin, "{}", input)
|
||||||
});
|
});
|
||||||
|
|
||||||
let output = self.expect_success(cmd, child.wait_with_output().unwrap());
|
let output = self.expect_success(
|
||||||
|
cmd,
|
||||||
|
child.wait_with_output().unwrap(),
|
||||||
|
);
|
||||||
worker.join().unwrap().unwrap();
|
worker.join().unwrap().unwrap();
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
@@ -277,8 +282,13 @@ impl WorkDir {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the given command and asserts that its exit code matches expected exit code.
|
/// Runs the given command and asserts that its exit code matches expected
|
||||||
pub fn assert_exit_code(&self, expected_code: i32, cmd: &mut process::Command) {
|
/// exit code.
|
||||||
|
pub fn assert_exit_code(
|
||||||
|
&self,
|
||||||
|
expected_code: i32,
|
||||||
|
cmd: &mut process::Command,
|
||||||
|
) {
|
||||||
let code = cmd.status().unwrap().code().unwrap();
|
let code = cmd.status().unwrap().code().unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
Reference in New Issue
Block a user