@@ -142,6 +142,10 @@ fn clean_multiple_packages_in_glob_char_path() {
142142 p. cargo ( "clean -p foo" )
143143 . arg ( "-Zbuild-dir-new-layout" )
144144 . masquerade_as_nightly_cargo ( & [ "new build-dir layout" ] )
145+ . with_stderr_data ( str![ [ r#"
146+ [REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
147+
148+ "# ] ] )
145149 . run ( ) ;
146150 assert_eq ! ( get_build_artifacts( foo_path, file_glob) . len( ) , 0 ) ;
147151}
@@ -598,7 +602,7 @@ fn package_cleans_all_the_things() {
598602 . arg ( "-Zbuild-dir-new-layout" )
599603 . masquerade_as_nightly_cargo ( & [ "new build-dir layout" ] )
600604 . run ( ) ;
601- // assert_all_clean(&p.build_dir()); // FIXME
605+ assert_all_clean ( & p. build_dir ( ) ) ;
602606 }
603607 let p = project ( )
604608 . file (
@@ -657,7 +661,7 @@ fn package_cleans_all_the_things() {
657661 . arg ( "-Zbuild-dir-new-layout" )
658662 . masquerade_as_nightly_cargo ( & [ "new build-dir layout" ] )
659663 . run ( ) ;
660- // assert_all_clean(&p.build_dir()); // FIXME
664+ assert_all_clean ( & p. build_dir ( ) ) ;
661665
662666 // Try some targets.
663667 p. cargo ( "build --all-targets --target" )
@@ -670,7 +674,43 @@ fn package_cleans_all_the_things() {
670674 . arg ( "-Zbuild-dir-new-layout" )
671675 . masquerade_as_nightly_cargo ( & [ "new build-dir layout" ] )
672676 . run ( ) ;
673- //assert_all_clean(&p.build_dir()); // FIXME
677+ assert_all_clean ( & p. build_dir ( ) ) ;
678+ }
679+
680+ // Ensures that all files for the package have been deleted.
681+ #[ track_caller]
682+ fn assert_all_clean ( build_dir : & Path ) {
683+ let walker = walkdir:: WalkDir :: new ( build_dir) . into_iter ( ) ;
684+ for entry in walker. filter_entry ( |e| {
685+ let path = e. path ( ) ;
686+ // This is a known limitation, clean can't differentiate between
687+ // the different build scripts from different packages.
688+ !( path
689+ . file_name ( )
690+ . unwrap ( )
691+ . to_str ( )
692+ . unwrap ( )
693+ . starts_with ( "build_script_build" )
694+ && path
695+ . parent ( )
696+ . unwrap ( )
697+ . file_name ( )
698+ . unwrap ( )
699+ . to_str ( )
700+ . unwrap ( )
701+ == "incremental" )
702+ } ) {
703+ let entry = entry. unwrap ( ) ;
704+ let path = entry. path ( ) ;
705+ if let ".rustc_info.json" | ".cargo-lock" | "CACHEDIR.TAG" =
706+ path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( )
707+ {
708+ continue ;
709+ }
710+ if path. is_symlink ( ) || path. is_file ( ) {
711+ panic ! ( "{:?} was not cleaned" , path) ;
712+ }
713+ }
674714}
675715
676716#[ cargo_test]
0 commit comments