From 9314831b456b3f17c0849173436531d7d92b2231 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Jun 2024 11:30:23 +0200 Subject: [PATCH 1/3] Implement `CompletedProcess::assert_stdout_contains` and improve error output --- src/tools/run-make-support/src/command.rs | 10 ++++++++-- src/tools/run-make-support/src/lib.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/tools/run-make-support/src/command.rs b/src/tools/run-make-support/src/command.rs index d689dc2f979a7..5ee58e4e7a951 100644 --- a/src/tools/run-make-support/src/command.rs +++ b/src/tools/run-make-support/src/command.rs @@ -6,7 +6,7 @@ use std::path::Path; use std::process::{Command as StdCommand, ExitStatus, Output, Stdio}; use crate::drop_bomb::DropBomb; -use crate::{assert_not_contains, handle_failed_output}; +use crate::{assert_contains, assert_not_contains, handle_failed_output}; /// This is a custom command wrapper that simplifies working with commands and makes it easier to /// ensure that we check the exit status of executed processes. @@ -167,6 +167,12 @@ impl CompletedProcess { self } + #[track_caller] + pub fn assert_stdout_contains>(self, needle: S) -> Self { + assert_contains(&self.stdout_utf8(), needle.as_ref()); + self + } + #[track_caller] pub fn assert_stdout_not_contains>(&self, needle: S) -> &Self { assert_not_contains(&self.stdout_utf8(), needle.as_ref()); @@ -182,7 +188,7 @@ impl CompletedProcess { #[track_caller] pub fn assert_stderr_contains>(&self, needle: S) -> &Self { - assert!(self.stderr_utf8().contains(needle.as_ref())); + assert_contains(&self.stderr_utf8(), needle.as_ref()); self } diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 0238255a53f3a..8bb6a8d51d0db 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -315,6 +315,18 @@ pub fn read_dir(dir: impl AsRef, callback: F) { } } +/// Check that `haystack` contains `needle`. Panic otherwise. +#[track_caller] +pub fn assert_contains(haystack: &str, needle: &str) { + if !haystack.contains(needle) { + eprintln!("=== HAYSTACK ==="); + eprintln!("{}", haystack); + eprintln!("=== NEEDLE ==="); + eprintln!("{}", needle); + panic!("needle was not found in haystack"); + } +} + /// Check that `haystack` does not contain `needle`. Panic otherwise. #[track_caller] pub fn assert_not_contains(haystack: &str, needle: &str) { From 96f9fe5488e74f8b0f75c993ffbcca2c14ba9d01 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Jun 2024 11:21:25 +0200 Subject: [PATCH 2/3] Migrate `run-make/allow-non-lint-warnings-cmdline` to `rmake.rs` --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - .../allow-non-lint-warnings-cmdline/Makefile | 12 ------------ .../allow-non-lint-warnings-cmdline/rmake.rs | 8 ++++++++ 3 files changed, 8 insertions(+), 13 deletions(-) delete mode 100644 tests/run-make/allow-non-lint-warnings-cmdline/Makefile create mode 100644 tests/run-make/allow-non-lint-warnings-cmdline/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 37da5d9c88d90..280420d022d66 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -1,5 +1,4 @@ run-make/allocator-shim-circular-deps/Makefile -run-make/allow-non-lint-warnings-cmdline/Makefile run-make/archive-duplicate-names/Makefile run-make/atomic-lock-free/Makefile run-make/branch-protection-check-IBT/Makefile diff --git a/tests/run-make/allow-non-lint-warnings-cmdline/Makefile b/tests/run-make/allow-non-lint-warnings-cmdline/Makefile deleted file mode 100644 index 78b9a7b989895..0000000000000 --- a/tests/run-make/allow-non-lint-warnings-cmdline/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# Test that -A warnings makes the 'empty trait list for derive' warning go away -OUT=$(shell $(RUSTC) foo.rs -A warnings 2>&1 | grep "warning" ) - -all: foo - test -z '$(OUT)' - -# This is just to make sure the above command actually succeeds -foo: - $(RUSTC) foo.rs -A warnings diff --git a/tests/run-make/allow-non-lint-warnings-cmdline/rmake.rs b/tests/run-make/allow-non-lint-warnings-cmdline/rmake.rs new file mode 100644 index 0000000000000..3866ed3f5be51 --- /dev/null +++ b/tests/run-make/allow-non-lint-warnings-cmdline/rmake.rs @@ -0,0 +1,8 @@ +// Test that -A warnings makes the 'empty trait list for derive' warning go away. + +use run_make_support::rustc; + +fn main() { + let output = rustc().input("foo.rs").arg("-Awarnings").run(); + output.assert_stderr_not_contains("warning"); +} From eca8d209d9c75ed0ba7ce434d62d9460d42271f5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 13 Jun 2024 12:52:05 +0200 Subject: [PATCH 3/3] Make `run-make/allow-non-lint-warnings-cmdline` into a ui test --- tests/run-make/allow-non-lint-warnings-cmdline/rmake.rs | 8 -------- .../foo.rs => ui/allow-non-lint-warnings.rs} | 3 +++ 2 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 tests/run-make/allow-non-lint-warnings-cmdline/rmake.rs rename tests/{run-make/allow-non-lint-warnings-cmdline/foo.rs => ui/allow-non-lint-warnings.rs} (60%) diff --git a/tests/run-make/allow-non-lint-warnings-cmdline/rmake.rs b/tests/run-make/allow-non-lint-warnings-cmdline/rmake.rs deleted file mode 100644 index 3866ed3f5be51..0000000000000 --- a/tests/run-make/allow-non-lint-warnings-cmdline/rmake.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Test that -A warnings makes the 'empty trait list for derive' warning go away. - -use run_make_support::rustc; - -fn main() { - let output = rustc().input("foo.rs").arg("-Awarnings").run(); - output.assert_stderr_not_contains("warning"); -} diff --git a/tests/run-make/allow-non-lint-warnings-cmdline/foo.rs b/tests/ui/allow-non-lint-warnings.rs similarity index 60% rename from tests/run-make/allow-non-lint-warnings-cmdline/foo.rs rename to tests/ui/allow-non-lint-warnings.rs index 02e8ccabf7921..f8f5a78ebff26 100644 --- a/tests/run-make/allow-non-lint-warnings-cmdline/foo.rs +++ b/tests/ui/allow-non-lint-warnings.rs @@ -1,3 +1,6 @@ +//@ compile-flags: -Awarnings +//@ check-pass + #[derive()] #[derive(Copy, Clone)] pub struct Foo;