Skip to content

Commit 02e58d3

Browse files
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`
2 parents 94c0bbb + fcfac05 commit 02e58d3

File tree

8 files changed

+22
-14
lines changed

8 files changed

+22
-14
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);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ impl Rustc {
201201
}
202202

203203
/// Specify the target triple, or a path to a custom target json spec file.
204-
pub fn target(&mut self, target: &str) -> &mut Self {
204+
pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self {
205+
let target = target.as_ref();
205206
self.cmd.arg(format!("--target={target}"));
206207
self
207208
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ impl Rustdoc {
104104
}
105105

106106
/// Specify the target triple, or a path to a custom target json spec file.
107-
pub fn target(&mut self, target: &str) -> &mut Self {
107+
pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self {
108+
let target = target.as_ref();
108109
self.cmd.arg(format!("--target={target}"));
109110
self
110111
}

tests/run-make/comment-section/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
.stdin("fn main() {}")
2222
.emit("link,obj")
2323
.arg("-Csave-temps")
24-
.target(&target)
24+
.target(target)
2525
.run();
2626

2727
// Check linked output has a `.comment` section with the expected content.

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

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

tests/run-make/inaccessible-temp-dir/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
// Run rustc with `-Z temps-dir` set to a directory *inside* the inaccessible one,
2929
// so that it can't create `tmp`.
3030
rustc()
31-
.target(&target())
31+
.target(target())
3232
.input("program.rs")
3333
.arg("-Ztemps-dir=inaccessible/tmp")
3434
.run_fail()

tests/run-make/static-pie/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn test(compiler: &str) {
5151

5252
rustc()
5353
.input("test-aslr.rs")
54-
.target(&target())
54+
.target(target())
5555
.linker(compiler)
5656
.arg("-Clinker-flavor=gcc")
5757
.arg("-Ctarget-feature=+crt-static")

0 commit comments

Comments
 (0)