11//! Tests for profiles defined in config files.
22
3- #![ allow( deprecated) ]
4-
53use cargo_test_support:: paths:: CargoPathExt ;
4+ use cargo_test_support:: prelude:: * ;
65use cargo_test_support:: registry:: Package ;
7- use cargo_test_support:: { basic_lib_manifest, paths, project} ;
6+ use cargo_test_support:: { basic_lib_manifest, paths, project, str } ;
87use cargo_util_schemas:: manifest:: TomlDebugInfo ;
98
109// TODO: this should be remove once -Zprofile-rustflags is stabilized
@@ -33,18 +32,23 @@ fn rustflags_works_with_zflag() {
3332 p. cargo ( "check -v" )
3433 . masquerade_as_nightly_cargo ( & [ "profile-rustflags" ] )
3534 . with_status ( 101 )
36- . with_stderr_contains ( "[..]feature `profile-rustflags` is required[..]" )
35+ . with_stderr_data ( str![ [ r#"
36+ [ERROR] config profile `dev` is not valid (defined in `[ROOT]/foo/.cargo/config.toml`)
37+
38+ Caused by:
39+ feature `profile-rustflags` is required
40+ ...
41+ "# ] ] )
3742 . run ( ) ;
3843
3944 p. cargo ( "check -v -Zprofile-rustflags" )
4045 . masquerade_as_nightly_cargo ( & [ "profile-rustflags" ] )
41- . with_stderr (
42- "\
43- [CHECKING] foo [..]
44- [RUNNING] `rustc --crate-name foo [..] -C link-dead-code=yes [..]
45- [FINISHED] [..]
46- " ,
47- )
46+ . with_stderr_data ( str![ [ r#"
47+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
48+ [RUNNING] `rustc --crate-name foo [..] -C link-dead-code=yes [..]`
49+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
50+
51+ "# ] ] )
4852 . run ( ) ;
4953
5054 p. change_file (
@@ -60,12 +64,11 @@ fn rustflags_works_with_zflag() {
6064
6165 p. cargo ( "check -v" )
6266 . masquerade_as_nightly_cargo ( & [ "profile-rustflags" ] )
63- . with_stderr (
64- "\
65- [FRESH] foo [..]
66- [FINISHED] [..]
67- " ,
68- )
67+ . with_stderr_data ( str![ [ r#"
68+ [FRESH] foo v0.0.1 ([ROOT]/foo)
69+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
70+
71+ "# ] ] )
6972 . run ( ) ;
7073}
7174
@@ -95,17 +98,14 @@ fn profile_config_validate_warnings() {
9598 )
9699 . build ( ) ;
97100
98- p. cargo ( "build" )
99- . with_stderr_unordered (
100- "\
101- [WARNING] unused config key `profile.dev.bad-key` in `[..].cargo/config.toml`
102- [WARNING] unused config key `profile.dev.package.bar.bad-key-bar` in `[..].cargo/config.toml`
103- [WARNING] unused config key `profile.dev.build-override.bad-key-bo` in `[..].cargo/config.toml`
104- [COMPILING] foo [..]
105- [FINISHED] [..]
106- " ,
107- )
108- . run ( ) ;
101+ p. cargo ( "build" ) . with_stderr_data ( str![ [ r#"
102+ [WARNING] unused config key `profile.dev.bad-key` in `[ROOT]/foo/.cargo/config.toml`
103+ [WARNING] unused config key `profile.dev.build-override.bad-key-bo` in `[ROOT]/foo/.cargo/config.toml`
104+ [WARNING] unused config key `profile.dev.package.bar.bad-key-bar` in `[ROOT]/foo/.cargo/config.toml`
105+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
106+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
107+
108+ "# ] ] . unordered ( ) ) . run ( ) ;
109109}
110110
111111#[ cargo_test]
@@ -132,14 +132,13 @@ fn profile_config_error_paths() {
132132
133133 p. cargo ( "build" )
134134 . with_status ( 101 )
135- . with_stderr (
136- "\
137- [ERROR] error in [..]/foo/.cargo/config.toml: could not load config key `profile.dev`
135+ . with_stderr_data ( str![ [ r#"
136+ [ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `profile.dev`
138137
139138Caused by:
140- error in [.. ]/home/.cargo/config.toml: `profile.dev.rpath` expected true/false, but found a string
141- " ,
142- )
139+ error in [ROOT ]/home/.cargo/config.toml: `profile.dev.rpath` expected true/false, but found a string
140+
141+ "# ] ] )
143142 . run ( ) ;
144143}
145144
@@ -159,14 +158,13 @@ fn profile_config_validate_errors() {
159158
160159 p. cargo ( "build" )
161160 . with_status ( 101 )
162- . with_stderr (
163- "\
164- [ERROR] config profile `dev` is not valid (defined in `[..]/foo/.cargo/config.toml`)
161+ . with_stderr_data ( str![ [ r#"
162+ [ERROR] config profile `dev` is not valid (defined in `[ROOT]/foo/.cargo/config.toml`)
165163
166164Caused by:
167165 `panic` may not be specified in a `package` profile
168- " ,
169- )
166+
167+ "# ] ] )
170168 . run ( ) ;
171169}
172170
@@ -186,14 +184,13 @@ fn profile_config_syntax_errors() {
186184
187185 p. cargo ( "build" )
188186 . with_status ( 101 )
189- . with_stderr (
190- "\
191- [ERROR] error in [..]/.cargo/config.toml: could not load config key `profile.dev`
187+ . with_stderr_data ( str![ [ r#"
188+ [ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `profile.dev`
192189
193190Caused by:
194- error in [.. ]/foo/.cargo/config.toml: `profile.dev.codegen-units` expected an integer, but found a string
195- " ,
196- )
191+ error in [ROOT ]/foo/.cargo/config.toml: `profile.dev.codegen-units` expected an integer, but found a string
192+
193+ "# ] ] )
197194 . run ( ) ;
198195}
199196
@@ -231,12 +228,12 @@ fn profile_config_override_spec_multiple() {
231228 // much of a problem.
232229 p. cargo ( "build -v" )
233230 . with_status ( 101 )
234- . with_stderr (
235- "\
231+ . with_stderr_data ( str![ [ r#"
236232[LOCKING] 2 packages to latest compatible versions
237- [ERROR] multiple package overrides in profile `dev` match package `bar v0.5.0 ([..])`
238- found package specs: bar, [email protected] " , 239- )
233+ [ERROR] multiple package overrides in profile `dev` match package `bar v0.5.0 ([ROOT]/foo/bar)`
234+ found package specs: bar, [email protected] 235+
236+ "# ] ] )
240237 . run ( ) ;
241238}
242239
@@ -264,22 +261,12 @@ fn profile_config_all_options() {
264261
265262 p. cargo ( "build --release -v" )
266263 . env_remove ( "CARGO_INCREMENTAL" )
267- . with_stderr (
268- "\
269- [COMPILING] foo [..]
270- [RUNNING] `rustc --crate-name foo [..] \
271- -C opt-level=1 \
272- -C panic=abort \
273- -C lto[..]\
274- -C codegen-units=2 \
275- -C debuginfo=2 [..]\
276- -C debug-assertions=on \
277- -C overflow-checks=off [..]\
278- -C rpath [..]\
279- -C incremental=[..]
280- [FINISHED] `release` profile [optimized + debuginfo] [..]
281- " ,
282- )
264+ . with_stderr_data ( str![ [ r#"
265+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
266+ [RUNNING] `rustc --crate-name foo [..] -C opt-level=1 -C panic=abort -C lto[..]-C codegen-units=2 -C debuginfo=2 [..]-C debug-assertions=on -C overflow-checks=off [..]-C rpath --out-dir [ROOT]/foo/target/release/deps -C incremental=[ROOT]/foo/target/release/incremental[..]`
267+ [FINISHED] `release` profile [optimized + debuginfo] target(s) in [ELAPSED]s
268+
269+ "# ] ] )
283270 . run ( ) ;
284271}
285272
@@ -318,18 +305,19 @@ fn profile_config_override_precedence() {
318305 . build ( ) ;
319306
320307 p. cargo ( "build -v" )
321- . with_stderr (
322- "\
308+ . with_stderr_data ( str![ [ r#"
323309[LOCKING] 2 packages to latest compatible versions
324- [COMPILING] bar [..]
325- [RUNNING] `rustc --crate-name bar [..] -C opt-level=2[..]-C codegen-units=2 [..]
326- [COMPILING] foo [..]
327- [RUNNING] `rustc --crate-name foo [..]-C codegen-units=2 [..]
328- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]" ,
329- )
310+ [COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
311+ [RUNNING] `rustc --crate-name bar [..] -C opt-level=2[..]-C codegen-units=2 [..]`
312+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
313+ [RUNNING] `rustc --crate-name foo [..]-C codegen-units=2 [..]`
314+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
315+
316+ "# ] ] )
330317 . run ( ) ;
331318}
332319
320+ #[ allow( deprecated) ]
333321#[ cargo_test]
334322fn profile_config_no_warn_unknown_override ( ) {
335323 let p = project ( )
@@ -371,7 +359,12 @@ fn profile_config_mixed_types() {
371359 . build ( ) ;
372360
373361 p. cargo ( "build -v" )
374- . with_stderr_contains ( "[..]-C opt-level=3 [..]" )
362+ . with_stderr_data ( str![ [ r#"
363+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
364+ [RUNNING] `rustc [..]-C opt-level=3 [..]`
365+ [FINISHED] `dev` profile [optimized + debuginfo] target(s) in [ELAPSED]s
366+
367+ "# ] ] )
375368 . run ( ) ;
376369}
377370
@@ -486,10 +479,16 @@ fn named_env_profile() {
486479 p. cargo ( "build -v --profile=other" )
487480 . env ( "CARGO_PROFILE_OTHER_CODEGEN_UNITS" , "1" )
488481 . env ( "CARGO_PROFILE_OTHER_INHERITS" , "dev" )
489- . with_stderr_contains ( "[..]-C codegen-units=1 [..]" )
482+ . with_stderr_data ( str![ [ r#"
483+ [COMPILING] foo v0.1.0 ([ROOT]/foo)
484+ [RUNNING] `rustc [..]-C codegen-units=1 [..]`
485+ [FINISHED] `other` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
486+
487+ "# ] ] )
490488 . run ( ) ;
491489}
492490
491+ #[ allow( deprecated) ]
493492#[ cargo_test]
494493fn test_with_dev_profile ( ) {
495494 // The `test` profile inherits from `dev` for both local crates and
@@ -512,20 +511,19 @@ fn test_with_dev_profile() {
512511 . build ( ) ;
513512 p. cargo ( "test --lib --no-run -v" )
514513 . env ( "CARGO_PROFILE_DEV_DEBUG" , "0" )
515- . with_stderr (
516- "\
517- [UPDATING] [..]
514+ . with_stderr_data ( str![ [ r#"
515+ [UPDATING] `dummy-registry` index
518516[LOCKING] 2 packages to latest compatible versions
519- [DOWNLOADING] [..]
520- [DOWNLOADED] [..]
517+ [DOWNLOADING] crates ...
518+ [DOWNLOADED] somedep v1.0.0 (registry `dummy-registry`)
521519[COMPILING] somedep v1.0.0
522- [RUNNING] `rustc --crate-name somedep [..]
523- [COMPILING] foo v0.1.0 [..]
524- [RUNNING] `rustc --crate-name foo [..]
525- [FINISHED] [..]
526- [EXECUTABLE] `[..]/ target/debug/deps/foo-[.. ][EXE]`
527- " ,
528- )
520+ [RUNNING] `rustc --crate-name somedep [..]`
521+ [COMPILING] foo v0.1.0 ([ROOT]/foo)
522+ [RUNNING] `rustc --crate-name foo [..]`
523+ [FINISHED] `test` profile [unoptimized] target(s) in [ELAPSED]s
524+ [EXECUTABLE] `[ROOT]/foo/ target/debug/deps/foo-[HASH ][EXE]`
525+
526+ "# ] ] )
529527 . with_stdout_does_not_contain ( "[..] -C debuginfo=0[..]" )
530528 . run ( ) ;
531529}
0 commit comments