@@ -42,6 +42,8 @@ const FILE_SKIP_LIST: &[&str] = &[
42
42
"issue-3253/foo.rs" ,
43
43
"issue-3253/bar.rs" ,
44
44
"issue-3253/paths" ,
45
+ // This directory is directly tested by format_files_find_new_files_via_cfg_match
46
+ "cfg_match" ,
45
47
// These files and directory are a part of modules defined inside `cfg_attr(..)`.
46
48
"cfg_mod/dir" ,
47
49
"cfg_mod/bar.rs" ,
@@ -468,6 +470,45 @@ fn format_files_find_new_files_via_cfg_if() {
468
470
} ) ;
469
471
}
470
472
473
+ #[ test]
474
+ fn format_files_find_new_files_via_cfg_match ( ) {
475
+ init_log ( ) ;
476
+ run_test_with ( & TestSetting :: default ( ) , || {
477
+ // We load these two files into the same session to test cfg_match!
478
+ // transparent mod discovery, and to ensure that it does not suffer
479
+ // from a similar issue as cfg_if! support did with issue-4656.
480
+ let files = vec ! [
481
+ Path :: new( "tests/source/cfg_match/lib2.rs" ) ,
482
+ Path :: new( "tests/source/cfg_match/lib.rs" ) ,
483
+ ] ;
484
+
485
+ let config = Config :: default ( ) ;
486
+ let mut session = Session :: < io:: Stdout > :: new ( config, None ) ;
487
+
488
+ let mut write_result = HashMap :: new ( ) ;
489
+ for file in files {
490
+ assert ! ( file. exists( ) ) ;
491
+ let result = session. format ( Input :: File ( file. into ( ) ) ) . unwrap ( ) ;
492
+ assert ! ( !session. has_formatting_errors( ) ) ;
493
+ assert ! ( !result. has_warnings( ) ) ;
494
+ let mut source_file = SourceFile :: new ( ) ;
495
+ mem:: swap ( & mut session. source_file , & mut source_file) ;
496
+
497
+ for ( filename, text) in source_file {
498
+ if let FileName :: Real ( ref filename) = filename {
499
+ write_result. insert ( filename. to_owned ( ) , text) ;
500
+ }
501
+ }
502
+ }
503
+ assert_eq ! (
504
+ 3 ,
505
+ write_result. len( ) ,
506
+ "Should have uncovered an extra file (format_me_please.rs) via lib.rs"
507
+ ) ;
508
+ assert ! ( handle_result( write_result, None ) . is_ok( ) ) ;
509
+ } ) ;
510
+ }
511
+
471
512
#[ test]
472
513
fn stdin_formatting_smoke_test ( ) {
473
514
init_log ( ) ;
0 commit comments