Skip to content

Commit 3bb1abb

Browse files
committed
add run_fail_assert_exit_code as a helper
1 parent d3a307e commit 3bb1abb

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ impl RustcInvocationBuilder {
7676
}
7777
output
7878
}
79+
80+
#[track_caller]
81+
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
82+
let caller_location = std::panic::Location::caller();
83+
let caller_line_number = caller_location.line();
84+
85+
let output = self.cmd.output().unwrap();
86+
if output.status.code().unwrap() != code {
87+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
88+
}
89+
output
90+
}
7991
}
8092

8193
#[derive(Debug)]

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

+12
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ impl RustdocInvocationBuilder {
5757
}
5858
output
5959
}
60+
61+
#[track_caller]
62+
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
63+
let caller_location = std::panic::Location::caller();
64+
let caller_line_number = caller_location.line();
65+
66+
let output = self.cmd.output().unwrap();
67+
if output.status.code().unwrap() != code {
68+
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
69+
}
70+
output
71+
}
6072
}
6173

6274
fn setup_common_rustdoc_build_cmd() -> Command {

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

+12-24
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,35 @@ fn main() {
77
.arg("success.rs")
88
.run();
99

10-
assert_eq!(rustc()
10+
rustc()
1111
.arg("--invalid-arg-foo")
12-
.run_fail()
13-
.status
14-
.code().unwrap(), 1);
12+
.run_fail_assert_exit_code(1);
1513

16-
assert_eq!(rustc()
14+
rustc()
1715
.arg("compile-error.rs")
18-
.run_fail()
19-
.status
20-
.code().unwrap(), 1);
16+
.run_fail_assert_exit_code(1);
2117

22-
assert_eq!(rustc()
18+
rustc()
2319
.env("RUSTC_ICE", "0")
2420
.arg("-Ztreat-err-as-bug")
2521
.arg("compile-error.rs")
26-
.run_fail()
27-
.status
28-
.code().unwrap(), 101);
22+
.run_fail_assert_exit_code(101);
2923

3024
rustdoc()
3125
.arg("-o")
3226
.arg_file(&tempdir().join("exit-code"))
3327
.arg("success.rs")
3428
.run();
3529

36-
assert_eq!(rustdoc()
30+
rustdoc()
3731
.arg("--invalid-arg-foo")
38-
.run_fail()
39-
.status
40-
.code().unwrap(), 1);
32+
.run_fail_assert_exit_code(1);
4133

42-
assert_eq!(rustdoc()
34+
rustdoc()
4335
.arg("compile-error.rs")
44-
.run_fail()
45-
.status
46-
.code().unwrap(), 1);
36+
.run_fail_assert_exit_code(1);
4737

48-
assert_eq!(rustdoc()
38+
rustdoc()
4939
.arg("lint-failure.rs")
50-
.run_fail()
51-
.status
52-
.code().unwrap(), 1);
40+
.run_fail_assert_exit_code(1);
5341
}

0 commit comments

Comments
 (0)