@@ -375,21 +375,43 @@ fn idempotence_tests() {
375375 } ) ;
376376}
377377
378+ // Run rustfmt on itself. This operation must be idempotent. We also check that
379+ // no warnings are emitted.
380+ // Issue-3443: these tests require nightly
378381#[ nightly_only_test]
379382#[ test]
380383fn self_tests ( ) {
381- let get_exe_path = |name| {
382- let mut path = env:: current_exe ( ) . unwrap ( ) ;
383- path. pop ( ) ;
384- path. set_file_name ( format ! ( "{name}{}" , env:: consts:: EXE_SUFFIX ) ) ;
385- path
386- } ;
387- let status = Command :: new ( get_exe_path ( "cargo-fmt" ) )
388- . args ( [ "--check" , "--all" ] )
389- . env ( "RUSTFMT" , get_exe_path ( "rustfmt" ) )
390- . status ( )
391- . unwrap ( ) ;
392- assert ! ( status. success( ) ) ;
384+ init_log ( ) ;
385+ let mut files = get_test_files ( Path :: new ( "tests" ) , false ) ;
386+ let bin_directories = vec ! [ "cargo-fmt" , "git-rustfmt" , "bin" , "format-diff" ] ;
387+ for dir in bin_directories {
388+ let mut path = PathBuf :: from ( "src" ) ;
389+ path. push ( dir) ;
390+ path. push ( "main.rs" ) ;
391+ files. push ( path) ;
392+ }
393+ files. push ( PathBuf :: from ( "src/lib.rs" ) ) ;
394+
395+ let ( reports, count, fails) = check_files ( files, & Some ( PathBuf :: from ( "rustfmt.toml" ) ) ) ;
396+ let mut warnings = 0 ;
397+
398+ // Display results.
399+ println ! ( "Ran {} self tests." , count) ;
400+ assert_eq ! ( fails, 0 , "{} self tests failed" , fails) ;
401+
402+ for format_report in reports {
403+ println ! (
404+ "{}" ,
405+ FormatReportFormatterBuilder :: new( & format_report) . build( )
406+ ) ;
407+ warnings += format_report. warning_count ( ) ;
408+ }
409+
410+ assert_eq ! (
411+ warnings, 0 ,
412+ "Rustfmt's code generated {} warnings" ,
413+ warnings
414+ ) ;
393415}
394416
395417#[ test]
0 commit comments