@@ -7,9 +7,7 @@ use std::path::{Path, PathBuf};
7
7
use std:: str:: Chars ;
8
8
use std:: thread;
9
9
10
- use rustfmt_emitter:: rustfmt_diff:: {
11
- make_diff, print_diff, Mismatch , ModifiedChunk , OutputWriter ,
12
- } ;
10
+ use rustfmt_emitter:: rustfmt_diff:: { make_diff, print_diff, Mismatch , ModifiedChunk , OutputWriter } ;
13
11
14
12
use crate :: config:: { Color , Config , EmitMode , FileName , NewlineStyle , ReportTactic } ;
15
13
use crate :: formatting:: { ReportedErrors , SourceFile } ;
@@ -96,7 +94,7 @@ fn is_file_skip(path: &Path) -> bool {
96
94
// Returns a `Vec` containing `PathBuf`s of files with an `rs` extension in the
97
95
// given path. The `recursive` argument controls if files from subdirectories
98
96
// are also returned.
99
- fn get_test_files ( path : & Path , recursive : bool ) -> Vec < PathBuf > {
97
+ fn get_test_files ( path : & Path , recursive : bool , is_file_skip : fn ( & Path ) -> bool ) -> Vec < PathBuf > {
100
98
let mut files = vec ! [ ] ;
101
99
if path. is_dir ( ) {
102
100
for entry in fs:: read_dir ( path)
@@ -105,7 +103,7 @@ fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
105
103
let entry = entry. expect ( "couldn't get `DirEntry`" ) ;
106
104
let path = entry. path ( ) ;
107
105
if path. is_dir ( ) && recursive {
108
- files. append ( & mut get_test_files ( & path, recursive) ) ;
106
+ files. append ( & mut get_test_files ( & path, recursive, is_file_skip ) ) ;
109
107
} else if path. extension ( ) . map_or ( false , |f| f == "rs" ) && !is_file_skip ( & path) {
110
108
files. push ( path) ;
111
109
}
@@ -179,7 +177,7 @@ fn system_tests() {
179
177
init_log ( ) ;
180
178
run_test_with ( & TestSetting :: default ( ) , || {
181
179
// Get all files in the tests/source directory.
182
- let files = get_test_files ( Path :: new ( "tests/source" ) , true ) ;
180
+ let files = get_test_files ( Path :: new ( "tests/source" ) , true , is_file_skip ) ;
183
181
let ( _reports, count, fails) = check_files ( files, & None ) ;
184
182
185
183
// Display results.
@@ -198,7 +196,7 @@ fn system_tests() {
198
196
#[ test]
199
197
fn coverage_tests ( ) {
200
198
init_log ( ) ;
201
- let files = get_test_files ( Path :: new ( "tests/coverage/source" ) , true ) ;
199
+ let files = get_test_files ( Path :: new ( "tests/coverage/source" ) , true , is_file_skip ) ;
202
200
let ( _reports, count, fails) = check_files ( files, & None ) ;
203
201
204
202
println ! ( "Ran {} tests in coverage mode." , count) ;
@@ -362,7 +360,7 @@ fn idempotence_tests() {
362
360
return ;
363
361
}
364
362
// Get all files in the tests/target directory.
365
- let files = get_test_files ( Path :: new ( "tests/target" ) , true ) ;
363
+ let files = get_test_files ( Path :: new ( "tests/target" ) , true , is_file_skip ) ;
366
364
let ( _reports, count, fails) = check_files ( files, & None ) ;
367
365
368
366
// Display results.
@@ -380,12 +378,19 @@ fn idempotence_tests() {
380
378
// no warnings are emitted.
381
379
#[ test]
382
380
fn self_tests ( ) {
381
+ fn is_file_skip ( path : & Path ) -> bool {
382
+ let skip_file_white_list = [ "target" , "tests" ] ;
383
+ skip_file_white_list
384
+ . iter ( )
385
+ . any ( |file_path| is_subpath ( path, file_path) )
386
+ }
387
+
383
388
init_log ( ) ;
384
389
// Issue-3443: these tests require nightly
385
390
if !is_nightly_channel ! ( ) {
386
391
return ;
387
392
}
388
- let mut files = get_test_files ( Path :: new ( "tests " ) , false ) ;
393
+ let mut files = get_test_files ( Path :: new ( "../../rustfmt-core " ) , true , is_file_skip ) ;
389
394
files. push ( PathBuf :: from ( "src/lib.rs" ) ) ;
390
395
391
396
let ( reports, count, fails) = check_files ( files, & Some ( PathBuf :: from ( "../../rustfmt.toml" ) ) ) ;
@@ -809,4 +814,3 @@ fn string_eq_ignore_newline_repr_test() {
809
814
assert ! ( string_eq_ignore_newline_repr( "a\r \n \r \n \r \n b" , "a\n \n \n b" ) ) ;
810
815
assert ! ( !string_eq_ignore_newline_repr( "a\r \n bcd" , "a\n bcdefghijk" ) ) ;
811
816
}
812
-
0 commit comments