Skip to content

Commit 41930ab

Browse files
committed
test: migrate profile_overrides to snapbox
1 parent dbb67df commit 41930ab

File tree

1 file changed

+82
-55
lines changed

1 file changed

+82
-55
lines changed

tests/testsuite/profile_overrides.rs

Lines changed: 82 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! Tests for profile overrides (build-override and per-package overrides).
22
3-
#![allow(deprecated)]
4-
3+
use cargo_test_support::prelude::*;
54
use cargo_test_support::registry::Package;
6-
use cargo_test_support::{basic_lib_manifest, basic_manifest, project};
5+
use cargo_test_support::{basic_lib_manifest, basic_manifest, project, str};
76

87
#[cargo_test]
98
fn profile_override_basic() {
@@ -33,15 +32,15 @@ fn profile_override_basic() {
3332
.build();
3433

3534
p.cargo("check -v")
36-
.with_stderr(
37-
"\
35+
.with_stderr_data(str![[r#"
3836
[LOCKING] 2 packages to latest compatible versions
39-
[CHECKING] bar [..]
37+
[CHECKING] bar v0.5.0 ([ROOT]/foo/bar)
4038
[RUNNING] `rustc --crate-name bar [..] -C opt-level=3 [..]`
41-
[CHECKING] foo [..]
39+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
4240
[RUNNING] `rustc --crate-name foo [..] -C opt-level=1 [..]`
43-
[FINISHED] `dev` profile [optimized + debuginfo] target(s) in [..]",
44-
)
41+
[FINISHED] `dev` profile [optimized + debuginfo] target(s) in [ELAPSED]s
42+
43+
"#]])
4544
.run();
4645
}
4746

@@ -74,20 +73,18 @@ fn profile_override_warnings() {
7473
.file("bar/src/lib.rs", "")
7574
.build();
7675

77-
p.cargo("build")
78-
.with_stderr_contains(
79-
"\
80-
[WARNING] profile package spec `[email protected]` in profile `dev` \
81-
has a version or URL that does not match any of the packages: \
82-
bar v0.5.0 ([..]/foo/bar)
76+
p.cargo("build").with_stderr_data(str![[r#"
77+
...
78+
[WARNING] profile package spec `[email protected]` in profile `dev` has a version or URL that does not match any of the packages: bar v0.5.0 ([ROOT]/foo/bar)
8379
[WARNING] profile package spec `bart` in profile `dev` did not match any packages
8480
85-
<tab>Did you mean `bar`?
81+
Did you mean `bar`?
8682
[WARNING] profile package spec `no-suggestion` in profile `dev` did not match any packages
87-
[COMPILING] [..]
88-
",
89-
)
90-
.run();
83+
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
84+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
85+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
86+
87+
"#]]).run();
9188
}
9289

9390
#[cargo_test]
@@ -134,7 +131,13 @@ fn profile_override_bad_settings() {
134131

135132
p.cargo("check")
136133
.with_status(101)
137-
.with_stderr_contains(format!("Caused by:\n {}", expected))
134+
.with_stderr_data(format!(
135+
"\
136+
...
137+
Caused by:\n {}
138+
",
139+
expected
140+
))
138141
.run();
139142
}
140143
}
@@ -221,24 +224,25 @@ fn profile_override_hierarchy() {
221224
// m2: 2 (as [profile.dev.package.m2])
222225
// m1: 1 (as [profile.dev])
223226

224-
p.cargo("build -v").with_stderr_unordered("\
227+
p.cargo("build -v")
228+
.with_stderr_data(str![[r#"
225229
[LOCKING] 4 packages to latest compatible versions
226-
[COMPILING] m3 [..]
227-
[COMPILING] dep [..]
228-
[RUNNING] `rustc --crate-name m3 --edition=2015 m3/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=4 [..]
229-
[RUNNING] `rustc --crate-name dep[..]dep/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=3 [..]
230-
[RUNNING] `rustc --crate-name m3 --edition=2015 m3/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=1 [..]
231-
[RUNNING] `rustc --crate-name build_script_build --edition=2015 m1/build.rs [..] --crate-type bin --emit=[..]link[..]-C codegen-units=4 [..]
232-
[COMPILING] m2 [..]
233-
[RUNNING] `rustc --crate-name build_script_build --edition=2015 m2/build.rs [..] --crate-type bin --emit=[..]link[..]-C codegen-units=2 [..]
234-
[RUNNING] `[..]/m1-[..]/build-script-build`
235-
[RUNNING] `[..]/m2-[..]/build-script-build`
236-
[RUNNING] `rustc --crate-name m2 --edition=2015 m2/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=2 [..]
237-
[COMPILING] m1 [..]
238-
[RUNNING] `rustc --crate-name m1 --edition=2015 m1/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=1 [..]
239-
[FINISHED] `dev` profile [unoptimized + debuginfo] [..]
240-
",
241-
)
230+
[COMPILING] m3 v0.5.0 ([ROOT]/foo/m3)
231+
[COMPILING] dep v0.5.0 ([ROOT]/dep)
232+
[RUNNING] `rustc --crate-name m3 --edition=2015 m3/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=4 [..]`
233+
[RUNNING] `rustc --crate-name dep [..][ROOT]/dep/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=3 [..]`
234+
[RUNNING] `rustc --crate-name m3 --edition=2015 m3/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=1 [..]`
235+
[RUNNING] `rustc --crate-name build_script_build --edition=2015 m1/build.rs [..] --crate-type bin --emit=[..]link[..]-C codegen-units=4 [..]`
236+
[COMPILING] m2 v0.0.1 ([ROOT]/foo/m2)
237+
[RUNNING] `rustc --crate-name build_script_build --edition=2015 m2/build.rs [..] --crate-type bin --emit=[..]link[..]-C codegen-units=2 [..]`
238+
[RUNNING] `[ROOT]/foo/target/debug/build/m1-[HASH]/build-script-build`
239+
[RUNNING] `[ROOT]/foo/target/debug/build/m2-[HASH]/build-script-build`
240+
[RUNNING] `rustc --crate-name m2 --edition=2015 m2/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=2 [..]`
241+
[COMPILING] m1 v0.0.1 ([ROOT]/foo/m1)
242+
[RUNNING] `rustc --crate-name m1 --edition=2015 m1/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=1 [..]`
243+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
244+
245+
"#]].unordered())
242246
.run();
243247
}
244248

@@ -270,11 +274,12 @@ fn profile_override_spec_multiple() {
270274

271275
p.cargo("check -v")
272276
.with_status(101)
273-
.with_stderr_contains(
274-
"\
275-
[ERROR] multiple package overrides in profile `dev` match package `bar v0.5.0 ([..])`
276-
found package specs: bar, [email protected]",
277-
)
277+
.with_stderr_data(str![[r#"
278+
...
279+
[ERROR] multiple package overrides in profile `dev` match package `bar v0.5.0 ([ROOT]/foo/bar)`
280+
found package specs: bar, [email protected]
281+
282+
"#]])
278283
.run();
279284
}
280285

@@ -302,7 +307,12 @@ fn profile_override_spec_with_version() {
302307
.build();
303308

304309
p.cargo("check -v")
305-
.with_stderr_contains("[RUNNING] `rustc [..]bar/src/lib.rs [..] -C codegen-units=2 [..]")
310+
.with_stderr_data(str![[r#"
311+
...
312+
[CHECKING] bar v0.5.0 ([ROOT]/foo/bar)
313+
[RUNNING] `rustc [..]bar/src/lib.rs [..] -C codegen-units=2 [..]`
314+
...
315+
"#]])
306316
.run();
307317
}
308318

@@ -330,7 +340,12 @@ fn profile_override_spec_with_partial_version() {
330340
.build();
331341

332342
p.cargo("check -v")
333-
.with_stderr_contains("[RUNNING] `rustc [..]bar/src/lib.rs [..] -C codegen-units=2 [..]")
343+
.with_stderr_data(str![[r#"
344+
...
345+
[CHECKING] bar v0.5.0 ([ROOT]/foo/bar)
346+
[RUNNING] `rustc [..]bar/src/lib.rs [..] -C codegen-units=2 [..]`
347+
...
348+
"#]])
334349
.run();
335350
}
336351

@@ -393,11 +408,19 @@ fn profile_override_spec() {
393408
.build();
394409

395410
p.cargo("check -v")
396-
.with_stderr_contains("[RUNNING] `rustc [..]dep1/src/lib.rs [..] -C codegen-units=1 [..]")
397-
.with_stderr_contains("[RUNNING] `rustc [..]dep2/src/lib.rs [..] -C codegen-units=2 [..]")
411+
.with_stderr_data(
412+
str![[r#"
413+
...
414+
[RUNNING] `rustc [..][ROOT]/dep1/src/lib.rs [..] -C codegen-units=1 [..]`
415+
[RUNNING] `rustc [..][ROOT]/dep2/src/lib.rs [..] -C codegen-units=2 [..]`
416+
...
417+
"#]]
418+
.unordered(),
419+
)
398420
.run();
399421
}
400422

423+
#[allow(deprecated)]
401424
#[cargo_test]
402425
fn override_proc_macro() {
403426
Package::new("shared", "1.0.0").publish();
@@ -450,13 +473,18 @@ fn override_proc_macro() {
450473

451474
p.cargo("check -v")
452475
// Shared built for the proc-macro.
453-
.with_stderr_contains("[RUNNING] `rustc [..]--crate-name shared [..]-C codegen-units=4[..]")
476+
.with_stderr_data(str![[r#"
477+
...
478+
[RUNNING] `rustc [..]--crate-name shared [..] -C codegen-units=4[..]`
479+
...
480+
[RUNNING] `rustc [..]--crate-name pm [..] -C codegen-units=4[..]`
481+
...
482+
"#]])
454483
// Shared built for the library.
455484
.with_stderr_line_without(
456485
&["[RUNNING] `rustc --crate-name shared --edition=2015"],
457486
&["-C codegen-units"],
458487
)
459-
.with_stderr_contains("[RUNNING] `rustc [..]--crate-name pm [..]-C codegen-units=4[..]")
460488
.with_stderr_line_without(
461489
&["[RUNNING] `rustc [..]--crate-name foo"],
462490
&["-C codegen-units"],
@@ -485,13 +513,12 @@ fn no_warning_ws() {
485513
.build();
486514

487515
p.cargo("check -p b")
488-
.with_stderr(
489-
"\
516+
.with_stderr_data(str![[r#"
490517
[LOCKING] 2 packages to latest compatible versions
491-
[CHECKING] b [..]
492-
[FINISHED] [..]
493-
",
494-
)
518+
[CHECKING] b v0.1.0 ([ROOT]/foo/b)
519+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
520+
521+
"#]])
495522
.run();
496523
}
497524

0 commit comments

Comments
 (0)