diff options
author | goto-engineering <goto@gotoengineering.io> | 2020-12-14 23:59:55 -0800 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2021-05-31 21:51:18 -0400 |
commit | e6cac8b119d0d50646b3ba1aaf53e648c779901a (patch) | |
tree | 0b878c8574bdca3eb94585654c982c323e4e452e /tests | |
parent | 0f502a9439822df41b3140d944f5d03c36144ecd (diff) |
cli: print warning if nothing was searched
This was once part of ripgrep, but at some point, was unintentionally
removed. The value of this warning is that since ripgrep tries to be
"smart" by default, it can be surprising if it doesn't search certain
things. This warning covers the case when ripgrep searches *nothing*,
which happens somewhat more frequently than you might expect. e.g., If
you're searching within an ignore directory.
Note that for now, we only print this message when the user has not
supplied any explicit paths. It's not clear that we want to print this
otherwise, and in particular, it seems that the message shows up too
eagerly. e.g., 'rg foo does-not-exist' will both print an error about
'does-not-exist' not existing, *and* the message about no files being
searched, which seems annoying in this case. We can always refine this
logic later.
Fixes #1404, Closes #1762
Diffstat (limited to 'tests')
-rw-r--r-- | tests/feature.rs | 41 | ||||
-rw-r--r-- | tests/regression.rs | 4 |
2 files changed, 44 insertions, 1 deletions
diff --git a/tests/feature.rs b/tests/feature.rs index e140fdfe..3cae7075 100644 --- a/tests/feature.rs +++ b/tests/feature.rs @@ -787,6 +787,47 @@ rgtest!(f1466_no_ignore_files, |dir: Dir, mut cmd: TestCommand| { eqnice!("foo\n", cmd.arg("-u").stdout()); }); +// See: https://github.com/BurntSushi/ripgrep/issues/1404 +rgtest!(f1404_nothing_searched_warning, |dir: Dir, mut cmd: TestCommand| { + dir.create(".ignore", "ignored-dir/**"); + dir.create_dir("ignored-dir"); + dir.create("ignored-dir/foo", "needle"); + + // Test that, if ripgrep searches only ignored folders/files, then there + // is a non-zero exit code. + cmd.arg("needle"); + cmd.assert_err(); + + // Test that we actually get an error message that we expect. + let output = cmd.cmd().output().unwrap(); + let stderr = String::from_utf8_lossy(&output.stderr); + let expected = "\ + No files were searched, which means ripgrep probably applied \ + a filter you didn't expect.\n\ + Running with --debug will show why files are being skipped.\n\ + "; + eqnice!(expected, stderr); +}); + +// See: https://github.com/BurntSushi/ripgrep/issues/1404 +rgtest!(f1404_nothing_searched_ignored, |dir: Dir, mut cmd: TestCommand| { + dir.create(".ignore", "ignored-dir/**"); + dir.create_dir("ignored-dir"); + dir.create("ignored-dir/foo", "needle"); + + // Test that, if ripgrep searches only ignored folders/files, then there + // is a non-zero exit code. + cmd.arg("--no-messages").arg("needle"); + cmd.assert_err(); + + // But since --no-messages is given, there should not be any error message + // printed. + let output = cmd.cmd().output().unwrap(); + let stderr = String::from_utf8_lossy(&output.stderr); + let expected = ""; + eqnice!(expected, stderr); +}); + rgtest!(no_context_sep, |dir: Dir, mut cmd: TestCommand| { dir.create("test", "foo\nctx\nbar\nctx\nfoo\nctx"); cmd.args(&["-A1", "--no-context-separator", "foo", "test"]); diff --git a/tests/regression.rs b/tests/regression.rs index 6e3454f6..1c2b5c15 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -392,7 +392,9 @@ rgtest!(r428_color_context_path, |dir: Dir, mut cmd: TestCommand| { }); // See: https://github.com/BurntSushi/ripgrep/issues/428 -rgtest!(r428_unrecognized_style, |_: Dir, mut cmd: TestCommand| { +rgtest!(r428_unrecognized_style, |dir: Dir, mut cmd: TestCommand| { + dir.create("file.txt", "Sherlock"); + cmd.arg("--colors=match:style:").arg("Sherlock"); cmd.assert_err(); |