Skip to content

Commit

Permalink
move exit-code to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
5225225 committed Apr 8, 2024
1 parent 0e5f520 commit 65df93b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 13 deletions.
12 changes: 12 additions & 0 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ impl Rustc {
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
}

/// Inspect what the underlying [`Command`] is up to the current construction.
pub fn inspect(&mut self, f: impl FnOnce(&Command)) -> &mut Self {
f(&self.cmd);
Expand Down
17 changes: 17 additions & 0 deletions src/tools/run-make-support/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ impl Rustdoc {
self
}

pub fn arg_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
self
}

/// Run the build `rustdoc` command and assert that the run is successful.
#[track_caller]
pub fn run(&mut self) -> Output {
Expand All @@ -77,4 +82,16 @@ impl Rustdoc {
}
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
}
}
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ run-make/emit/Makefile
run-make/env-dep-info/Makefile
run-make/error-found-staticlib-instead-crate/Makefile
run-make/error-writing-dependencies/Makefile
run-make/exit-code/Makefile
run-make/export-executable-symbols/Makefile
run-make/extern-diff-internal-name/Makefile
run-make/extern-flag-disambiguates/Makefile
Expand Down
12 changes: 0 additions & 12 deletions tests/run-make/exit-code/Makefile

This file was deleted.

42 changes: 42 additions & 0 deletions tests/run-make/exit-code/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Test that we exit with the correct exit code for successful / unsuccessful / ICE compilations

extern crate run_make_support;

use run_make_support::{rustc, rustdoc, tmp_dir};

fn main() {
rustc()
.arg("success.rs")
.run();

rustc()
.arg("--invalid-arg-foo")
.run_fail_assert_exit_code(1);

rustc()
.arg("compile-error.rs")
.run_fail_assert_exit_code(1);

rustc()
.env("RUSTC_ICE", "0")
.arg("-Ztreat-err-as-bug")
.arg("compile-error.rs")
.run_fail_assert_exit_code(101);

rustdoc()
.arg("success.rs")
.arg("-o").arg_path(tmp_dir().join("exit-code"))
.run();

rustdoc()
.arg("--invalid-arg-foo")
.run_fail_assert_exit_code(1);

rustdoc()
.arg("compile-error.rs")
.run_fail_assert_exit_code(1);

rustdoc()
.arg("lint-failure.rs")
.run_fail_assert_exit_code(1);
}

0 comments on commit 65df93b

Please sign in to comment.