11//! Tests for caching compiler diagnostics.
22
3- #![ allow( deprecated) ]
4-
53use super :: messages:: raw_rustc_output;
4+ use cargo_test_support:: str;
65use cargo_test_support:: tools;
76use cargo_test_support:: { basic_manifest, is_coarse_mtime, project, registry:: Package , sleep_ms} ;
87
@@ -160,7 +159,17 @@ fn clears_cache_after_fix() {
160159 // Make sure the cache is invalidated when there is no output.
161160 let p = project ( ) . file ( "src/lib.rs" , "fn asdf() {}" ) . build ( ) ;
162161 // 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 ( ) ;
164173 let cpath = p
165174 . glob ( "target/debug/.fingerprint/foo-*/output-*" )
166175 . next ( )
@@ -175,13 +184,12 @@ fn clears_cache_after_fix() {
175184 p. change_file ( "src/lib.rs" , "" ) ;
176185
177186 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+ "# ] ] )
185193 . run ( ) ;
186194 assert_eq ! (
187195 p. glob( "target/debug/.fingerprint/foo-*/output-*" ) . count( ) ,
@@ -190,12 +198,11 @@ fn clears_cache_after_fix() {
190198
191199 // And again, check the cache is correct.
192200 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+ "# ] ] )
199206 . run ( ) ;
200207}
201208
@@ -267,13 +274,41 @@ fn very_verbose() {
267274 . build ( ) ;
268275
269276 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+ )
271292 . run ( ) ;
272293
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 ( ) ;
274300
275301 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+ )
277312 . run ( ) ;
278313}
279314
@@ -346,25 +381,23 @@ fn replay_non_json() {
346381 let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
347382 p. cargo ( "check" )
348383 . 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)
352386line 1
353387line 2
354- [FINISHED] `dev` profile [..]
355- " ,
356- )
388+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
389+
390+ "# ] ] )
357391 . run ( ) ;
358392
359393 p. cargo ( "check" )
360394 . env ( "RUSTC" , rustc. bin ( "rustc_alt" ) )
361- . with_stderr (
362- "\
395+ . with_stderr_data ( str![ [ r#"
363396line 1
364397line 2
365- [FINISHED] `dev` profile [..]
366- " ,
367- )
398+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
399+
400+ "# ] ] )
368401 . run ( ) ;
369402}
370403
@@ -407,28 +440,29 @@ fn caching_large_output() {
407440 let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
408441 p. cargo ( "check" )
409442 . env ( "RUSTC" , rustc. bin ( "rustc_alt" ) )
410- . with_stderr ( & format ! (
443+ . with_stderr_data ( & format ! (
411444 "\
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
415448" ,
416449 expected
417450 ) )
418451 . run ( ) ;
419452
420453 p. cargo ( "check" )
421454 . env ( "RUSTC" , rustc. bin ( "rustc_alt" ) )
422- . with_stderr ( & format ! (
455+ . with_stderr_data ( & format ! (
423456 "\
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
426459" ,
427460 expected
428461 ) )
429462 . run ( ) ;
430463}
431464
465+ #[ allow( deprecated) ]
432466#[ cargo_test]
433467fn rustc_workspace_wrapper ( ) {
434468 let p = project ( )
@@ -441,18 +475,29 @@ fn rustc_workspace_wrapper() {
441475
442476 p. cargo ( "check -v" )
443477 . 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+ " ,
446488 )
447489 . run ( ) ;
448490
449491 // Check without a wrapper should rebuild
450492 p. cargo ( "check -v" )
451- . with_stderr_contains (
493+ . with_stderr_data (
452494 "\
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
456501" ,
457502 )
458503 . with_stdout_does_not_contain (
@@ -463,22 +508,40 @@ fn rustc_workspace_wrapper() {
463508 // Again, reading from the cache.
464509 p. cargo ( "check -v" )
465510 . 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+ )
467522 . with_stdout_does_not_contain (
468523 "WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]" ,
469524 )
470525 . run ( ) ;
471526
472527 // And `check` should also be fresh, reading from cache.
473528 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+ )
476538 . with_stdout_does_not_contain (
477539 "WRAPPER CALLED: rustc --crate-name foo --edition=2015 src/lib.rs [..]" ,
478540 )
479541 . run ( ) ;
480542}
481543
544+ #[ allow( deprecated) ]
482545#[ cargo_test]
483546fn wacky_hashless_fingerprint ( ) {
484547 // On Windows, executables don't have hashes. This checks for a bad
@@ -491,7 +554,15 @@ fn wacky_hashless_fingerprint() {
491554 . with_stderr_does_not_contain ( "[..]unused[..]" )
492555 . run ( ) ;
493556 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+ )
495566 . run ( ) ;
496567 // This should not pick up the cache from `a`.
497568 p. cargo ( "check --bin b" )
0 commit comments