summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCollin Styles <collingstyles@gmail.com>2019-10-16 19:03:00 -0700
committerAndrew Gallant <jamslam@gmail.com>2020-02-17 17:16:28 -0500
commita070722ff27c7d57d47b1766de9d253fbfe5bef9 (patch)
tree1a6370a1966bc094f22ef2d61afcb9d4c1ad6d52 /tests
parent4628d778089d0bf609462af7d5b38997fd9a014f (diff)
cli: add --include-zero flag
This flag, when used in conjunction with --count or --count-matches, will print a result for each file searched even if there were zero matches in that file. This is off by default but can be enabled to make ripgrep behave more like grep. This also clarifies some of the defaults for the grep-printer::SummaryBuilder type. Closes #1370, Closes #1405
Diffstat (limited to 'tests')
-rw-r--r--tests/misc.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/misc.rs b/tests/misc.rs
index c122f5f5..b4026702 100644
--- a/tests/misc.rs
+++ b/tests/misc.rs
@@ -392,6 +392,37 @@ rgtest!(count_matches_via_only, |dir: Dir, mut cmd: TestCommand| {
eqnice!(expected, cmd.stdout());
});
+rgtest!(include_zero, |dir: Dir, mut cmd: TestCommand| {
+ dir.create("sherlock", SHERLOCK);
+ cmd.args(&[
+ "--count",
+ "--include-zero",
+ "nada",
+ ]);
+ cmd.assert_err();
+
+ let output = cmd.cmd().output().unwrap();
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ let expected = "sherlock:0\n";
+
+ eqnice!(expected, stdout);
+});
+
+rgtest!(include_zero_override, |dir: Dir, mut cmd: TestCommand| {
+ dir.create("sherlock", SHERLOCK);
+ cmd.args(&[
+ "--count",
+ "--include-zero",
+ "--no-include-zero",
+ "nada",
+ ]);
+ cmd.assert_err();
+
+ let output = cmd.cmd().output().unwrap();
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ assert!(stdout.is_empty());
+});
+
rgtest!(files_with_matches, |dir: Dir, mut cmd: TestCommand| {
dir.create("sherlock", SHERLOCK);
cmd.arg("--files-with-matches").arg("Sherlock");