Rollup merge of #121884 - 5225225:rmake-exit-code, r=jieyouxu
Port exit-code run-make test to use rust As part of https://github.com/rust-lang/rust/issues/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`
This commit is contained in:
commit
a79b2437af
5 changed files with 70 additions and 16 deletions
|
@ -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);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output};
|
||||
|
||||
|
@ -58,9 +59,8 @@ impl Rustdoc {
|
|||
self
|
||||
}
|
||||
|
||||
/// Fallback argument provider. Consider adding meaningfully named methods instead of using
|
||||
/// this method.
|
||||
pub fn arg(&mut self, arg: &str) -> &mut Self {
|
||||
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
|
||||
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
|
||||
self.cmd.arg(arg);
|
||||
self
|
||||
}
|
||||
|
@ -77,4 +77,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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
# ignore-cross-compile
|
||||
include ../tools.mk
|
||||
|
||||
all:
|
||||
$(RUSTC) success.rs; [ $$? -eq 0 ]
|
||||
$(RUSTC) --invalid-arg-foo; [ $$? -eq 1 ]
|
||||
$(RUSTC) compile-error.rs; [ $$? -eq 1 ]
|
||||
RUSTC_ICE=0 $(RUSTC) -Ztreat-err-as-bug compile-error.rs; [ $$? -eq 101 ]
|
||||
$(RUSTDOC) -o $(TMPDIR)/exit-code success.rs; [ $$? -eq 0 ]
|
||||
$(RUSTDOC) --invalid-arg-foo; [ $$? -eq 1 ]
|
||||
$(RUSTDOC) compile-error.rs; [ $$? -eq 1 ]
|
||||
$(RUSTDOC) lint-failure.rs; [ $$? -eq 1 ]
|
43
tests/run-make/exit-code/rmake.rs
Normal file
43
tests/run-make/exit-code/rmake.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
// 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(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);
|
||||
}
|
Loading…
Add table
Reference in a new issue