Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port exit-code run-make test to use rust #121884

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading