Skip to content

Commit

Permalink
Rewrite and rename issue-26092 to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 13, 2024
1 parent 178c493 commit 12fa410
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 55 deletions.
16 changes: 16 additions & 0 deletions src/tools/run-make-support/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ impl Command {
output
}

/// Run the constructed command and return its output no matter what.
#[track_caller]
pub fn run_unchecked(&mut self) -> CompletedProcess {
self.command_output()
}

#[track_caller]
fn command_output(&mut self) -> CompletedProcess {
self.drop_bomb.defuse();
Expand Down Expand Up @@ -167,25 +173,35 @@ impl CompletedProcess {
self
}

/// Checks that trimmed `stdout` does not contain trimmed `content`.
#[track_caller]
pub fn assert_stdout_not_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
assert_not_contains(&self.stdout_utf8(), needle.as_ref());
self
}

/// Checks that trimmed `stdout` contains trimmed `content`.
#[track_caller]
pub fn assert_stdout_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
assert!(self.stdout_utf8().contains(needle.as_ref()));
self
}

/// Checks that trimmed `stderr` matches trimmed `content`.
#[track_caller]
pub fn assert_stderr_equals<S: AsRef<str>>(&self, content: S) -> &Self {
assert_eq!(self.stderr_utf8().trim(), content.as_ref().trim());
self
}

/// Checks that trimmed `stderr` contains trimmed `content`.
#[track_caller]
pub fn assert_stderr_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
assert!(self.stderr_utf8().contains(needle.as_ref()));
self
}

/// Checks that trimmed `stderr` does not contain trimmed `content`.
#[track_caller]
pub fn assert_stderr_not_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
assert_not_contains(&self.stdout_utf8(), needle.as_ref());
Expand Down
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ macro_rules! impl_common_helpers {
self.cmd.run_fail()
}

/// Run the constructed command and return its output no matter what.
#[track_caller]
pub fn run_unchecked(&mut self) -> crate::command::CompletedProcess {
self.cmd.run_unchecked()
}

/// Set the path where the command will be run.
pub fn current_dir<P: AsRef<::std::path::Path>>(&mut self, path: P) -> &mut Self {
self.cmd.current_dir(path);
Expand Down
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 @@ -88,7 +88,6 @@ run-make/issue-20626/Makefile
run-make/issue-22131/Makefile
run-make/issue-25581/Makefile
run-make/issue-26006/Makefile
run-make/issue-26092/Makefile
run-make/issue-28595/Makefile
run-make/issue-33329/Makefile
run-make/issue-35164/Makefile
Expand Down
1 change: 0 additions & 1 deletion tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn main() {

let output =
rustc().input("main.rs").emit("metadata").extern_("stable", "libstable.rmeta").run();

let version = fs_wrapper::read_to_string(source_root().join("src/version"));
let expected_string = format!("stable since {}", version.trim());
output.assert_stderr_contains(expected_string);
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions tests/run-make/clear-error-blank-output/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// When an empty output file is passed to rustc, the ensuing error message
// should be clear. However, calling file_stem on an empty path returns None,
// which, when unwrapped, causes a panic, stopping execution of rustc
// and printing an obscure message instead of reaching the helpful
// error message. This test checks that the panic does not occur.
// See https://github.com/rust-lang/rust/pull/26199

use run_make_support::rustc;

fn main() {
let output = rustc().output("").input("blank.rs").run_fail();
output.assert_stderr_not_contains("panic");
}
6 changes: 0 additions & 6 deletions tests/run-make/issue-26092/Makefile

This file was deleted.

23 changes: 9 additions & 14 deletions tests/run-make/link-arg/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@
use run_make_support::rustc;

fn main() {
let output = String::from_utf8(
rustc()
.input("empty.rs")
.link_arg("-lfoo")
.link_arg("-lbar")
.print("link-args")
.command_output()
.stdout,
)
.unwrap();
assert!(
output.contains("lfoo") || output.contains("lbar"),
"The output did not contain the expected \"lfoo\" or \"lbar\" strings."
);
// The original Makefile test did not check if rustc succeeded or failed.
let out = rustc()
.input("empty.rs")
.link_arg("-lfoo")
.link_arg("-lbar")
.print("link-args")
.run_unchecked();
out.assert_stdout_contains("lfoo");
out.assert_stdout_contains("lbar");
}
12 changes: 0 additions & 12 deletions tests/run-make/link-dedup/Makefile

This file was deleted.

28 changes: 10 additions & 18 deletions tests/run-make/link-dedup/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,18 @@

//@ ignore-msvc

use run_make_support::rustc;

fn main() {
rustc().input("depa.rs").run();
rustc().input("depb.rs").run();
rustc().input("depc.rs").run();
let output =
String::from_utf8(rustc().input("empty.rs").cfg("bar").command_output().stderr).unwrap();
let pos_a1 =
output.find("-ltesta").expect("empty.rs, compiled with --cfg, should contain -ltesta");
let pos_b = output[pos_a1..]
.find("-ltestb")
.map(|pos| pos + pos_a1)
.expect("empty.rs, compiled with --cfg, should contain -ltestb");
let _ = output[pos_b..]
.find("-ltesta")
.map(|pos| pos + pos_b)
.expect("empty.rs, compiled with --cfg, should contain a second -ltesta");
let output = String::from_utf8(rustc().input("empty.rs").command_output().stderr).unwrap();
assert!(output.contains("-ltesta"));
let output = String::from_utf8(rustc().input("empty.rs").command_output().stderr).unwrap();
assert!(!output.contains("-ltestb"));
let output = String::from_utf8(rustc().input("empty.rs").command_output().stderr).unwrap();
assert_eq!(output.matches("-ltesta").count, 1);
let output = rustc().input("empty.rs").cfg("bar").run_fail();
output.assert_stderr_contains("\"-ltesta\" \"-ltestb\" \"-ltesta\"");
let output = rustc().input("empty.rs").run_fail();
output.assert_stderr_contains("\"-ltesta\"");
let output = rustc().input("empty.rs").run_fail();
output.assert_stderr_not_contains("\"-ltestb\"");
let output = rustc().input("empty.rs").run_fail();
output.assert_stderr_not_contains("\"-ltesta\" \"-ltesta\" \"-ltesta\"");
}
1 change: 0 additions & 1 deletion tests/run-make/rustdoc-error-lines/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use run_make_support::rustdoc;

fn main() {
let output = rustdoc().input("input.rs").arg("--test").run_fail().stdout_utf8();

let should_contain = &[
"input.rs - foo (line 5)",
"input.rs:7:15",
Expand Down
1 change: 0 additions & 1 deletion tests/run-make/rustdoc-scrape-examples-macros/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ fn main() {
.arg("-")
.run()
.stdout_utf8();

rustc()
.input("src/proc.rs")
.crate_name(proc_crate_name)
Expand Down
1 change: 0 additions & 1 deletion tests/run-make/rustdoc-shared-flags/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use run_make_support::{rustc, rustdoc, Diff};
fn compare_outputs(args: &[&str]) {
let rustc_output = rustc().args(args).run().stdout_utf8();
let rustdoc_output = rustdoc().args(args).run().stdout_utf8();

Diff::new().expected_text("rustc", rustc_output).actual_text("rustdoc", rustdoc_output).run();
}

Expand Down

0 comments on commit 12fa410

Please sign in to comment.