1
1
//! Tests for `[alias]` config command aliases.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use std:: env;
6
4
5
+ use cargo_test_support:: str;
7
6
use cargo_test_support:: tools:: echo_subcommand;
8
7
use cargo_test_support:: { basic_bin_manifest, project} ;
9
8
@@ -23,11 +22,11 @@ fn alias_incorrect_config_type() {
23
22
24
23
p. cargo ( "b-cargo-test -v" )
25
24
. with_status ( 101 )
26
- . with_stderr (
27
- "\
25
+ . with_stderr_data ( str![ [ r#"
28
26
[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
+ "# ] ] )
31
30
. run ( ) ;
32
31
}
33
32
@@ -47,22 +46,21 @@ fn alias_malformed_config_string() {
47
46
48
47
p. cargo ( "b-cargo-test -v" )
49
48
. with_status ( 101 )
50
- . with_stderr (
51
- "\
49
+ . with_stderr_data ( str![ [ r#"
52
50
[ERROR] could not load Cargo configuration
53
51
54
52
Caused by:
55
- could not parse TOML configuration in `[..] /config.toml`
53
+ could not parse TOML configuration in `[ROOT]/foo/.cargo /config.toml`
56
54
57
55
Caused by:
58
- TOML parse error at line [..]
56
+ TOML parse error at line 3, column 32
59
57
|
60
58
3 | b-cargo-test = `
61
59
| ^
62
60
invalid string
63
- expected `\ " `, `'`
64
- " ,
65
- )
61
+ expected `"`, `'`
62
+
63
+ "# ] ] )
66
64
. run ( ) ;
67
65
}
68
66
@@ -82,23 +80,22 @@ fn alias_malformed_config_list() {
82
80
83
81
p. cargo ( "b-cargo-test -v" )
84
82
. with_status ( 101 )
85
- . with_stderr (
86
- "\
83
+ . with_stderr_data ( str![ [ r#"
87
84
[ERROR] could not load Cargo configuration
88
85
89
86
Caused by:
90
- failed to load TOML configuration from `[..] /config.toml`
87
+ failed to load TOML configuration from `[ROOT]/foo/.cargo /config.toml`
91
88
92
89
Caused by:
93
- [..] `alias`
90
+ failed to parse key `alias`
94
91
95
92
Caused by:
96
- [..] `b-cargo-test`
93
+ failed to parse key `b-cargo-test`
97
94
98
95
Caused by:
99
96
expected string but found integer in list
100
- " ,
101
- )
97
+
98
+ "# ] ] )
102
99
. run ( ) ;
103
100
}
104
101
@@ -117,11 +114,12 @@ fn alias_config() {
117
114
. build ( ) ;
118
115
119
116
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
+ "# ] ] )
125
123
. run ( ) ;
126
124
}
127
125
@@ -141,11 +139,12 @@ fn dependent_alias() {
141
139
. build ( ) ;
142
140
143
141
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
+ "# ] ] )
149
148
. run ( ) ;
150
149
}
151
150
@@ -163,13 +162,12 @@ fn builtin_alias_shadowing_external_subcommand() {
163
162
164
163
p. cargo ( "t" )
165
164
. 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
+ "# ] ] )
173
171
. run ( ) ;
174
172
}
175
173
@@ -194,14 +192,14 @@ fn alias_shadowing_external_subcommand() {
194
192
195
193
p. cargo ( "echo" )
196
194
. env ( "PATH" , & path)
197
- . with_stderr ( " \
195
+ . with_stderr_data ( str! [ [ r#"
198
196
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
199
197
This was previously accepted but is being phased out; it will become a hard error in a future release.
200
198
For 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
+ "# ] ] )
205
203
. run ( ) ;
206
204
}
207
205
@@ -229,36 +227,35 @@ fn default_args_alias() {
229
227
p. cargo ( "echo" )
230
228
. env ( "PATH" , & path)
231
229
. with_status ( 101 )
232
- . with_stderr ( " \
230
+ . with_stderr_data ( str! [ [ r#"
233
231
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
234
232
This was previously accepted but is being phased out; it will become a hard error in a future release.
235
233
For 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
+ "# ] ] )
239
237
. run ( ) ;
240
238
241
239
p. cargo ( "test-1" )
242
240
. env ( "PATH" , & path)
243
241
. with_status ( 101 )
244
- . with_stderr ( " \
242
+ . with_stderr_data ( str! [ [ r#"
245
243
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
246
244
This was previously accepted but is being phased out; it will become a hard error in a future release.
247
245
For 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
+ "# ] ] )
251
249
. run ( ) ;
252
250
253
251
// Builtins are not expanded by rule
254
252
p. cargo ( "build" )
255
- . with_stderr (
256
- "\
253
+ . with_stderr_data ( str![ [ r#"
257
254
[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
+ "# ] ] )
262
259
. run ( ) ;
263
260
}
264
261
@@ -280,16 +277,18 @@ fn corecursive_alias() {
280
277
281
278
p. cargo ( "test-1" )
282
279
. 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
+ "# ] ] )
286
284
. run ( ) ;
287
285
288
286
p. cargo ( "test-2" )
289
287
. 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
+ "# ] ] )
293
292
. run ( ) ;
294
293
}
295
294
@@ -308,8 +307,12 @@ fn alias_list_test() {
308
307
. build ( ) ;
309
308
310
309
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
+ "# ] ] )
313
316
. run ( ) ;
314
317
}
315
318
@@ -328,8 +331,12 @@ fn alias_with_flags_config() {
328
331
. build ( ) ;
329
332
330
333
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
+ "# ] ] )
333
340
. run ( ) ;
334
341
}
335
342
@@ -348,13 +355,12 @@ fn alias_cannot_shadow_builtin_command() {
348
355
. build ( ) ;
349
356
350
357
p. cargo ( "build" )
351
- . with_stderr (
352
- "\
358
+ . with_stderr_data ( str![ [ r#"
353
359
[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
+ "# ] ] )
358
364
. run ( ) ;
359
365
}
360
366
@@ -373,13 +379,12 @@ fn alias_override_builtin_alias() {
373
379
. build ( ) ;
374
380
375
381
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
380
385
[RUNNING] `target/debug/foo[EXE]`
381
- " ,
382
- )
386
+
387
+ "# ] ] )
383
388
. run ( ) ;
384
389
}
385
390
@@ -394,7 +399,12 @@ fn builtin_alias_takes_options() {
394
399
)
395
400
. build ( ) ;
396
401
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 ( ) ;
398
408
}
399
409
400
410
#[ cargo_test]
@@ -403,13 +413,12 @@ fn global_options_with_alias() {
403
413
let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
404
414
405
415
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
+ "# ] ] )
413
422
. run ( ) ;
414
423
}
415
424
@@ -422,13 +431,12 @@ fn weird_check() {
422
431
423
432
p. cargo ( "-- check --invalid_argument -some-other-argument" )
424
433
. with_status ( 101 )
425
- . with_stderr (
426
- "\
434
+ . with_stderr_data ( str![ [ r#"
427
435
[ERROR] trailing arguments after built-in command `check` are unsupported: `--invalid_argument -some-other-argument`
428
436
429
437
To pass the arguments to the subcommand, remove `--`
430
- " ,
431
- )
438
+
439
+ "# ] ] )
432
440
. run ( ) ;
433
441
}
434
442
@@ -449,20 +457,18 @@ fn empty_alias() {
449
457
450
458
p. cargo ( "string" )
451
459
. with_status ( 101 )
452
- . with_stderr (
453
- "\
460
+ . with_stderr_data ( str![ [ r#"
454
461
[ERROR] subcommand is required, but `alias.string` is empty
455
- " ,
456
- )
462
+
463
+ "# ] ] )
457
464
. run ( ) ;
458
465
459
466
p. cargo ( "array" )
460
467
. with_status ( 101 )
461
- . with_stderr (
462
- "\
468
+ . with_stderr_data ( str![ [ r#"
463
469
[ERROR] subcommand is required, but `alias.array` is empty
464
- " ,
465
- )
470
+
471
+ "# ] ] )
466
472
. run ( ) ;
467
473
}
468
474
@@ -482,10 +488,9 @@ fn alias_no_subcommand() {
482
488
483
489
p. cargo ( "a" )
484
490
. with_status ( 101 )
485
- . with_stderr (
486
- "\
491
+ . with_stderr_data ( str![ [ r#"
487
492
[ERROR] subcommand is required, add a subcommand to the command alias `alias.a`
488
- " ,
489
- )
493
+
494
+ "# ] ] )
490
495
. run ( ) ;
491
496
}
0 commit comments