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