1
1
//! Tests for caching compiler diagnostics.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use super :: messages:: raw_rustc_output;
4
+ use cargo_test_support:: str;
6
5
use cargo_test_support:: tools;
7
6
use cargo_test_support:: { basic_manifest, is_coarse_mtime, project, registry:: Package , sleep_ms} ;
8
7
@@ -160,7 +159,17 @@ fn clears_cache_after_fix() {
160
159
// Make sure the cache is invalidated when there is no output.
161
160
let p = project ( ) . file ( "src/lib.rs" , "fn asdf() {}" ) . build ( ) ;
162
161
// Fill the cache.
163
- p. cargo ( "check" ) . with_stderr_contains ( "[..]asdf[..]" ) . run ( ) ;
162
+ p. cargo ( "check" )
163
+ . with_stderr_data (
164
+ "\
165
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
166
+ [WARNING] function `asdf` is never used
167
+ ...
168
+ [WARNING] `foo` (lib) generated 1 warning
169
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
170
+ " ,
171
+ )
172
+ . run ( ) ;
164
173
let cpath = p
165
174
. glob ( "target/debug/.fingerprint/foo-*/output-*" )
166
175
. next ( )
@@ -175,13 +184,12 @@ fn clears_cache_after_fix() {
175
184
p. change_file ( "src/lib.rs" , "" ) ;
176
185
177
186
p. cargo ( "check" )
178
- . with_stdout ( "" )
179
- . with_stderr (
180
- "\
181
- [CHECKING] foo [..]
182
- [FINISHED] [..]
183
- " ,
184
- )
187
+ . with_stdout_data ( str![ [ r#""# ] ] )
188
+ . with_stderr_data ( str![ [ r#"
189
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
190
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
191
+
192
+ "# ] ] )
185
193
. run ( ) ;
186
194
assert_eq ! (
187
195
p. glob( "target/debug/.fingerprint/foo-*/output-*" ) . count( ) ,
@@ -190,12 +198,11 @@ fn clears_cache_after_fix() {
190
198
191
199
// And again, check the cache is correct.
192
200
p. cargo ( "check" )
193
- . with_stdout ( "" )
194
- . with_stderr (
195
- "\
196
- [FINISHED] [..]
197
- " ,
198
- )
201
+ . with_stdout_data ( str![ [ r#""# ] ] )
202
+ . with_stderr_data ( str![ [ r#"
203
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
204
+
205
+ "# ] ] )
199
206
. run ( ) ;
200
207
}
201
208
@@ -267,13 +274,41 @@ fn very_verbose() {
267
274
. build ( ) ;
268
275
269
276
p. cargo ( "check -vv" )
270
- . with_stderr_contains ( "[..]not_used[..]" )
277
+ . with_stderr_data (
278
+ "\
279
+ [UPDATING] `dummy-registry` index
280
+ [LOCKING] 2 packages to latest compatible versions
281
+ [DOWNLOADING] crates ...
282
+ [DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
283
+ [CHECKING] bar v1.0.0
284
+ [RUNNING] [..]
285
+ [WARNING] function `not_used` is never used
286
+ ...
287
+ [CHECKING] foo v0.1.0 ([ROOT]/foo)
288
+ [RUNNING] [..]
289
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
290
+ " ,
291
+ )
271
292
. run ( ) ;
272
293
273
- p. cargo ( "check" ) . with_stderr ( "[FINISHED] [..]" ) . run ( ) ;
294
+ p. cargo ( "check" )
295
+ . with_stderr_data ( str![ [ r#"
296
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
297
+
298
+ "# ] ] )
299
+ . run ( ) ;
274
300
275
301
p. cargo ( "check -vv" )
276
- . with_stderr_contains ( "[..]not_used[..]" )
302
+ . with_stderr_data (
303
+ "\
304
+ [FRESH] bar v1.0.0
305
+ [WARNING] function `not_used` is never used
306
+ ...
307
+ [WARNING] `bar` (lib) generated 1 warning
308
+ [FRESH] foo v0.1.0 ([ROOT]/foo)
309
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
310
+ " ,
311
+ )
277
312
. run ( ) ;
278
313
}
279
314
@@ -346,25 +381,23 @@ fn replay_non_json() {
346
381
let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
347
382
p. cargo ( "check" )
348
383
. env ( "RUSTC" , rustc. bin ( "rustc_alt" ) )
349
- . with_stderr (
350
- "\
351
- [CHECKING] foo [..]
384
+ . with_stderr_data ( str![ [ r#"
385
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
352
386
line 1
353
387
line 2
354
- [FINISHED] `dev` profile [..]
355
- " ,
356
- )
388
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
389
+
390
+ "# ] ] )
357
391
. run ( ) ;
358
392
359
393
p. cargo ( "check" )
360
394
. env ( "RUSTC" , rustc. bin ( "rustc_alt" ) )
361
- . with_stderr (
362
- "\
395
+ . with_stderr_data ( str![ [ r#"
363
396
line 1
364
397
line 2
365
- [FINISHED] `dev` profile [..]
366
- " ,
367
- )
398
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
399
+
400
+ "# ] ] )
368
401
. run ( ) ;
369
402
}
370
403
@@ -407,28 +440,29 @@ fn caching_large_output() {
407
440
let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
408
441
p. cargo ( "check" )
409
442
. env ( "RUSTC" , rustc. bin ( "rustc_alt" ) )
410
- . with_stderr ( & format ! (
443
+ . with_stderr_data ( & format ! (
411
444
"\
412
- [CHECKING] foo [..]
413
- {}warning: `foo` (lib) generated 250 warnings
414
- [FINISHED] `dev` profile [..]
445
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
446
+ {}[WARNING] `foo` (lib) generated 250 warnings
447
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
415
448
" ,
416
449
expected
417
450
) )
418
451
. run ( ) ;
419
452
420
453
p. cargo ( "check" )
421
454
. env ( "RUSTC" , rustc. bin ( "rustc_alt" ) )
422
- . with_stderr ( & format ! (
455
+ . with_stderr_data ( & format ! (
423
456
"\
424
- {}warning: `foo` (lib) generated 250 warnings
425
- [FINISHED] `dev` profile [..]
457
+ {}[WARNING] `foo` (lib) generated 250 warnings
458
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
426
459
" ,
427
460
expected
428
461
) )
429
462
. run ( ) ;
430
463
}
431
464
465
+ #[ allow( deprecated) ]
432
466
#[ cargo_test]
433
467
fn rustc_workspace_wrapper ( ) {
434
468
let p = project ( )
@@ -441,18 +475,29 @@ fn rustc_workspace_wrapper() {
441
475
442
476
p. cargo ( "check -v" )
443
477
. env ( "RUSTC_WORKSPACE_WRAPPER" , tools:: echo_wrapper ( ) )
444
- . with_stderr_contains (
445
- "WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]" ,
478
+ . with_stderr_data (
479
+ "\
480
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
481
+ [RUNNING] [..]
482
+ WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]
483
+ [WARNING] function `unused_func` is never used
484
+ ...
485
+ [WARNING] `foo` (lib) generated 1 warning
486
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
487
+ " ,
446
488
)
447
489
. run ( ) ;
448
490
449
491
// Check without a wrapper should rebuild
450
492
p. cargo ( "check -v" )
451
- . with_stderr_contains (
493
+ . with_stderr_data (
452
494
"\
453
- [CHECKING] foo [..]
454
- [RUNNING] `rustc[..]
455
- [WARNING] [..]unused_func[..]
495
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
496
+ [RUNNING] `rustc[..]`
497
+ [WARNING] function `unused_func` is never used
498
+ ...
499
+ [WARNING] `foo` (lib) generated 1 warning
500
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
456
501
" ,
457
502
)
458
503
. with_stdout_does_not_contain (
@@ -463,22 +508,40 @@ fn rustc_workspace_wrapper() {
463
508
// Again, reading from the cache.
464
509
p. cargo ( "check -v" )
465
510
. env ( "RUSTC_WORKSPACE_WRAPPER" , tools:: echo_wrapper ( ) )
466
- . with_stderr_contains ( "[FRESH] foo [..]" )
511
+ . with_stderr_data (
512
+ "\
513
+ [FRESH] foo v0.0.1 ([ROOT]/foo)
514
+ WRAPPER CALLED: rustc [..]
515
+ ...
516
+ [WARNING] function `unused_func` is never used
517
+ ...
518
+ [WARNING] `foo` (lib) generated 1 warning
519
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
520
+ " ,
521
+ )
467
522
. with_stdout_does_not_contain (
468
523
"WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]" ,
469
524
)
470
525
. run ( ) ;
471
526
472
527
// And `check` should also be fresh, reading from cache.
473
528
p. cargo ( "check -v" )
474
- . with_stderr_contains ( "[FRESH] foo [..]" )
475
- . with_stderr_contains ( "[WARNING] [..]unused_func[..]" )
529
+ . with_stderr_data (
530
+ "\
531
+ [FRESH] foo v0.0.1 ([ROOT]/foo)
532
+ [WARNING] function `unused_func` is never used
533
+ ...
534
+ [WARNING] `foo` (lib) generated 1 warning
535
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
536
+ " ,
537
+ )
476
538
. with_stdout_does_not_contain (
477
539
"WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]" ,
478
540
)
479
541
. run ( ) ;
480
542
}
481
543
544
+ #[ allow( deprecated) ]
482
545
#[ cargo_test]
483
546
fn wacky_hashless_fingerprint ( ) {
484
547
// On Windows, executables don't have hashes. This checks for a bad
@@ -491,7 +554,15 @@ fn wacky_hashless_fingerprint() {
491
554
. with_stderr_does_not_contain ( "[..]unused[..]" )
492
555
. run ( ) ;
493
556
p. cargo ( "check --bin a" )
494
- . with_stderr_contains ( "[..]unused[..]" )
557
+ . with_stderr_data (
558
+ "\
559
+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
560
+ [WARNING] unused variable: `unused`
561
+ ...
562
+ [WARNING] `foo` (bin \" a\" ) generated 1 warning
563
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
564
+ " ,
565
+ )
495
566
. run ( ) ;
496
567
// This should not pick up the cache from `a`.
497
568
p. cargo ( "check --bin b" )
0 commit comments