Skip to content

Commit 65df93b

Browse files
committed
move exit-code to rmake
1 parent 0e5f520 commit 65df93b

File tree

5 files changed

+71
-13
lines changed

5 files changed

+71
-13
lines changed

Diff for: src/tools/run-make-support/src/rustc.rs

+12
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ impl Rustc {
183183
output
184184
}
185185

186+
#[track_caller]
187+
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
188+
let caller_location = std::panic::Location::caller();
189+
let caller_line_number = caller_location.line();
190+
191+
let output = self.cmd.output().unwrap();
192+
if output.status.code().unwrap() != code {
193+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
194+
}
195+
output
196+
}
197+
186198
/// Inspect what the underlying [`Command`] is up to the current construction.
187199
pub fn inspect(&mut self, f: impl FnOnce(&Command)) -> &mut Self {
188200
f(&self.cmd);

Diff for: src/tools/run-make-support/src/rustdoc.rs

+17
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ impl Rustdoc {
6565
self
6666
}
6767

68+
pub fn arg_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
69+
self.cmd.arg(path.as_ref());
70+
self
71+
}
72+
6873
/// Run the build `rustdoc` command and assert that the run is successful.
6974
#[track_caller]
7075
pub fn run(&mut self) -> Output {
@@ -77,4 +82,16 @@ impl Rustdoc {
7782
}
7883
output
7984
}
85+
86+
#[track_caller]
87+
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
88+
let caller_location = std::panic::Location::caller();
89+
let caller_line_number = caller_location.line();
90+
91+
let output = self.cmd.output().unwrap();
92+
if output.status.code().unwrap() != code {
93+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
94+
}
95+
output
96+
}
8097
}

Diff for: src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ run-make/emit/Makefile
5959
run-make/env-dep-info/Makefile
6060
run-make/error-found-staticlib-instead-crate/Makefile
6161
run-make/error-writing-dependencies/Makefile
62-
run-make/exit-code/Makefile
6362
run-make/export-executable-symbols/Makefile
6463
run-make/extern-diff-internal-name/Makefile
6564
run-make/extern-flag-disambiguates/Makefile

Diff for: tests/run-make/exit-code/Makefile

-12
This file was deleted.

Diff for: tests/run-make/exit-code/rmake.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Test that we exit with the correct exit code for successful / unsuccessful / ICE compilations
2+
3+
extern crate run_make_support;
4+
5+
use run_make_support::{rustc, rustdoc, tmp_dir};
6+
7+
fn main() {
8+
rustc()
9+
.arg("success.rs")
10+
.run();
11+
12+
rustc()
13+
.arg("--invalid-arg-foo")
14+
.run_fail_assert_exit_code(1);
15+
16+
rustc()
17+
.arg("compile-error.rs")
18+
.run_fail_assert_exit_code(1);
19+
20+
rustc()
21+
.env("RUSTC_ICE", "0")
22+
.arg("-Ztreat-err-as-bug")
23+
.arg("compile-error.rs")
24+
.run_fail_assert_exit_code(101);
25+
26+
rustdoc()
27+
.arg("success.rs")
28+
.arg("-o").arg_path(tmp_dir().join("exit-code"))
29+
.run();
30+
31+
rustdoc()
32+
.arg("--invalid-arg-foo")
33+
.run_fail_assert_exit_code(1);
34+
35+
rustdoc()
36+
.arg("compile-error.rs")
37+
.run_fail_assert_exit_code(1);
38+
39+
rustdoc()
40+
.arg("lint-failure.rs")
41+
.run_fail_assert_exit_code(1);
42+
}

0 commit comments

Comments
 (0)