authorbors <bors@rust-lang.org> 2024-06-17 21:32:16 UTC
committerbors <bors@rust-lang.org> 2024-06-17 21:32:16 UTC
log59e2c01c2217a01546222e4d9ff4e6695ee8a1db
tree169a3936cf296ecffe84f6fff35d05dd3fff8d00
parent04ab7b2be0db3e6787f5303285c6b2ee6279868d
parent6228b3e40e78ca0a29fd4599c9b7a3e340bb1572

Auto merge of #125500 - Oneirical:bundle-them-up-why-not, r=jieyouxu

Migrate `link-arg`, `link-dedup` and `issue-26092` `run-make` tests to `rmake` format Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). All of these tests check if rustc's output contains (or does not) contain certain strings. Does that mean these could be better suited to becoming UI/codegen tests? try-job: x86_64-msvc

12 files changed, 108 insertions(+), 43 deletions(-)

src/tools/run-make-support/src/command.rs+29-15
......@@ -6,7 +6,7 @@ use std::path::Path;
66use std::process::{Command as StdCommand, ExitStatus, Output, Stdio};
77
88use crate::drop_bomb::DropBomb;
9use crate::{assert_contains, assert_not_contains, handle_failed_output};
9use crate::{assert_contains, assert_equals, assert_not_contains, handle_failed_output};
1010
1111/// This is a custom command wrapper that simplifies working with commands and makes it easier to
1212/// ensure that we check the exit status of executed processes.
......@@ -21,6 +21,7 @@ use crate::{assert_contains, assert_not_contains, handle_failed_output};
2121///
2222/// [`run`]: Self::run
2323/// [`run_fail`]: Self::run_fail
24/// [`run_unchecked`]: Self::run_unchecked
2425#[derive(Debug)]
2526pub struct Command {
2627 cmd: StdCommand,
......@@ -116,6 +117,15 @@ impl Command {
116117 output
117118 }
118119
120 /// Run the command but do not check its exit status.
121 /// Only use if you explicitly don't care about the exit status.
122 /// Prefer to use [`Self::run`] and [`Self::run_fail`]
123 /// whenever possible.
124 #[track_caller]
125 pub fn run_unchecked(&mut self) -> CompletedProcess {
126 self.command_output()
127 }
128
119129 #[track_caller]
120130 fn command_output(&mut self) -> CompletedProcess {
121131 self.drop_bomb.defuse();
......@@ -163,41 +173,45 @@ impl CompletedProcess {
163173 self.output.status
164174 }
165175
166 /// Checks that trimmed `stdout` matches trimmed `content`.
176 /// Checks that trimmed `stdout` matches trimmed `expected`.
167177 #[track_caller]
168 pub fn assert_stdout_equals<S: AsRef<str>>(&self, content: S) -> &Self {
169 assert_eq!(self.stdout_utf8().trim(), content.as_ref().trim());
178 pub fn assert_stdout_equals<S: AsRef<str>>(&self, expected: S) -> &Self {
179 assert_equals(self.stdout_utf8().trim(), expected.as_ref().trim());
170180 self
171181 }
172182
183 /// Checks that `stdout` does not contain `unexpected`.
173184 #[track_caller]
174 pub fn assert_stdout_contains<S: AsRef<str>>(self, needle: S) -> Self {
175 assert_contains(&self.stdout_utf8(), needle.as_ref());
185 pub fn assert_stdout_not_contains<S: AsRef<str>>(&self, unexpected: S) -> &Self {
186 assert_not_contains(&self.stdout_utf8(), unexpected.as_ref());
176187 self
177188 }
178189
190 /// Checks that `stdout` contains `expected`.
179191 #[track_caller]
180 pub fn assert_stdout_not_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
181 assert_not_contains(&self.stdout_utf8(), needle.as_ref());
192 pub fn assert_stdout_contains<S: AsRef<str>>(&self, expected: S) -> &Self {
193 assert_contains(&self.stdout_utf8(), expected.as_ref());
182194 self
183195 }
184196
185 /// Checks that trimmed `stderr` matches trimmed `content`.
197 /// Checks that trimmed `stderr` matches trimmed `expected`.
186198 #[track_caller]
187 pub fn assert_stderr_equals<S: AsRef<str>>(&self, content: S) -> &Self {
188 assert_eq!(self.stderr_utf8().trim(), content.as_ref().trim());
199 pub fn assert_stderr_equals<S: AsRef<str>>(&self, expected: S) -> &Self {
200 assert_equals(self.stderr_utf8().trim(), expected.as_ref().trim());
189201 self
190202 }
191203
204 /// Checks that `stderr` contains `expected`.
192205 #[track_caller]
193 pub fn assert_stderr_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
194 assert_contains(&self.stderr_utf8(), needle.as_ref());
206 pub fn assert_stderr_contains<S: AsRef<str>>(&self, expected: S) -> &Self {
207 assert_contains(&self.stderr_utf8(), expected.as_ref());
195208 self
196209 }
197210
211 /// Checks that `stderr` does not contain `unexpected`.
198212 #[track_caller]
199 pub fn assert_stderr_not_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
200 assert_not_contains(&self.stdout_utf8(), needle.as_ref());
213 pub fn assert_stderr_not_contains<S: AsRef<str>>(&self, unexpected: S) -> &Self {
214 assert_not_contains(&self.stdout_utf8(), unexpected.as_ref());
201215 self
202216 }
203217
src/tools/run-make-support/src/lib.rs+21
......@@ -332,6 +332,18 @@ pub fn read_dir<F: Fn(&Path)>(dir: impl AsRef<Path>, callback: F) {
332332 }
333333}
334334
335/// Check that `actual` is equal to `expected`. Panic otherwise.
336#[track_caller]
337pub fn assert_equals(actual: &str, expected: &str) {
338 if actual != expected {
339 eprintln!("=== ACTUAL TEXT ===");
340 eprintln!("{}", actual);
341 eprintln!("=== EXPECTED ===");
342 eprintln!("{}", expected);
343 panic!("expected text was not found in actual text");
344 }
345}
346
335347/// Check that `haystack` contains `needle`. Panic otherwise.
336348#[track_caller]
337349pub fn assert_contains(haystack: &str, needle: &str) {
......@@ -468,6 +480,15 @@ macro_rules! impl_common_helpers {
468480 self.cmd.run_fail()
469481 }
470482
483 /// Run the command but do not check its exit status.
484 /// Only use if you explicitly don't care about the exit status.
485 /// Prefer to use [`Self::run`] and [`Self::run_fail`]
486 /// whenever possible.
487 #[track_caller]
488 pub fn run_unchecked(&mut self) -> crate::command::CompletedProcess {
489 self.cmd.run_unchecked()
490 }
491
471492 /// Set the path where the command will be run.
472493 pub fn current_dir<P: AsRef<::std::path::Path>>(&mut self, path: P) -> &mut Self {
473494 self.cmd.current_dir(path);
src/tools/tidy/src/allowed_run_make_makefiles.txt-3
......@@ -83,7 +83,6 @@ run-make/issue-20626/Makefile
8383run-make/issue-22131/Makefile
8484run-make/issue-25581/Makefile
8585run-make/issue-26006/Makefile
86run-make/issue-26092/Makefile
8786run-make/issue-28595/Makefile
8887run-make/issue-33329/Makefile
8988run-make/issue-35164/Makefile
......@@ -109,10 +108,8 @@ run-make/libtest-json/Makefile
109108run-make/libtest-junit/Makefile
110109run-make/libtest-padding/Makefile
111110run-make/libtest-thread-limit/Makefile
112run-make/link-arg/Makefile
113111run-make/link-args-order/Makefile
114112run-make/link-cfg/Makefile
115run-make/link-dedup/Makefile
116113run-make/link-framework/Makefile
117114run-make/link-path-order/Makefile
118115run-make/linkage-attr-on-static/Makefile
tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs-1
......@@ -12,7 +12,6 @@ fn main() {
1212
1313 let output =
1414 rustc().input("main.rs").emit("metadata").extern_("stable", "libstable.rmeta").run();
15
1615 let version = fs_wrapper::read_to_string(source_root().join("src/version"));
1716 let expected_string = format!("stable since {}", version.trim());
1817 output.assert_stderr_contains(expected_string);
tests/run-make/clear-error-blank-output/blank.rs created+1
......@@ -0,0 +1 @@
1fn main() {}
tests/run-make/clear-error-blank-output/rmake.rs created+13
......@@ -0,0 +1,13 @@
1// When an empty output file is passed to rustc, the ensuing error message
2// should be clear. However, calling file_stem on an empty path returns None,
3// which, when unwrapped, causes a panic, stopping execution of rustc
4// and printing an obscure message instead of reaching the helpful
5// error message. This test checks that the panic does not occur.
6// See https://github.com/rust-lang/rust/pull/26199
7
8use run_make_support::rustc;
9
10fn main() {
11 let output = rustc().output("").stdin(b"fn main() {}").run_fail();
12 output.assert_stderr_not_contains("panic");
13}
tests/run-make/issue-26092/Makefile deleted-6
......@@ -1,6 +0,0 @@
1include ../tools.mk
2
3# This test ensures that rustc does not panic with `-o ""` option.
4
5all:
6 $(RUSTC) -o "" blank.rs 2>&1 | $(CGREP) -i 'panic' && exit 1 || exit 0
tests/run-make/issue-26092/blank.rs deleted-1
......@@ -1 +0,0 @@
1fn main() {}
tests/run-make/link-arg/Makefile deleted-5
......@@ -1,5 +0,0 @@
1include ../tools.mk
2RUSTC_FLAGS = -C link-arg="-lfoo" -C link-arg="-lbar" --print link-args
3
4all:
5 $(RUSTC) $(RUSTC_FLAGS) empty.rs | $(CGREP) lfoo lbar
tests/run-make/link-arg/rmake.rs created+20
......@@ -0,0 +1,20 @@
1// In 2016, the rustc flag "-C link-arg" was introduced - it can be repeatedly used
2// to add single arguments to the linker. This test passes 2 arguments to the linker using it,
3// then checks that the compiler's output contains the arguments passed to it.
4// This ensures that the compiler successfully parses this flag.
5// See https://github.com/rust-lang/rust/pull/36574
6
7use run_make_support::rustc;
8
9fn main() {
10 // We are only checking for the output of --print=link-args,
11 // rustc failing or succeeding does not matter.
12 let out = rustc()
13 .input("empty.rs")
14 .link_arg("-lfoo")
15 .link_arg("-lbar")
16 .print("link-args")
17 .run_unchecked();
18 out.assert_stdout_contains("lfoo");
19 out.assert_stdout_contains("lbar");
20}
tests/run-make/link-dedup/Makefile deleted-12
......@@ -1,12 +0,0 @@
1# ignore-msvc
2
3include ../tools.mk
4
5all:
6 $(RUSTC) depa.rs
7 $(RUSTC) depb.rs
8 $(RUSTC) depc.rs
9 $(RUSTC) empty.rs --cfg bar 2>&1 | $(CGREP) '"-ltesta" "-ltestb" "-ltesta"'
10 $(RUSTC) empty.rs 2>&1 | $(CGREP) '"-ltesta"'
11 $(RUSTC) empty.rs 2>&1 | $(CGREP) -v '"-ltestb"'
12 $(RUSTC) empty.rs 2>&1 | $(CGREP) -v '"-ltesta" "-ltesta" "-ltesta"'
tests/run-make/link-dedup/rmake.rs created+24
......@@ -0,0 +1,24 @@
1// When native libraries are passed to the linker, there used to be an annoyance
2// where multiple instances of the same library in a row would cause duplication in
3// outputs. This has been fixed, and this test checks that it stays fixed.
4// With the --cfg flag, -ltestb gets added to the output, breaking up the chain of -ltesta.
5// Without the --cfg flag, there should be a single -ltesta, no more, no less.
6// See https://github.com/rust-lang/rust/pull/84794
7
8//@ ignore-msvc
9
10use run_make_support::rustc;
11
12fn main() {
13 rustc().input("depa.rs").run();
14 rustc().input("depb.rs").run();
15 rustc().input("depc.rs").run();
16 let output = rustc().input("empty.rs").cfg("bar").run_fail();
17 output.assert_stderr_contains(r#""-ltesta" "-ltestb" "-ltesta""#);
18 let output = rustc().input("empty.rs").run_fail();
19 output.assert_stderr_contains(r#""-ltesta""#);
20 let output = rustc().input("empty.rs").run_fail();
21 output.assert_stderr_not_contains(r#""-ltestb""#);
22 let output = rustc().input("empty.rs").run_fail();
23 output.assert_stderr_not_contains(r#""-ltesta" "-ltesta" "-ltesta""#);
24}