Skip to content

Commit a79b243

Browse files
authored
Rollup merge of #121884 - 5225225:rmake-exit-code, r=jieyouxu
Port exit-code run-make test to use rust As part of #121876 ~~As draft because formatting will fail because `x fmt` isn't working for me for some reason, I'll debug that later, just opening this now for review, will mark as ready when formatting is fixed~~ (misleading message from x fmt) cc `@jieyouxu`
2 parents 8b2459c + de79a6c commit a79b243

File tree

5 files changed

+70
-16
lines changed

5 files changed

+70
-16
lines changed

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);

src/tools/run-make-support/src/rustdoc.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::env;
2+
use std::ffi::OsStr;
23
use std::path::Path;
34
use std::process::{Command, Output};
45

@@ -58,9 +59,8 @@ impl Rustdoc {
5859
self
5960
}
6061

61-
/// Fallback argument provider. Consider adding meaningfully named methods instead of using
62-
/// this method.
63-
pub fn arg(&mut self, arg: &str) -> &mut Self {
62+
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
63+
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
6464
self.cmd.arg(arg);
6565
self
6666
}
@@ -77,4 +77,16 @@ impl Rustdoc {
7777
}
7878
output
7979
}
80+
81+
#[track_caller]
82+
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
83+
let caller_location = std::panic::Location::caller();
84+
let caller_line_number = caller_location.line();
85+
86+
let output = self.cmd.output().unwrap();
87+
if output.status.code().unwrap() != code {
88+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
89+
}
90+
output
91+
}
8092
}

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

tests/run-make/exit-code/Makefile

-12
This file was deleted.

tests/run-make/exit-code/rmake.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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")
29+
.arg(tmp_dir().join("exit-code"))
30+
.run();
31+
32+
rustdoc()
33+
.arg("--invalid-arg-foo")
34+
.run_fail_assert_exit_code(1);
35+
36+
rustdoc()
37+
.arg("compile-error.rs")
38+
.run_fail_assert_exit_code(1);
39+
40+
rustdoc()
41+
.arg("lint-failure.rs")
42+
.run_fail_assert_exit_code(1);
43+
}

0 commit comments

Comments
 (0)