Skip to content

Commit 2d01f40

Browse files
committed
test: migrate tool_paths to snapbox
1 parent 8bdb52f commit 2d01f40

File tree

1 file changed

+105
-109
lines changed

1 file changed

+105
-109
lines changed

tests/testsuite/tool_paths.rs

Lines changed: 105 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Tests for configuration values that point to programs.
22
3-
#![allow(deprecated)]
4-
5-
use cargo_test_support::{basic_lib_manifest, project, rustc_host, rustc_host_env};
3+
use cargo_test_support::{basic_lib_manifest, project, rustc_host, rustc_host_env, str};
64

75
#[cargo_test]
86
fn pathless_tools() {
@@ -24,13 +22,12 @@ fn pathless_tools() {
2422
.build();
2523

2624
foo.cargo("build --verbose")
27-
.with_stderr(
28-
"\
29-
[COMPILING] foo v0.5.0 ([CWD])
30-
[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]`
31-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
32-
",
33-
)
25+
.with_stderr_data(str![[r#"
26+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
27+
[RUNNING] `rustc [..]-C linker=nonexistent-linker [..]`
28+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
29+
30+
"#]])
3431
.run();
3532
}
3633

@@ -50,13 +47,12 @@ fn custom_linker_cfg() {
5047
.build();
5148

5249
foo.cargo("build --verbose")
53-
.with_stderr(
54-
"\
55-
[COMPILING] foo v0.5.0 ([CWD])
56-
[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]`
57-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
58-
",
59-
)
50+
.with_stderr_data(str![[r#"
51+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
52+
[RUNNING] `rustc [..]-C linker=nonexistent-linker [..]`
53+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
54+
55+
"#]])
6056
.run();
6157
}
6258

@@ -83,13 +79,12 @@ fn custom_linker_cfg_precedence() {
8379
.build();
8480

8581
foo.cargo("build --verbose")
86-
.with_stderr(
87-
"\
88-
[COMPILING] foo v0.5.0 ([CWD])
89-
[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]`
90-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
91-
",
92-
)
82+
.with_stderr_data(str![[r#"
83+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
84+
[RUNNING] `rustc [..]-C linker=nonexistent-linker [..]`
85+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
86+
87+
"#]])
9388
.run();
9489
}
9590

@@ -111,13 +106,12 @@ fn custom_linker_cfg_collision() {
111106

112107
foo.cargo("build --verbose")
113108
.with_status(101)
114-
.with_stderr(&format!(
115-
"\
109+
.with_stderr_data(str![[r#"
116110
[ERROR] several matching instances of `target.'cfg(..)'.linker` in configurations
117-
first match `cfg(not(target_arch = \"avr\"))` located in [..]/foo/.cargo/config.toml
118-
second match `cfg(not(target_os = \"none\"))` located in [..]/foo/.cargo/config.toml
119-
",
120-
))
111+
first match `cfg(not(target_arch = "avr"))` located in [ROOT]/foo/.cargo/config.toml
112+
second match `cfg(not(target_os = "none"))` located in [ROOT]/foo/.cargo/config.toml
113+
114+
"#]])
121115
.run();
122116
}
123117

@@ -149,13 +143,12 @@ fn absolute_tools() {
149143
.build();
150144

151145
foo.cargo("build --verbose")
152-
.with_stderr(
153-
"\
154-
[COMPILING] foo v0.5.0 ([CWD])
155-
[RUNNING] `rustc [..] -C linker=[..]bogus/nonexistent-linker [..]`
156-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
157-
",
158-
)
146+
.with_stderr_data(str![[r#"
147+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
148+
[RUNNING] `rustc [..]-C linker=[..]/bogus/nonexistent-linker [..]`
149+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
150+
151+
"#]])
159152
.run();
160153
}
161154

@@ -189,18 +182,14 @@ fn relative_tools() {
189182
)
190183
.build();
191184

192-
let prefix = p.root().into_os_string().into_string().unwrap();
193-
194185
p.cargo("build --verbose")
195186
.cwd("bar")
196-
.with_stderr(&format!(
197-
"\
198-
[COMPILING] bar v0.5.0 ([CWD])
199-
[RUNNING] `rustc [..] -C linker={prefix}/./tools/nonexistent-linker [..]`
200-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
201-
",
202-
prefix = prefix,
203-
))
187+
.with_stderr_data(str![[r#"
188+
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
189+
[RUNNING] `rustc [..]-C linker=[ROOT]/foo/./tools/nonexistent-linker [..]`
190+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
191+
192+
"#]])
204193
.run();
205194
}
206195

@@ -226,38 +215,35 @@ fn custom_runner() {
226215

227216
p.cargo("run -- --param")
228217
.with_status(101)
229-
.with_stderr_contains(
230-
"\
231-
[COMPILING] foo v0.0.1 ([CWD])
232-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
218+
.with_stderr_data(str![[r#"
219+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
220+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
233221
[RUNNING] `nonexistent-runner -r target/debug/foo[EXE] --param`
234-
",
235-
)
222+
...
223+
"#]])
236224
.run();
237225

238226
p.cargo("test --test test --verbose -- --param")
239227
.with_status(101)
240-
.with_stderr_contains(
241-
"\
242-
[COMPILING] foo v0.0.1 ([CWD])
228+
.with_stderr_data(str![[r#"
229+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
243230
[RUNNING] `rustc [..]`
244-
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]
245-
[RUNNING] `nonexistent-runner -r [..]/target/debug/deps/test-[..][EXE] --param`
246-
",
247-
)
231+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
232+
[RUNNING] `nonexistent-runner -r [ROOT]/foo/target/debug/deps/test-[HASH][EXE] --param`
233+
...
234+
"#]])
248235
.run();
249236

250237
p.cargo("bench --bench bench --verbose -- --param")
251238
.with_status(101)
252-
.with_stderr_contains(
253-
"\
254-
[COMPILING] foo v0.0.1 ([CWD])
239+
.with_stderr_data(str![[r#"
240+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
255241
[RUNNING] `rustc [..]`
256242
[RUNNING] `rustc [..]`
257-
[FINISHED] `bench` profile [optimized] target(s) in [..]
258-
[RUNNING] `nonexistent-runner -r [..]/target/release/deps/bench-[..][EXE] --param --bench`
259-
",
260-
)
243+
[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s
244+
[RUNNING] `nonexistent-runner -r [ROOT]/foo/target/release/deps/bench-[HASH][EXE] --param --bench`
245+
...
246+
"#]])
261247
.run();
262248
}
263249

@@ -277,13 +263,12 @@ fn custom_runner_cfg() {
277263

278264
p.cargo("run -- --param")
279265
.with_status(101)
280-
.with_stderr_contains(
281-
"\
282-
[COMPILING] foo v0.0.1 ([CWD])
283-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
266+
.with_stderr_data(str![[r#"
267+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
268+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
284269
[RUNNING] `nonexistent-runner -r target/debug/foo[EXE] --param`
285-
",
286-
)
270+
...
271+
"#]])
287272
.run();
288273
}
289274

@@ -311,13 +296,12 @@ fn custom_runner_cfg_precedence() {
311296

312297
p.cargo("run -- --param")
313298
.with_status(101)
314-
.with_stderr_contains(
315-
"\
316-
[COMPILING] foo v0.0.1 ([CWD])
317-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
299+
.with_stderr_data(str![[r#"
300+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
301+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
318302
[RUNNING] `nonexistent-runner -r target/debug/foo[EXE] --param`
319-
",
320-
)
303+
...
304+
"#]])
321305
.run();
322306
}
323307

@@ -339,13 +323,12 @@ fn custom_runner_cfg_collision() {
339323

340324
p.cargo("run -- --param")
341325
.with_status(101)
342-
.with_stderr(
343-
"\
326+
.with_stderr_data(str![[r#"
344327
[ERROR] several matching instances of `target.'cfg(..)'.runner` in configurations
345-
first match `cfg(not(target_arch = \"avr\"))` located in [..]/foo/.cargo/config.toml
346-
second match `cfg(not(target_os = \"none\"))` located in [..]/foo/.cargo/config.toml
347-
",
348-
)
328+
first match `cfg(not(target_arch = "avr"))` located in [ROOT]/foo/.cargo/config.toml
329+
second match `cfg(not(target_os = "none"))` located in [ROOT]/foo/.cargo/config.toml
330+
331+
"#]])
349332
.run();
350333
}
351334

@@ -361,17 +344,16 @@ fn custom_runner_env() {
361344
// FIXME: Update "Caused by" error message once rust/pull/87704 is merged.
362345
// On Windows, changing to a custom executable resolver has changed the
363346
// error messages.
364-
.with_stderr(&format!(
365-
"\
366-
[COMPILING] foo [..]
367-
[FINISHED] `dev` profile [..]
347+
.with_stderr_data(str![[r#"
348+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
349+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
368350
[RUNNING] `nonexistent-runner --foo target/debug/foo[EXE]`
369351
[ERROR] could not execute process `nonexistent-runner --foo target/debug/foo[EXE]` (never executed)
370352
371353
Caused by:
372-
[..]
373-
"
374-
))
354+
[NOT_FOUND]
355+
356+
"#]])
375357
.run();
376358
}
377359

@@ -397,7 +379,11 @@ fn custom_runner_env_overrides_config() {
397379
p.cargo("run")
398380
.env(&key, "should-run --foo")
399381
.with_status(101)
400-
.with_stderr_contains("[RUNNING] `should-run --foo target/debug/foo[EXE]`")
382+
.with_stderr_data(str![[r#"
383+
...
384+
[RUNNING] `should-run --foo target/debug/foo[EXE]`
385+
...
386+
"#]])
401387
.run();
402388
}
403389

@@ -412,7 +398,12 @@ fn custom_runner_env_true() {
412398

413399
p.cargo("run")
414400
.env(&key, "true")
415-
.with_stderr_contains("[RUNNING] `true target/debug/foo[EXE]`")
401+
.with_stderr_data(str![[r#"
402+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
403+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
404+
[RUNNING] `true target/debug/foo[EXE]`
405+
406+
"#]])
416407
.run();
417408
}
418409

@@ -425,7 +416,11 @@ fn custom_linker_env() {
425416
p.cargo("build -v")
426417
.env(&key, "nonexistent-linker")
427418
.with_status(101)
428-
.with_stderr_contains("[RUNNING] `rustc [..]-C linker=nonexistent-linker [..]")
419+
.with_stderr_data(str![[r#"
420+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
421+
[RUNNING] `rustc [..]-C linker=nonexistent-linker [..]`
422+
...
423+
"#]])
429424
.run();
430425
}
431426

@@ -442,11 +437,13 @@ fn target_in_environment_contains_lower_case() {
442437
p.cargo("build -v --target")
443438
.arg(target)
444439
.env(&env_key, "nonexistent-linker")
445-
.with_stderr_contains(format!(
446-
"warning: environment variables are expected to use uppercase \
447-
letters and underscores, the variable `{}` will be ignored and \
448-
have no effect",
449-
env_key
440+
.with_stderr_data(format!("\
441+
[WARNING] environment variables are expected to use uppercase letters and underscores, the variable `{env_key}` will be ignored and have no effect
442+
[WARNING] environment variables are expected to use uppercase letters and underscores, the variable `{env_key}` will be ignored and have no effect
443+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
444+
[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]`
445+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
446+
"
450447
))
451448
.run();
452449
}
@@ -476,15 +473,14 @@ fn cfg_ignored_fields() {
476473
.build();
477474

478475
p.cargo("check")
479-
.with_stderr(
480-
"\
476+
.with_stderr_data(str![[r#"
481477
[WARNING] unused key `somelib` in [target] config table `cfg(not(bar))`
482-
[WARNING] unused key `ar` in [target] config table `cfg(not(target_os = \"none\"))`
483-
[WARNING] unused key `foo` in [target] config table `cfg(not(target_os = \"none\"))`
484-
[WARNING] unused key `invalid` in [target] config table `cfg(not(target_os = \"none\"))`
485-
[CHECKING] foo v0.0.1 ([..])
486-
[FINISHED] [..]
487-
",
488-
)
478+
[WARNING] unused key `ar` in [target] config table `cfg(not(target_os = "none"))`
479+
[WARNING] unused key `foo` in [target] config table `cfg(not(target_os = "none"))`
480+
[WARNING] unused key `invalid` in [target] config table `cfg(not(target_os = "none"))`
481+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
482+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
483+
484+
"#]])
489485
.run();
490486
}

0 commit comments

Comments
 (0)