Skip to content

Commit

Permalink
add run_fail_assert_exit_code as a helper
Browse files Browse the repository at this point in the history
  • Loading branch information
5225225 committed Mar 9, 2024
1 parent d3a307e commit 3bb1abb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
12 changes: 12 additions & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ impl RustcInvocationBuilder {
}
output
}

#[track_caller]
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();

let output = self.cmd.output().unwrap();
if output.status.code().unwrap() != code {
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
}
output
}
}

#[derive(Debug)]
Expand Down
12 changes: 12 additions & 0 deletions src/tools/run-make-support/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ impl RustdocInvocationBuilder {
}
output
}

#[track_caller]
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();

let output = self.cmd.output().unwrap();
if output.status.code().unwrap() != code {
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
}
output
}
}

fn setup_common_rustdoc_build_cmd() -> Command {
Expand Down
36 changes: 12 additions & 24 deletions tests/run-make/exit-code/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,35 @@ fn main() {
.arg("success.rs")
.run();

assert_eq!(rustc()
rustc()
.arg("--invalid-arg-foo")
.run_fail()
.status
.code().unwrap(), 1);
.run_fail_assert_exit_code(1);

assert_eq!(rustc()
rustc()
.arg("compile-error.rs")
.run_fail()
.status
.code().unwrap(), 1);
.run_fail_assert_exit_code(1);

assert_eq!(rustc()
rustc()
.env("RUSTC_ICE", "0")
.arg("-Ztreat-err-as-bug")
.arg("compile-error.rs")
.run_fail()
.status
.code().unwrap(), 101);
.run_fail_assert_exit_code(101);

rustdoc()
.arg("-o")
.arg_file(&tempdir().join("exit-code"))
.arg("success.rs")
.run();

assert_eq!(rustdoc()
rustdoc()
.arg("--invalid-arg-foo")
.run_fail()
.status
.code().unwrap(), 1);
.run_fail_assert_exit_code(1);

assert_eq!(rustdoc()
rustdoc()
.arg("compile-error.rs")
.run_fail()
.status
.code().unwrap(), 1);
.run_fail_assert_exit_code(1);

assert_eq!(rustdoc()
rustdoc()
.arg("lint-failure.rs")
.run_fail()
.status
.code().unwrap(), 1);
.run_fail_assert_exit_code(1);
}

0 comments on commit 3bb1abb

Please sign in to comment.