@@ -111,7 +111,7 @@ fn write_message(msg: &str) {
111
111
fn system_tests ( ) {
112
112
// Get all files in the tests/source directory.
113
113
let files = get_test_files ( Path :: new ( "tests/source" ) , true ) ;
114
- let ( _reports, count, fails) = check_files ( files) ;
114
+ let ( _reports, count, fails) = check_files ( files, None ) ;
115
115
116
116
// Display results.
117
117
println ! ( "Ran {} system tests." , count) ;
@@ -123,7 +123,7 @@ fn system_tests() {
123
123
#[ test]
124
124
fn coverage_tests ( ) {
125
125
let files = get_test_files ( Path :: new ( "tests/coverage/source" ) , true ) ;
126
- let ( _reports, count, fails) = check_files ( files) ;
126
+ let ( _reports, count, fails) = check_files ( files, None ) ;
127
127
128
128
println ! ( "Ran {} tests in coverage mode." , count) ;
129
129
assert_eq ! ( fails, 0 , "{} tests failed" , fails) ;
@@ -192,7 +192,7 @@ fn assert_output(source: &Path, expected_filename: &Path) {
192
192
fn idempotence_tests ( ) {
193
193
// Get all files in the tests/target directory.
194
194
let files = get_test_files ( Path :: new ( "tests/target" ) , true ) ;
195
- let ( _reports, count, fails) = check_files ( files) ;
195
+ let ( _reports, count, fails) = check_files ( files, None ) ;
196
196
197
197
// Display results.
198
198
println ! ( "Ran {} idempotent tests." , count) ;
@@ -213,7 +213,7 @@ fn self_tests() {
213
213
}
214
214
files. push ( PathBuf :: from ( "src/lib.rs" ) ) ;
215
215
216
- let ( reports, count, fails) = check_files ( files) ;
216
+ let ( reports, count, fails) = check_files ( files, Some ( PathBuf :: from ( "rustfmt.toml" ) ) ) ;
217
217
let mut warnings = 0 ;
218
218
219
219
// Display results.
@@ -298,15 +298,15 @@ fn format_lines_errors_are_reported_with_tabs() {
298
298
299
299
// For each file, run rustfmt and collect the output.
300
300
// Returns the number of files checked and the number of failures.
301
- fn check_files ( files : Vec < PathBuf > ) -> ( Vec < FormatReport > , u32 , u32 ) {
301
+ fn check_files ( files : Vec < PathBuf > , opt_config : Option < PathBuf > ) -> ( Vec < FormatReport > , u32 , u32 ) {
302
302
let mut count = 0 ;
303
303
let mut fails = 0 ;
304
304
let mut reports = vec ! [ ] ;
305
305
306
306
for file_name in files {
307
307
debug ! ( "Testing '{}'..." , file_name. display( ) ) ;
308
308
309
- match idempotent_check ( & file_name) {
309
+ match idempotent_check ( & file_name, & opt_config ) {
310
310
Ok ( ref report) if report. has_warnings ( ) => {
311
311
print ! ( "{}" , report) ;
312
312
fails += 1 ;
@@ -385,9 +385,16 @@ pub enum IdempotentCheckError {
385
385
Parse ,
386
386
}
387
387
388
- pub fn idempotent_check ( filename : & PathBuf ) -> Result < FormatReport , IdempotentCheckError > {
388
+ pub fn idempotent_check (
389
+ filename : & PathBuf ,
390
+ opt_config : & Option < PathBuf > ,
391
+ ) -> Result < FormatReport , IdempotentCheckError > {
389
392
let sig_comments = read_significant_comments ( filename) ;
390
- let config = read_config ( filename) ;
393
+ let config = if let Some ( ref config_file_path) = opt_config {
394
+ Config :: from_toml_path ( config_file_path) . expect ( "rustfmt.toml not found" )
395
+ } else {
396
+ read_config ( filename)
397
+ } ;
391
398
let ( error_summary, file_map, format_report) = format_file ( filename, & config) ;
392
399
if error_summary. has_parsing_errors ( ) {
393
400
return Err ( IdempotentCheckError :: Parse ) ;
0 commit comments