about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-07-26 12:06:25 -0400
committerOneirical <manchot@videotron.ca>2024-07-26 15:20:01 -0400
commit1a15d901211c37aa2f4f818cbcc49bfa0c2e80b6 (patch)
treeee297268891c9368e1edf296ffa270fc7b38e146
parentd5c073eb090f34b42da85f3f768ea6847b9ba7bc (diff)
downloadrust-1a15d901211c37aa2f4f818cbcc49bfa0c2e80b6.tar.gz
rust-1a15d901211c37aa2f4f818cbcc49bfa0c2e80b6.zip
assert_stdout_contains_regex in run_make_support + variations
-rw-r--r--src/tools/run-make-support/src/assertion_helpers.rs32
-rw-r--r--src/tools/run-make-support/src/command.rs33
-rw-r--r--src/tools/run-make-support/src/external_deps/llvm.rs30
-rw-r--r--src/tools/run-make-support/src/lib.rs7
-rw-r--r--tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs8
5 files changed, 99 insertions, 11 deletions
diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs
index 4b5b349431d..6d256fc594d 100644
--- a/src/tools/run-make-support/src/assertion_helpers.rs
+++ b/src/tools/run-make-support/src/assertion_helpers.rs
@@ -3,7 +3,7 @@
 use std::panic;
 use std::path::Path;
 
-use crate::fs;
+use crate::{fs, regex};
 
 /// Assert that `actual` is equal to `expected`.
 #[track_caller]
@@ -47,6 +47,36 @@ pub fn assert_not_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N)
     }
 }
 
+/// Assert that `haystack` contains the regex pattern `needle`.
+#[track_caller]
+pub fn assert_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) {
+    let haystack = haystack.as_ref();
+    let needle = needle.as_ref();
+    let re = regex::Regex::new(needle).unwrap();
+    if !re.is_match(haystack) {
+        eprintln!("=== HAYSTACK ===");
+        eprintln!("{}", haystack);
+        eprintln!("=== NEEDLE ===");
+        eprintln!("{}", needle);
+        panic!("needle was not found in haystack");
+    }
+}
+
+/// Assert that `haystack` does not contain the regex pattern `needle`.
+#[track_caller]
+pub fn assert_not_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) {
+    let haystack = haystack.as_ref();
+    let needle = needle.as_ref();
+    let re = regex::Regex::new(needle).unwrap();
+    if re.is_match(haystack) {
+        eprintln!("=== HAYSTACK ===");
+        eprintln!("{}", haystack);
+        eprintln!("=== NEEDLE ===");
+        eprintln!("{}", needle);
+        panic!("needle was unexpectedly found in haystack");
+    }
+}
+
 /// Assert that all files in `dir1` exist and have the same content in `dir2`
 pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
     let dir2 = dir2.as_ref();
diff --git a/src/tools/run-make-support/src/command.rs b/src/tools/run-make-support/src/command.rs
index 47376c401bb..8686855b6f3 100644
--- a/src/tools/run-make-support/src/command.rs
+++ b/src/tools/run-make-support/src/command.rs
@@ -6,7 +6,10 @@ use std::path::Path;
 use std::process::{Command as StdCommand, ExitStatus, Output, Stdio};
 
 use crate::util::handle_failed_output;
-use crate::{assert_contains, assert_equals, assert_not_contains};
+use crate::{
+    assert_contains, assert_contains_regex, assert_equals, assert_not_contains,
+    assert_not_contains_regex,
+};
 
 use build_helper::drop_bomb::DropBomb;
 
@@ -192,6 +195,13 @@ impl CompletedProcess {
         self
     }
 
