@@ -372,6 +372,44 @@ fn self_tests() {
372372 ) ;
373373}
374374
375+ #[ test]
376+ fn format_files_find_new_files_via_cfg_if ( ) {
377+ init_log ( ) ;
378+ run_test_with ( & TestSetting :: default ( ) , || {
379+ // To repro issue-4656, it is necessary that these files are parsed
380+ // as a part of the same session (hence this separate test runner).
381+ let files = vec ! [
382+ Path :: new( "tests/source/issue-4656/lib2.rs" ) ,
383+ Path :: new( "tests/source/issue-4656/lib.rs" ) ,
384+ ] ;
385+
386+ let config = Config :: default ( ) ;
387+ let mut session = Session :: < io:: Stdout > :: new ( config, None ) ;
388+
389+ let mut write_result = HashMap :: new ( ) ;
390+ for file in files {
391+ assert ! ( file. exists( ) ) ;
392+ let result = session. format ( Input :: File ( file. into ( ) ) ) . unwrap ( ) ;
393+ assert ! ( !session. has_formatting_errors( ) ) ;
394+ assert ! ( !result. has_warnings( ) ) ;
395+ let mut source_file = SourceFile :: new ( ) ;
396+ mem:: swap ( & mut session. source_file , & mut source_file) ;
397+
398+ for ( filename, text) in source_file {
399+ if let FileName :: Real ( ref filename) = filename {
400+ write_result. insert ( filename. to_owned ( ) , text) ;
401+ }
402+ }
403+ }
404+ assert_eq ! (
405+ 3 ,
406+ write_result. len( ) ,
407+ "Should have uncovered an extra file (format_me_please.rs) via lib.rs"
408+ ) ;
409+ assert ! ( handle_result( write_result, None ) . is_ok( ) ) ;
410+ } ) ;
411+ }
412+
375413#[ test]
376414fn stdin_formatting_smoke_test ( ) {
377415 init_log ( ) ;
0 commit comments