Skip to content

Commit

Permalink
Rollup merge of #121884 - 5225225:rmake-exit-code, r=jieyouxu
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
matthiaskrgr authored Apr 10, 2024
2 parents 8b2459c + de79a6c commit a79b243
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 16 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
18 changes: 15 additions & 3 deletions src/tools/run-make-support/src/rustdoc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::ffi::OsStr;
use std::path::Path;
use std::process::{Command, Output};

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
}
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.

43 changes: 43 additions & 0 deletions tests/run-make/exit-code/rmake.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit a79b243

Please sign in to comment.