+    /// Checks that `stdout` does not contain the regex pattern `unexpected`.
+    #[track_caller]
+    pub fn assert_stdout_not_contains_regex<S: AsRef<str>>(&self, unexpected: S) -> &Self {
+        assert_not_contains_regex(&self.stdout_utf8(), unexpected);
+        self
+    }
+
     /// Checks that `stdout` contains `expected`.
     #[track_caller]
     pub fn assert_stdout_contains<S: AsRef<str>>(&self, expected: S) -> &Self {
@@ -199,6 +209,13 @@ impl CompletedProcess {
         self
     }
 
+    /// Checks that `stdout` contains the regex pattern `expected`.
+    #[track_caller]
+    pub fn assert_stdout_contains_regex<S: AsRef<str>>(&self, expected: S) -> &Self {
+        assert_contains_regex(&self.stdout_utf8(), expected);
+        self
+    }
+
     /// Checks that trimmed `stderr` matches trimmed `expected`.
     #[track_caller]
     pub fn assert_stderr_equals<S: AsRef<str>>(&self, expected: S) -> &Self {
@@ -213,6 +230,13 @@ impl CompletedProcess {
         self
     }
 
+    /// Checks that `stderr` contains the regex pattern `expected`.
+    #[track_caller]
+    pub fn assert_stderr_contains_regex<S: AsRef<str>>(&self, expected: S) -> &Self {
+        assert_contains_regex(&self.stderr_utf8(), expected);
+        self
+    }
+
     /// Checks that `stderr` does not contain `unexpected`.
     #[track_caller]
     pub fn assert_stderr_not_contains<S: AsRef<str>>(&self, unexpected: S) -> &Self {
@@ -220,6 +244,13 @@ impl CompletedProcess {
         self
     }
 
+    /// Checks that `stderr` does not contain the regex pattern `unexpected`.
+    #[track_caller]
+    pub fn assert_stderr_not_contains_regex<S: AsRef<str>>(&self, unexpected: S) -> &Self {
+        assert_not_contains_regex(&self.stdout_utf8(), unexpected);
+        self
+    }
+
     #[track_caller]
     pub fn assert_exit_code(&self, code: i32) -> &Self {
         assert!(self.output.status.code() == Some(code));
diff --git a/src/tools/run-make-support/src/external_deps/llvm.rs b/src/tools/run-make-support/src/external_deps/llvm.rs
index b116bd08e3a..259bb615946 100644
--- a/src/tools/run-make-support/src/external_deps/llvm.rs
+++ b/src/tools/run-make-support/src/external_deps/llvm.rs
@@ -36,6 +36,12 @@ pub fn llvm_ar() -> LlvmAr {
     LlvmAr::new()
 }
 
+/// Construct a new `llvm-nm` invocation. This assumes that `llvm-nm` is available
+/// at `$LLVM_BIN_DIR/llvm-nm`.
+pub fn llvm_nm() -> LlvmNm {
+    LlvmNm::new()
+}
+
 /// A `llvm-readobj` invocation builder.
 #[derive(Debug)]
 #[must_use]
@@ -71,11 +77,19 @@ pub struct LlvmAr {
     cmd: Command,
 }
 
+/// A `llvm-nm` invocation builder.
+#[derive(Debug)]
+#[must_use]
+pub struct LlvmNm {
+    cmd: Command,
+}
+
 crate::macros::impl_common_helpers!(LlvmReadobj);
 crate::macros::impl_common_helpers!(LlvmProfdata);
 crate::macros::impl_common_helpers!(LlvmFilecheck);
 crate::macros::impl_common_helpers!(LlvmObjdump);
 crate::macros::impl_common_helpers!(LlvmAr);
+crate::macros::impl_common_helpers!(LlvmNm);
 
 /// Generate the path to the bin directory of LLVM.
 #[must_use]
@@ -244,3 +258,19 @@ impl LlvmAr {
         self
     }
 }
+
+impl LlvmNm {
+    /// Construct a new `llvm-nm` invocation. This assumes that `llvm-nm` is available
+    /// at `$LLVM_BIN_DIR/llvm-nm`.
+    pub fn new() -> Self {
+        let llvm_nm = llvm_bin_dir().join("llvm-nm");
+        let cmd = Command::new(llvm_nm);
+        Self { cmd }
+    }
+
+    /// Provide an input file.
+    pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
+        self.cmd.arg(path.as_ref());
+        self
+    }
+}
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index 085120764b4..f28f2a120a4 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -48,8 +48,8 @@ pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
 pub use clang::{clang, Clang};
 pub use htmldocck::htmldocck;
 pub use llvm::{
-    llvm_ar, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmFilecheck,
-    LlvmObjdump, LlvmProfdata, LlvmReadobj,
+    llvm_ar, llvm_filecheck, llvm_nm, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr,
+    LlvmFilecheck, LlvmNm, LlvmObjdump, LlvmProfdata, LlvmReadobj,
 };
 pub use python::python_command;
 pub use rustc::{aux_build, bare_rustc, rustc, Rustc};
@@ -84,7 +84,8 @@ pub use path_helpers::{
 pub use scoped_run::{run_in_tmpdir, test_while_readonly};
 
 pub use assertion_helpers::{
-    assert_contains, assert_dirs_are_equal, assert_equals, assert_not_contains,
+    assert_contains, assert_contains_regex, assert_dirs_are_equal, assert_equals,
+    assert_not_contains, assert_not_contains_regex,
 };
 
 pub use string::{
diff --git a/tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs b/tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs
index 8d7afd3245e..5a1460963b6 100644
--- a/tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs
+++ b/tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs
@@ -4,18 +4,14 @@
 // in rustc flags without a compilation failure or the removal of expected symbols.
 // See https://github.com/rust-lang/rust/pull/100101
 
-//FIXME(Oneirical): try it on test-various
-
-use run_make_support::{llvm_ar, llvm_readobj, regex, rfs, rust_lib_name, rustc};
+use run_make_support::{llvm_ar, llvm_nm, rfs, rust_lib_name, rustc};
 
 fn main() {
     // Build a strangely named dependency.
     rustc().input("native_dep.rs").crate_type("staticlib").output("native_dep.ext").run();
 
     rustc().input("rust_dep.rs").crate_type("rlib").arg("-Zpacked_bundled_libs").run();
-    let symbols = llvm_readobj().symbols().input(rust_lib_name("rust_dep")).run().stdout_utf8();
-    let re = regex::Regex::new("U.*native_f1").unwrap();
-    assert!(re.is_match(&symbols));
+    llvm_nm().input(rust_lib_name("rust_dep")).run().assert_stdout_contains_regex("U.*native_f1");
     llvm_ar()
         .arg("t")
         .arg(rust_lib_name("rust_dep"))