11//! Tests for `[alias]` config command aliases.
22
3- #![ allow( deprecated) ]
4-
53use std:: env;
64
5+ use cargo_test_support:: str;
76use cargo_test_support:: tools:: echo_subcommand;
87use cargo_test_support:: { basic_bin_manifest, project} ;
98
@@ -23,11 +22,11 @@ fn alias_incorrect_config_type() {
2322
2423 p. cargo ( "b-cargo-test -v" )
2524 . with_status ( 101 )
26- . with_stderr (
27- "\
25+ . with_stderr_data ( str![ [ r#"
2826[ERROR] invalid configuration for key `alias.b-cargo-test`
29- expected a list, but found a integer for [..]" ,
30- )
27+ expected a list, but found a integer for `alias.b-cargo-test` in [ROOT]/foo/.cargo/config.toml
28+
29+ "# ] ] )
3130 . run ( ) ;
3231}
3332
@@ -47,22 +46,21 @@ fn alias_malformed_config_string() {
4746
4847 p. cargo ( "b-cargo-test -v" )
4948 . with_status ( 101 )
50- . with_stderr (
51- "\
49+ . with_stderr_data ( str![ [ r#"
5250[ERROR] could not load Cargo configuration
5351
5452Caused by:
55- could not parse TOML configuration in `[..] /config.toml`
53+ could not parse TOML configuration in `[ROOT]/foo/.cargo /config.toml`
5654
5755Caused by:
58- TOML parse error at line [..]
56+ TOML parse error at line 3, column 32
5957 |
6058 3 | b-cargo-test = `
6159 | ^
6260 invalid string
63- expected `\ " `, `'`
64- " ,
65- )
61+ expected `"`, `'`
62+
63+ "# ] ] )
6664 . run ( ) ;
6765}
6866
@@ -82,23 +80,22 @@ fn alias_malformed_config_list() {
8280
8381 p. cargo ( "b-cargo-test -v" )
8482 . with_status ( 101 )
85- . with_stderr (
86- "\
83+ . with_stderr_data ( str![ [ r#"
8784[ERROR] could not load Cargo configuration
8885
8986Caused by:
90- failed to load TOML configuration from `[..] /config.toml`
87+ failed to load TOML configuration from `[ROOT]/foo/.cargo /config.toml`
9188
9289Caused by:
93- [..] `alias`
90+ failed to parse key `alias`
9491
9592Caused by:
96- [..] `b-cargo-test`
93+ failed to parse key `b-cargo-test`
9794
9895Caused by:
9996 expected string but found integer in list
100- " ,
101- )
97+
98+ "# ] ] )
10299 . run ( ) ;
103100}
104101
@@ -117,11 +114,12 @@ fn alias_config() {
117114 . build ( ) ;
118115
119116 p. cargo ( "b-cargo-test -v" )
120- . with_stderr_contains (
121- "\
122- [COMPILING] foo v0.5.0 [..]
123- [RUNNING] `rustc --crate-name foo [..]" ,
124- )
117+ . with_stderr_data ( str![ [ r#"
118+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
119+ [RUNNING] `rustc --crate-name foo [..]
120+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
121+
122+ "# ] ] )
125123 . run ( ) ;
126124}
127125
@@ -141,11 +139,12 @@ fn dependent_alias() {
141139 . build ( ) ;
142140
143141 p. cargo ( "a-cargo-test" )
144- . with_stderr_contains (
145- "\
146- [COMPILING] foo v0.5.0 [..]
147- [RUNNING] `rustc --crate-name foo [..]" ,
148- )
142+ . with_stderr_data ( str![ [ r#"
143+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
144+ [RUNNING] `rustc --crate-name foo [..]
145+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
146+
147+ "# ] ] )
149148 . run ( ) ;
150149}
151150
@@ -163,13 +162,12 @@ fn builtin_alias_shadowing_external_subcommand() {
163162
164163 p. cargo ( "t" )
165164 . env ( "PATH" , & path)
166- . with_stderr (
167- "\
168- [COMPILING] foo v0.5.0 [..]
169- [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]
170- [RUNNING] unittests src/main.rs [..]
171- " ,
172- )
165+ . with_stderr_data ( str![ [ r#"
166+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
167+ [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
168+ [RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH][EXE])
169+
170+ "# ] ] )
173171 . run ( ) ;
174172}
175173
@@ -194,14 +192,14 @@ fn alias_shadowing_external_subcommand() {
194192
195193 p. cargo ( "echo" )
196194 . env ( "PATH" , & path)
197- . with_stderr ( " \
195+ . with_stderr_data ( str! [ [ r#"
198196[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
199197This was previously accepted but is being phased out; it will become a hard error in a future release.
200198For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
201- [COMPILING] foo v0.5.0 [..]
202- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
203- " ,
204- )
199+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
200+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
201+
202+ "# ] ] )
205203 . run ( ) ;
206204}
207205
@@ -229,36 +227,35 @@ fn default_args_alias() {
229227 p. cargo ( "echo" )
230228 . env ( "PATH" , & path)
231229 . with_status ( 101 )
232- . with_stderr ( " \
230+ . with_stderr_data ( str! [ [ r#"
233231[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
234232This was previously accepted but is being phased out; it will become a hard error in a future release.
235233For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
236- error: alias echo has unresolvable recursive definition: echo -> echo
237- " ,
238- )
234+ [ERROR] alias echo has unresolvable recursive definition: echo -> echo
235+
236+ "# ] ] )
239237 . run ( ) ;
240238
241239 p. cargo ( "test-1" )
242240 . env ( "PATH" , & path)
243241 . with_status ( 101 )
244- . with_stderr ( " \
242+ . with_stderr_data ( str! [ [ r#"
245243[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
246244This was previously accepted but is being phased out; it will become a hard error in a future release.
247245For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
248- error: alias test-1 has unresolvable recursive definition: test-1 -> echo -> echo
249- " ,
250- )
246+ [ERROR] alias test-1 has unresolvable recursive definition: test-1 -> echo -> echo
247+
248+ "# ] ] )
251249 . run ( ) ;
252250
253251 // Builtins are not expanded by rule
254252 p. cargo ( "build" )
255- . with_stderr (
256- "\
253+ . with_stderr_data ( str![ [ r#"
257254[WARNING] user-defined alias `build` is ignored, because it is shadowed by a built-in command
258- [COMPILING] foo v0.5.0 ([..] )
259- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
260- " ,
261- )
255+ [COMPILING] foo v0.5.0 ([ROOT]/foo )
256+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
257+
258+ "# ] ] )
262259 . run ( ) ;
263260}
264261
@@ -280,16 +277,18 @@ fn corecursive_alias() {
280277
281278 p. cargo ( "test-1" )
282279 . with_status ( 101 )
283- . with_stderr (
284- "error: alias test-1 has unresolvable recursive definition: test-1 -> test-2 -> test-3 -> test-1" ,
285- )
280+ . with_stderr_data ( str![ [ r#"
281+ [ERROR] alias test-1 has unresolvable recursive definition: test-1 -> test-2 -> test-3 -> test-1
282+
283+ "# ] ] )
286284 . run ( ) ;
287285
288286 p. cargo ( "test-2" )
289287 . with_status ( 101 )
290- . with_stderr (
291- "error: alias test-2 has unresolvable recursive definition: test-2 -> test-3 -> test-1 -> test-2" ,
292- )
288+ . with_stderr_data ( str![ [ r#"
289+ [ERROR] alias test-2 has unresolvable recursive definition: test-2 -> test-3 -> test-1 -> test-2
290+
291+ "# ] ] )
293292 . run ( ) ;
294293}
295294
@@ -308,8 +307,12 @@ fn alias_list_test() {
308307 . build ( ) ;
309308
310309 p. cargo ( "b-cargo-test -v" )
311- . with_stderr_contains ( "[COMPILING] foo v0.5.0 [..]" )
312- . with_stderr_contains ( "[RUNNING] `rustc --crate-name [..]" )
310+ . with_stderr_data ( str![ [ r#"
311+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
312+ [RUNNING] `rustc --crate-name foo [..]
313+ [FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
314+
315+ "# ] ] )
313316 . run ( ) ;
314317}
315318
@@ -328,8 +331,12 @@ fn alias_with_flags_config() {
328331 . build ( ) ;
329332
330333 p. cargo ( "b-cargo-test -v" )
331- . with_stderr_contains ( "[COMPILING] foo v0.5.0 [..]" )
332- . with_stderr_contains ( "[RUNNING] `rustc --crate-name foo [..]" )
334+ . with_stderr_data ( str![ [ r#"
335+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
336+ [RUNNING] `rustc --crate-name foo [..]
337+ [FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
338+
339+ "# ] ] )
333340 . run ( ) ;
334341}
335342
@@ -348,13 +355,12 @@ fn alias_cannot_shadow_builtin_command() {
348355 . build ( ) ;
349356
350357 p. cargo ( "build" )
351- . with_stderr (
352- "\
358+ . with_stderr_data ( str![ [ r#"
353359[WARNING] user-defined alias `build` is ignored, because it is shadowed by a built-in command
354- [COMPILING] foo v0.5.0 ([..] )
355- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
356- " ,
357- )
360+ [COMPILING] foo v0.5.0 ([ROOT]/foo )
361+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
362+
363+ "# ] ] )
358364 . run ( ) ;
359365}
360366
@@ -373,13 +379,12 @@ fn alias_override_builtin_alias() {
373379 . build ( ) ;
374380
375381 p. cargo ( "b" )
376- . with_stderr (
377- "\
378- [COMPILING] foo v0.5.0 ([..])
379- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
382+ . with_stderr_data ( str![ [ r#"
383+ [COMPILING] foo v0.5.0 ([ROOT]/foo)
384+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
380385[RUNNING] `target/debug/foo[EXE]`
381- " ,
382- )
386+
387+ "# ] ] )
383388 . run ( ) ;
384389}
385390
@@ -394,7 +399,12 @@ fn builtin_alias_takes_options() {
394399 )
395400 . build ( ) ;
396401
397- p. cargo ( "r --example ex1 -- asdf" ) . with_stdout ( "asdf" ) . run ( ) ;
402+ p. cargo ( "r --example ex1 -- asdf" )
403+ . with_stdout_data ( str![ [ r#"
404+ asdf
405+
406+ "# ] ] )
407+ . run ( ) ;
398408}
399409
400410#[ cargo_test]
@@ -403,13 +413,12 @@ fn global_options_with_alias() {
403413 let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
404414
405415 p. cargo ( "-v c" )
406- . with_stderr (
407- "\
408- [CHECKING] foo [..]
409- [RUNNING] `rustc [..]
410- [FINISHED] `dev` profile [..]
411- " ,
412- )
416+ . with_stderr_data ( str![ [ r#"
417+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
418+ [RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]
419+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
420+
421+ "# ] ] )
413422 . run ( ) ;
414423}
415424
@@ -422,13 +431,12 @@ fn weird_check() {
422431
423432 p. cargo ( "-- check --invalid_argument -some-other-argument" )
424433 . with_status ( 101 )
425- . with_stderr (
426- "\
434+ . with_stderr_data ( str![ [ r#"
427435[ERROR] trailing arguments after built-in command `check` are unsupported: `--invalid_argument -some-other-argument`
428436
429437To pass the arguments to the subcommand, remove `--`
430- " ,
431- )
438+
439+ "# ] ] )
432440 . run ( ) ;
433441}
434442
@@ -449,20 +457,18 @@ fn empty_alias() {
449457
450458 p. cargo ( "string" )
451459 . with_status ( 101 )
452- . with_stderr (
453- "\
460+ . with_stderr_data ( str![ [ r#"
454461[ERROR] subcommand is required, but `alias.string` is empty
455- " ,
456- )
462+
463+ "# ] ] )
457464 . run ( ) ;
458465
459466 p. cargo ( "array" )
460467 . with_status ( 101 )
461- . with_stderr (
462- "\
468+ . with_stderr_data ( str![ [ r#"
463469[ERROR] subcommand is required, but `alias.array` is empty
464- " ,
465- )
470+
471+ "# ] ] )
466472 . run ( ) ;
467473}
468474
@@ -482,10 +488,9 @@ fn alias_no_subcommand() {
482488
483489 p. cargo ( "a" )
484490 . with_status ( 101 )
485- . with_stderr (
486- "\
491+ . with_stderr_data ( str![ [ r#"
487492[ERROR] subcommand is required, add a subcommand to the command alias `alias.a`
488- " ,
489- )
493+
494+ "# ] ] )
490495 . run ( ) ;
491496}
0 commit comments