diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-07-01 20:29:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-01 20:29:59 +0200 |
| commit | a509b5a0bac0ecfc68557aedc60b9aa6f9b2d24b (patch) | |
| tree | 9b40faa9dd8a3fcb3559f83d2b463b4831a24267 /src | |
| parent | cb81d0dd05b5b55cbee03528bdf5c6bd837c3572 (diff) | |
| parent | fcfac05657acf387392f853904c917ac06c082c5 (diff) | |
| download | rust-a509b5a0bac0ecfc68557aedc60b9aa6f9b2d24b.tar.gz rust-a509b5a0bac0ecfc68557aedc60b9aa6f9b2d24b.zip | |
Rollup merge of #127201 - GuillaumeGomez:improve-run-make-support, r=Kobzol
Improve run-make-support API I think I'll slowly continue this work. Makes things a bit nicer for contributors, so why not. :D r? ``@Kobzol``
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/run-make-support/src/command.rs | 8 | ||||
| -rw-r--r-- | src/tools/run-make-support/src/lib.rs | 12 | ||||
| -rw-r--r-- | src/tools/run-make-support/src/rustc.rs | 3 | ||||
| -rw-r--r-- | src/tools/run-make-support/src/rustdoc.rs | 3 |
4 files changed, 17 insertions, 9 deletions
diff --git a/src/tools/run-make-support/src/command.rs b/src/tools/run-make-support/src/command.rs index 0a1bd9b0b34..ee651704c6f 100644 --- a/src/tools/run-make-support/src/command.rs +++ b/src/tools/run-make-support/src/command.rs @@ -185,14 +185,14 @@ impl CompletedProcess { /// Checks that `stdout` does not contain `unexpected`. #[track_caller] pub fn assert_stdout_not_contains<S: AsRef<str>>(&self, unexpected: S) -> &Self { - assert_not_contains(&self.stdout_utf8(), unexpected.as_ref()); + assert_not_contains(&self.stdout_utf8(), unexpected); self } /// Checks that `stdout` contains `expected`. #[track_caller] pub fn assert_stdout_contains<S: AsRef<str>>(&self, expected: S) -> &Self { - assert_contains(&self.stdout_utf8(), expected.as_ref()); + assert_contains(&self.stdout_utf8(), expected); self } @@ -206,14 +206,14 @@ impl CompletedProcess { /// Checks that `stderr` contains `expected`. #[track_caller] pub fn assert_stderr_contains<S: AsRef<str>>(&self, expected: S) -> &Self { - assert_contains(&self.stderr_utf8(), expected.as_ref()); + assert_contains(&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 { - assert_not_contains(&self.stdout_utf8(), unexpected.as_ref()); + assert_not_contains(&self.stdout_utf8(), unexpected); self } diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index df417722e02..294dae10942 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -409,7 +409,9 @@ pub fn read_dir<F: FnMut(&Path)>(dir: impl AsRef<Path>, mut callback: F) { /// Check that `actual` is equal to `expected`. Panic otherwise. #[track_caller] -pub fn assert_equals(actual: &str, expected: &str) { +pub fn assert_equals<S1: AsRef<str>, S2: AsRef<str>>(actual: S1, expected: S2) { + let actual = actual.as_ref(); + let expected = expected.as_ref(); if actual != expected { eprintln!("=== ACTUAL TEXT ==="); eprintln!("{}", actual); @@ -421,7 +423,9 @@ pub fn assert_equals(actual: &str, expected: &str) { /// Check that `haystack` contains `needle`. Panic otherwise. #[track_caller] -pub fn assert_contains(haystack: &str, needle: &str) { +pub fn assert_contains<S1: AsRef<str>, S2: AsRef<str>>(haystack: S1, needle: S2) { + let haystack = haystack.as_ref(); + let needle = needle.as_ref(); if !haystack.contains(needle) { eprintln!("=== HAYSTACK ==="); eprintln!("{}", haystack); @@ -433,7 +437,9 @@ pub fn assert_contains(haystack: &str, needle: &str) { /// Check that `haystack` does not contain `needle`. Panic otherwise. #[track_caller] -pub fn assert_not_contains(haystack: &str, needle: &str) { +pub fn assert_not_contains<S1: AsRef<str>, S2: AsRef<str>>(haystack: S1, needle: S2) { + let haystack = haystack.as_ref(); + let needle = needle.as_ref(); if haystack.contains(needle) { eprintln!("=== HAYSTACK ==="); eprintln!("{}", haystack); diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index df843d74fc9..3f23c1b8f9e 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -201,7 +201,8 @@ impl Rustc { } /// Specify the target triple, or a path to a custom target json spec file. - pub fn target(&mut self, target: &str) -> &mut Self { + pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self { + let target = target.as_ref(); self.cmd.arg(format!("--target={target}")); self } diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs index fb00427b1c1..2be962ad888 100644 --- a/src/tools/run-make-support/src/rustdoc.rs +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -104,7 +104,8 @@ impl Rustdoc { } /// Specify the target triple, or a path to a custom target json spec file. - pub fn target(&mut self, target: &str) -> &mut Self { + pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self { + let target = target.as_ref(); self.cmd.arg(format!("--target={target}")); self } |
