mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-25 17:21:57 -07:00
exit: tweak exit status logic
This changes how ripgrep emit exit status codes. In particular, any error that occurs while searching will now cause ripgrep to emit a `2` exit code, where as it previously would emit either a `0` or a `1` code based on whether it matched or not. That is, ripgrep would only emit a `2` exit code for a catastrophic error. This tweak includes additional logic that GNU grep adheres to, which seems like good sense. Namely, if -q/--quiet is given, and an error occurs and a match occurs, then ripgrep will emit a `0` exit code. Closes #1159
This commit is contained in:
@@ -593,10 +593,47 @@ rgtest!(r1130, |dir: Dir, mut cmd: TestCommand| {
|
||||
});
|
||||
|
||||
// See: https://github.com/BurntSushi/ripgrep/issues/1159
|
||||
rgtest!(r1159, |_: Dir, mut cmd: TestCommand| {
|
||||
rgtest!(r1159_invalid_flag, |_: Dir, mut cmd: TestCommand| {
|
||||
cmd.arg("--wat").assert_exit_code(2);
|
||||
});
|
||||
|
||||
// See: https://github.com/BurntSushi/ripgrep/issues/1159
|
||||
rgtest!(r1159_exit_status, |dir: Dir, _: TestCommand| {
|
||||
dir.create("foo", "test");
|
||||
|
||||
// search with a match gets 0 exit status.
|
||||
let mut cmd = dir.command();
|
||||
cmd.arg("test").assert_exit_code(0);
|
||||
|
||||
// search with --quiet and a match gets 0 exit status.
|
||||
let mut cmd = dir.command();
|
||||
cmd.arg("-q").arg("test").assert_exit_code(0);
|
||||
|
||||
// search with a match and an error gets 2 exit status.
|
||||
let mut cmd = dir.command();
|
||||
cmd.arg("test").arg("no-file").assert_exit_code(2);
|
||||
|
||||
// search with a match in --quiet mode and an error gets 0 exit status.
|
||||
let mut cmd = dir.command();
|
||||
cmd.arg("-q").arg("test").arg("foo").arg("no-file").assert_exit_code(0);
|
||||
|
||||
// search with no match gets 1 exit status.
|
||||
let mut cmd = dir.command();
|
||||
cmd.arg("nada").assert_exit_code(1);
|
||||
|
||||
// search with --quiet and no match gets 1 exit status.
|
||||
let mut cmd = dir.command();
|
||||
cmd.arg("-q").arg("nada").assert_exit_code(1);
|
||||
|
||||
// search with no match and an error gets 2 exit status.
|
||||
let mut cmd = dir.command();
|
||||
cmd.arg("nada").arg("no-file").assert_exit_code(2);
|
||||
|
||||
// search with no match in --quiet mode and an error gets 2 exit status.
|
||||
let mut cmd = dir.command();
|
||||
cmd.arg("-q").arg("nada").arg("foo").arg("no-file").assert_exit_code(2);
|
||||
});
|
||||
|
||||
// See: https://github.com/BurntSushi/ripgrep/issues/1163
|
||||
rgtest!(r1163, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create("bom.txt", "\u{FEFF}test123\ntest123");
|
||||
|
Reference in New Issue
Block a user