@@ -433,7 +433,7 @@ fn rustfix_coverage_known_exceptions_accuracy() {
433433 let rs_path = Path :: new ( "tests/ui" ) . join ( filename) ;
434434 assert ! (
435435 rs_path. exists( ) ,
436- "`{}` does not exists " ,
436+ "`{}` does not exist " ,
437437 rs_path. strip_prefix( env!( "CARGO_MANIFEST_DIR" ) ) . unwrap( ) . display( )
438438 ) ;
439439 let fixed_path = rs_path. with_extension ( "fixed" ) ;
@@ -445,6 +445,45 @@ fn rustfix_coverage_known_exceptions_accuracy() {
445445 }
446446}
447447
448+ #[ test]
449+ fn ui_cargo_toml_metadata ( ) {
450+ let ui_cargo_path = Path :: new ( "tests/ui-cargo" ) ;
451+ let cargo_common_metadata_path = ui_cargo_path. join ( "cargo_common_metadata" ) ;
452+ let publish_exceptions =
453+ [ "fail_publish" , "fail_publish_true" , "pass_publish_empty" ] . map ( |path| cargo_common_metadata_path. join ( path) ) ;
454+
455+ for entry in walkdir:: WalkDir :: new ( ui_cargo_path) {
456+ let entry = entry. unwrap ( ) ;
457+ let path = entry. path ( ) ;
458+ if path. file_name ( ) != Some ( OsStr :: new ( "Cargo.toml" ) ) {
459+ continue ;
460+ }
461+
462+ let toml = fs:: read_to_string ( path) . unwrap ( ) . parse :: < toml:: Value > ( ) . unwrap ( ) ;
463+
464+ let package = toml. as_table ( ) . unwrap ( ) . get ( "package" ) . unwrap ( ) . as_table ( ) . unwrap ( ) ;
465+
466+ let name = package. get ( "name" ) . unwrap ( ) . as_str ( ) . unwrap ( ) . replace ( '-' , "_" ) ;
467+ assert ! (
468+ path. parent( )
469+ . unwrap( )
470+ . components( )
471+ . map( |component| component. as_os_str( ) . to_string_lossy( ) . replace( '-' , "_" ) )
472+ . any( |s| * s == name)
473+ || path. starts_with( & cargo_common_metadata_path) ,
474+ "{:?} has incorrect package name" ,
475+ path
476+ ) ;
477+
478+ let publish = package. get ( "publish" ) . and_then ( toml:: Value :: as_bool) . unwrap_or ( true ) ;
479+ assert ! (
480+ !publish || publish_exceptions. contains( & path. parent( ) . unwrap( ) . to_path_buf( ) ) ,
481+ "{:?} lacks `publish = false`" ,
482+ path
483+ ) ;
484+ }
485+ }
486+
448487/// Restores an env var on drop
449488#[ must_use]
450489struct VarGuard {
0 commit comments