use crate::util::{Dir, TestCommand};
const HAY: &'static [u8] = include_bytes!("./data/sherlock-nul.txt");
#[cfg(not(target_os = "macos"))]
rgtest!(mmap_match_implicit, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--mmap", "-n", "Project Gutenberg EBook", "-g", "hay"]);
let expected = "\
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
";
eqnice!(expected, cmd.stdout());
});
#[cfg(not(target_os = "macos"))]
rgtest!(mmap_match_explicit, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--mmap", "-n", "Project Gutenberg EBook", "hay"]);
let expected = "\
1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
";
eqnice!(expected, cmd.stdout());
});
#[cfg(not(target_os = "macos"))]
rgtest!(mmap_match_near_nul, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--mmap", "-n", "abcdef", "hay"]);
let expected = "\
binary file matches (found \"\\0\" byte around offset 77041)
";
eqnice!(expected, cmd.stdout());
});
#[cfg(not(target_os = "macos"))]
rgtest!(mmap_match_count, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--mmap", "-c", "Project Gutenberg EBook|Heaven", "hay"]);
eqnice!("2\n", cmd.stdout());
});
#[cfg(not(target_os = "macos"))]
rgtest!(mmap_match_multiple, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--mmap", "-n", "Project Gutenberg EBook|Heaven", "hay"]);
let expected = "\
1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
1871:\"No. Heaven knows what the objects of his studies are. But here we
";
eqnice!(expected, cmd.stdout());
});
#[cfg(not(target_os = "macos"))]
rgtest!(mmap_binary_flag, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--mmap", "-n", "--binary", "Heaven", "-g", "hay"]);
let expected = "\
hay:1871:\"No. Heaven knows what the objects of his studies are. But here we
";
eqnice!(expected, cmd.stdout());
});
#[cfg(not(target_os = "macos"))]
rgtest!(mmap_text_flag, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--mmap", "-n", "--text", "Heaven", "-g", "hay"]);
let expected = "\
hay:1871:\"No. Heaven knows what the objects of his studies are. But here we
";
eqnice!(expected, cmd.stdout());
});
#[cfg(not(target_os = "macos"))]
rgtest!(mmap_after_nul_match, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--mmap", "-n", "medical student", "hay"]);
let expected = "\
176:\"A medical student, I suppose?\" said I.
409:\"A medical student, I suppose?\" said I.
642:\"A medical student, I suppose?\" said I.
875:\"A medical student, I suppose?\" said I.
1108:\"A medical student, I suppose?\" said I.
1341:\"A medical student, I suppose?\" said I.
1574:\"A medical student, I suppose?\" said I.
1807:\"A medical student, I suppose?\" said I.
1867:\"And yet you say he is not a medical student?\"
";
eqnice!(expected, cmd.stdout());
});
rgtest!(after_match1_implicit, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "Project Gutenberg EBook", "-g", "hay"]);
let expected = "\
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
hay: WARNING: stopped searching binary file after match (found \"\\0\" byte around offset 77041)
";
eqnice!(expected, cmd.stdout());
});
rgtest!(after_match1_explicit, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "Project Gutenberg EBook", "hay"]);
let expected = "\
1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
binary file matches (found \"\\0\" byte around offset 77041)
";
eqnice!(expected, cmd.stdout());
});
rgtest!(after_match1_stdin, |_: Dir, mut cmd: TestCommand| {
cmd.args(&["--no-mmap", "-n", "Project Gutenberg EBook"]);
let expected = "\
1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
binary file matches (found \"\\0\" byte around offset 77041)
";
eqnice!(expected, cmd.pipe(HAY));
});
rgtest!(after_match1_implicit_binary, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&[
"--no-mmap",
"-n",
"--binary",
"Project Gutenberg EBook",
"-g",
"hay",
]);
let expected = "\
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
hay: binary file matches (found \"\\0\" byte around offset 77041)
";
eqnice!(expected, cmd.stdout());
});
rgtest!(after_match1_implicit_text, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&[
"--no-mmap",
"-n",
"--text",
"Project Gutenberg EBook",
"-g",
"hay",
]);
let expected = "\
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
";
eqnice!(expected, cmd.stdout());
});
rgtest!(after_match1_explicit_text, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "--text", "Project Gutenberg EBook", "hay"]);
let expected = "\
1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
";
eqnice!(expected, cmd.stdout());
});
rgtest!(after_match1_implicit_path, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-l", "Project Gutenberg EBook", "-g", "hay"]);
eqnice!("hay\n", cmd.stdout());
});
rgtest!(after_match1_implicit_quiet, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-q", "Project Gutenberg EBook", "-g", "hay"]);
eqnice!("", cmd.stdout());
});
rgtest!(after_match1_implicit_count, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-c", "Project Gutenberg EBook", "-g", "hay"]);
cmd.assert_err();
});
rgtest!(
after_match1_implicit_count_binary,
|dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&[
"--no-mmap",
"-c",
"--binary",
"Project Gutenberg EBook",
"-g",
"hay",
]);
eqnice!("hay:1\n", cmd.stdout());
}
);
rgtest!(after_match1_explicit_count, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-c", "Project Gutenberg EBook", "hay"]);
eqnice!("1\n", cmd.stdout());
});
rgtest!(after_match2_implicit, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&[
"--no-mmap",
"-n",
"Project Gutenberg EBook|a medical student",
"-g",
"hay",
]);
let expected = "\
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
hay: WARNING: stopped searching binary file after match (found \"\\0\" byte around offset 77041)
";
eqnice!(expected, cmd.stdout());
});
rgtest!(after_match2_implicit_text, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&[
"--no-mmap",
"-n",
"--text",
"Project Gutenberg EBook|a medical student",
"-g",
"hay",
]);
let expected = "\
hay:1:The Project Gutenberg EBook of A Study In Scarlet, by Arthur Conan Doyle
hay:1867:\"And yet you say he is not a medical student?\"
";
eqnice!(expected, cmd.stdout());
});
rgtest!(before_match1_implicit, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "Heaven", "-g", "hay"]);
cmd.assert_err();
});
rgtest!(before_match1_explicit, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "Heaven", "hay"]);
let expected = "\
binary file matches (found \"\\0\" byte around offset 77041)
";
eqnice!(expected, cmd.stdout());
});
rgtest!(before_match1_implicit_binary, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "--binary", "Heaven", "-g", "hay"]);
let expected = "\
hay: binary file matches (found \"\\0\" byte around offset 77041)
";
eqnice!(expected, cmd.stdout());
});
rgtest!(before_match1_implicit_text, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "--text", "Heaven", "-g", "hay"]);
let expected = "\
hay:1871:\"No. Heaven knows what the objects of his studies are. But here we
";
eqnice!(expected, cmd.stdout());
});
rgtest!(before_match2_implicit, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "a medical student", "-g", "hay"]);
cmd.assert_err();
});
rgtest!(before_match2_explicit, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "a medical student", "hay"]);
let expected = "\
binary file matches (found \"\\0\" byte around offset 77041)
";
eqnice!(expected, cmd.stdout());
});
rgtest!(before_match2_implicit_text, |dir: Dir, mut cmd: TestCommand| {
dir.create_bytes("hay", HAY);
cmd.args(&["--no-mmap", "-n", "--text", "a medical student", "-g", "hay"]);
let expected = "\
hay:1867:\"And yet you say he is not a medical student?\"
";
eqnice!(expected, cmd.stdout());
});
rgtest!(
matching_files_inconsistent_with_count,
|dir: Dir, _cmd: TestCommand| {
let mut file1 = String::new();
file1.push_str("cat here\n");
for _ in 0..150_000 {
file1.push_str("padding line\n");
}
file1.push_str("\x00");
dir.create("file1.txt", &file1);
dir.create("file2.txt", "cat here");
let got = dir.command().args(&["--sort=path", "-l", "cat"]).stdout();
eqnice!("file1.txt\nfile2.txt\n", got);
let got = dir.command().args(&["--sort=path", "-c", "cat"]).stdout();
eqnice!("file2.txt:1\n", got);
let got = dir
.command()
.args(&["--sort=path", "-c", "cat", "--binary"])
.stdout();
eqnice!("file1.txt:1\nfile2.txt:1\n", got);
let got = dir
.command()
.args(&["--sort=path", "-c", "cat", "--text"])
.stdout();
eqnice!("file1.txt:1\nfile2.txt:1\n", got);
}
);