diff options
author | Jon Surrell <jon.surrell@automattic.com> | 2018-06-19 13:41:44 +0200 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2018-06-19 07:41:44 -0400 |
commit | ca23a170f769f59e5bde02a4ab32b54cd2d66165 (patch) | |
tree | 19017dc22d4656544be76939c8f940da787572bd /tests | |
parent | 223d7d9846bff4a9aaf6ba84f5662a1ee7ffa900 (diff) |
ripgrep: use exit code 2 to indicate error
Exit code 1 was shared to indicate both "no results" and "error." Use
status code 2 to indicate errors, similar to grep's behavior.
Fixes #948
PR #954
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests.rs | 30 | ||||
-rw-r--r-- | tests/workdir.rs | 37 |
2 files changed, 58 insertions, 9 deletions
diff --git a/tests/tests.rs b/tests/tests.rs index 0ee4995b..f3cc8f06 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -2191,3 +2191,33 @@ fn type_list() { // This can change over time, so just make sure we print something. assert!(!lines.is_empty()); } + +// See: https://github.com/BurntSushi/ripgrep/issues/948 +sherlock!( + exit_code_match_success, + ".", + ".", + |wd: WorkDir, mut cmd: Command| { + wd.assert_exit_code(0, &mut cmd); + } +); + +// See: https://github.com/BurntSushi/ripgrep/issues/948 +sherlock!( + exit_code_no_match, + "6d28e48b5224a42b167e{10}", + ".", + |wd: WorkDir, mut cmd: Command| { + wd.assert_exit_code(1, &mut cmd); + } +); + +// See: https://github.com/BurntSushi/ripgrep/issues/948 +sherlock!( + exit_code_error, + "*", + ".", + |wd: WorkDir, mut cmd: Command| { + wd.assert_exit_code(2, &mut cmd); + } +); diff --git a/tests/workdir.rs b/tests/workdir.rs index 3c47e948..99f0bf3f 100644 --- a/tests/workdir.rs +++ b/tests/workdir.rs @@ -261,18 +261,37 @@ impl WorkDir { pub fn assert_err(&self, cmd: &mut process::Command) { let o = cmd.output().unwrap(); if o.status.success() { - panic!("\n\n===== {:?} =====\n\ - command succeeded but expected failure!\ - \n\ncwd: {}\ - \n\nstatus: {}\ - \n\nstdout: {}\n\nstderr: {}\ - \n\n=====\n", - cmd, self.dir.display(), o.status, - String::from_utf8_lossy(&o.stdout), - String::from_utf8_lossy(&o.stderr)); + panic!( + "\n\n===== {:?} =====\n\ + command succeeded but expected failure!\ + \n\ncwd: {}\ + \n\nstatus: {}\ + \n\nstdout: {}\n\nstderr: {}\ + \n\n=====\n", + cmd, + self.dir.display(), + o.status, + String::from_utf8_lossy(&o.stdout), + String::from_utf8_lossy(&o.stderr) + ); } } + /// Runs the given command and asserts that its exit code matches expected exit code. + pub fn assert_exit_code(&self, expected_code: i32, cmd: &mut process::Command) { + let code = cmd.status().unwrap().code().unwrap(); + + assert_eq!( + expected_code, code, + "\n\n===== {:?} =====\n\ + expected exit code did not match\ + \n\nexpected: {}\ + \n\nfound: {}\ + \n\n=====\n", + cmd, expected_code, code + ); + } + /// Runs the given command and asserts that something was printed to /// stderr. pub fn assert_non_empty_stderr(&self, cmd: &mut process::Command) { |