| author | bors <bors@rust-lang.org> 2024-06-17 21:32:16 UTC |
| committer | bors <bors@rust-lang.org> 2024-06-17 21:32:16 UTC |
| log | 59e2c01c2217a01546222e4d9ff4e6695ee8a1db |
| tree | 169a3936cf296ecffe84f6fff35d05dd3fff8d00 |
| parent | 04ab7b2be0db3e6787f5303285c6b2ee6279868d |
| parent | 6228b3e40e78ca0a29fd4599c9b7a3e340bb1572 |
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-msvc12 files changed, 108 insertions(+), 43 deletions(-)
src/tools/run-make-support/src/command.rs+29-15| ... | ... | @@ -6,7 +6,7 @@ use std::path::Path; |
| 6 | 6 | use std::process::{Command as StdCommand, ExitStatus, Output, Stdio}; |
| 7 | 7 | |
| 8 | 8 | use crate::drop_bomb::DropBomb; |
| 9 | use crate::{assert_contains, assert_not_contains, handle_failed_output}; | |
| 9 | use crate::{assert_contains, assert_equals, assert_not_contains, handle_failed_output}; | |
| 10 | 10 | |
| 11 | 11 | /// This is a custom command wrapper that simplifies working with commands and makes it easier to |
| 12 | 12 | /// ensure that we check the exit status of executed processes. |
| ... | ... | @@ -21,6 +21,7 @@ use crate::{assert_contains, assert_not_contains, handle_failed_output}; |
| 21 | 21 | /// |
| 22 | 22 | /// [`run`]: Self::run |
| 23 | 23 | /// [`run_fail`]: Self::run_fail |
| 24 | /// [`run_unchecked`]: Self::run_unchecked | |
| 24 | 25 | #[derive(Debug)] |
| 25 | 26 | pub struct Command { |
| 26 | 27 | cmd: StdCommand, |
| ... | ... | @@ -116,6 +117,15 @@ impl Command { |
| 116 | 117 | output |
| 117 | 118 | } |
| 118 | 119 | |
| 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 | ||
| 119 | 129 | #[track_caller] |
| 120 | 130 | fn command_output(&mut self) -> CompletedProcess { |
| 121 | 131 | self.drop_bomb.defuse(); |
| ... | ... | @@ -163,41 +173,45 @@ impl CompletedProcess { |
| 163 | 173 | self.output.status |
| 164 | 174 | } |
| 165 | 175 | |
| 166 | /// Checks that trimmed `stdout` matches trimmed `content`. | |
| 176 | /// Checks that trimmed `stdout` matches trimmed `expected`. | |
| 167 | 177 | #[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()); | |
| 170 | 180 | self |
| 171 | 181 | } |
| 172 | 182 | |
| 183 | /// Checks that `stdout` does not contain `unexpected`. | |
| 173 | 184 | #[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()); | |
| 176 | 187 | self |
| 177 | 188 | } |
| 178 | 189 | |
| 190 | /// Checks that `stdout` contains `expected`. | |
| 179 | 191 | #[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()); | |
| 182 | 194 | self |
| 183 | 195 | } |
| 184 | 196 | |
| 185 | /// Checks that trimmed `stderr` matches trimmed `content`. | |
| 197 | /// Checks that trimmed `stderr` matches trimmed `expected`. | |
| 186 | 198 | #[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()); | |
| 189 | 201 | self |
| 190 | 202 | } |
| 191 | 203 | |
| 204 | /// Checks that `stderr` contains `expected`. | |
| 192 | 205 | #[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()); | |
| 195 | 208 | self |
| 196 | 209 | } |
| 197 | 210 | |
| 211 | /// Checks that `stderr` does not contain `unexpected`. | |
| 198 | 212 | #[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()); | |
| 201 | 215 | self |
| 202 | 216 | } |
| 203 | 217 |
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) { |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | /// Check that `actual` is equal to `expected`. Panic otherwise. | |
| 336 | #[track_caller] | |
| 337 | pub 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 | ||
| 335 | 347 | /// Check that `haystack` contains `needle`. Panic otherwise. |
| 336 | 348 | #[track_caller] |
| 337 | 349 | pub fn assert_contains(haystack: &str, needle: &str) { |
| ... | ... | @@ -468,6 +480,15 @@ macro_rules! impl_common_helpers { |
| 468 | 480 | self.cmd.run_fail() |
| 469 | 481 | } |
| 470 | 482 | |
| 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 | ||
| 471 | 492 | /// Set the path where the command will be run. |
| 472 | 493 | pub fn current_dir<P: AsRef<::std::path::Path>>(&mut self, path: P) -> &mut Self { |
| 473 | 494 | self.cmd.current_dir(path); |
src/tools/tidy/src/allowed_run_make_makefiles.txt-3| ... | ... | @@ -83,7 +83,6 @@ run-make/issue-20626/Makefile |
| 83 | 83 | run-make/issue-22131/Makefile |
| 84 | 84 | run-make/issue-25581/Makefile |
| 85 | 85 | run-make/issue-26006/Makefile |
| 86 | run-make/issue-26092/Makefile | |
| 87 | 86 | run-make/issue-28595/Makefile |
| 88 | 87 | run-make/issue-33329/Makefile |
| 89 | 88 | run-make/issue-35164/Makefile |
| ... | ... | @@ -109,10 +108,8 @@ run-make/libtest-json/Makefile |
| 109 | 108 | run-make/libtest-junit/Makefile |
| 110 | 109 | run-make/libtest-padding/Makefile |
| 111 | 110 | run-make/libtest-thread-limit/Makefile |
| 112 | run-make/link-arg/Makefile | |
| 113 | 111 | run-make/link-args-order/Makefile |
| 114 | 112 | run-make/link-cfg/Makefile |
| 115 | run-make/link-dedup/Makefile | |
| 116 | 113 | run-make/link-framework/Makefile |
| 117 | 114 | run-make/link-path-order/Makefile |
| 118 | 115 | run-make/linkage-attr-on-static/Makefile |
tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs-1| ... | ... | @@ -12,7 +12,6 @@ fn main() { |
| 12 | 12 | |
| 13 | 13 | let output = |
| 14 | 14 | rustc().input("main.rs").emit("metadata").extern_("stable", "libstable.rmeta").run(); |
| 15 | ||
| 16 | 15 | let version = fs_wrapper::read_to_string(source_root().join("src/version")); |
| 17 | 16 | let expected_string = format!("stable since {}", version.trim()); |
| 18 | 17 | output.assert_stderr_contains(expected_string); |
tests/run-make/clear-error-blank-output/blank.rs created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | fn 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 | ||
| 8 | use run_make_support::rustc; | |
| 9 | ||
| 10 | fn 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 @@ |
| 1 | include ../tools.mk | |
| 2 | ||
| 3 | # This test ensures that rustc does not panic with `-o ""` option. | |
| 4 | ||
| 5 | all: | |
| 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 @@ |
| 1 | fn main() {} |
tests/run-make/link-arg/Makefile deleted-5| ... | ... | @@ -1,5 +0,0 @@ |
| 1 | include ../tools.mk | |
| 2 | RUSTC_FLAGS = -C link-arg="-lfoo" -C link-arg="-lbar" --print link-args | |
| 3 | ||
| 4 | all: | |
| 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 | ||
| 7 | use run_make_support::rustc; | |
| 8 | ||
| 9 | fn 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 | ||
| 3 | include ../tools.mk | |
| 4 | ||
| 5 | all: | |
| 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 | ||
| 10 | use run_make_support::rustc; | |
| 11 | ||
| 12 | fn 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 | } |