Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use exit code 2 to indicate error #954

Merged
merged 5 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn main() {
Ok(_) => process::exit(0),
Err(err) => {
eprintln!("{}", err);
process::exit(1);
process::exit(2);
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
);
37 changes: 28 additions & 9 deletions tests/workdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down