Skip to content

Commit b5b97dc

Browse files
Improve run-make-support API for assert* functions
1 parent 7b21c18 commit b5b97dc

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/tools/run-make-support/src/command.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ impl CompletedProcess {
185185
/// Checks that `stdout` does not contain `unexpected`.
186186
#[track_caller]
187187
pub fn assert_stdout_not_contains<S: AsRef<str>>(&self, unexpected: S) -> &Self {
188-
assert_not_contains(&self.stdout_utf8(), unexpected.as_ref());
188+
assert_not_contains(&self.stdout_utf8(), unexpected);
189189
self
190190
}
191191

192192
/// Checks that `stdout` contains `expected`.
193193
#[track_caller]
194194
pub fn assert_stdout_contains<S: AsRef<str>>(&self, expected: S) -> &Self {
195-
assert_contains(&self.stdout_utf8(), expected.as_ref());
195+
assert_contains(&self.stdout_utf8(), expected);
196196
self
197197
}
198198

@@ -206,14 +206,14 @@ impl CompletedProcess {
206206
/// Checks that `stderr` contains `expected`.
207207
#[track_caller]
208208
pub fn assert_stderr_contains<S: AsRef<str>>(&self, expected: S) -> &Self {
209-
assert_contains(&self.stderr_utf8(), expected.as_ref());
209+
assert_contains(&self.stderr_utf8(), expected);
210210
self
211211
}
212212

213213
/// Checks that `stderr` does not contain `unexpected`.
214214
#[track_caller]
215215
pub fn assert_stderr_not_contains<S: AsRef<str>>(&self, unexpected: S) -> &Self {
216-
assert_not_contains(&self.stdout_utf8(), unexpected.as_ref());
216+
assert_not_contains(&self.stdout_utf8(), unexpected);
217217
self
218218
}
219219

src/tools/run-make-support/src/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ pub fn read_dir<F: FnMut(&Path)>(dir: impl AsRef<Path>, mut callback: F) {
409409

410410
/// Check that `actual` is equal to `expected`. Panic otherwise.
411411
#[track_caller]
412-
pub fn assert_equals(actual: &str, expected: &str) {
412+
pub fn assert_equals<S1: AsRef<str>, S2: AsRef<str>>(actual: S1, expected: S2) {
413+
let actual = actual.as_ref();
414+
let expected = expected.as_ref();
413415
if actual != expected {
414416
eprintln!("=== ACTUAL TEXT ===");
415417
eprintln!("{}", actual);
@@ -421,7 +423,9 @@ pub fn assert_equals(actual: &str, expected: &str) {
421423

422424
/// Check that `haystack` contains `needle`. Panic otherwise.
423425
#[track_caller]
424-
pub fn assert_contains(haystack: &str, needle: &str) {
426+
pub fn assert_contains<S1: AsRef<str>, S2: AsRef<str>>(haystack: S1, needle: S2) {
427+
let haystack = haystack.as_ref();
428+
let needle = needle.as_ref();
425429
if !haystack.contains(needle) {
426430
eprintln!("=== HAYSTACK ===");
427431
eprintln!("{}", haystack);
@@ -433,7 +437,9 @@ pub fn assert_contains(haystack: &str, needle: &str) {
433437

434438
/// Check that `haystack` does not contain `needle`. Panic otherwise.
435439
#[track_caller]
436-
pub fn assert_not_contains(haystack: &str, needle: &str) {
440+
pub fn assert_not_contains<S1: AsRef<str>, S2: AsRef<str>>(haystack: S1, needle: S2) {
441+
let haystack = haystack.as_ref();
442+
let needle = needle.as_ref();
437443
if haystack.contains(needle) {
438444
eprintln!("=== HAYSTACK ===");
439445
eprintln!("{}", haystack);

tests/run-make/compressed-debuginfo/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ fn check_compression(compression: &str, to_find: &str) {
2323
cmd("readelf").arg("-t").arg("foo.o").run().assert_stdout_contains(to_find);
2424
} else {
2525
assert_contains(
26-
&stderr,
27-
&format!("unknown debuginfo compression algorithm {compression}"),
26+
stderr,
27+
format!("unknown debuginfo compression algorithm {compression}"),
2828
);
2929
}
3030
});

0 commit comments

Comments
 (0)