@@ -103,7 +103,7 @@ fn assert_output(source: &Path, expected_filename: &Path) {
103
103
if !compare. is_empty ( ) {
104
104
let mut failures = HashMap :: new ( ) ;
105
105
failures. insert ( source. to_owned ( ) , compare) ;
106
- print_mismatches ( failures) ;
106
+ print_mismatches_default_message ( failures, source . display ( ) ) ;
107
107
assert ! ( false , "Text does not match expected output" ) ;
108
108
}
109
109
}
@@ -219,15 +219,15 @@ where
219
219
for file_name in files. filter ( |f| f. extension ( ) . map_or ( false , |f| f == "rs" ) ) {
220
220
debug ! ( "Testing '{}'..." , file_name. display( ) ) ;
221
221
222
- match idempotent_check ( file_name) {
222
+ match idempotent_check ( & file_name) {
223
223
Ok ( ref report) if report. has_warnings ( ) => {
224
224
print ! ( "{}" , report) ;
225
225
fails += 1 ;
226
226
}
227
227
Ok ( report) => reports. push ( report) ,
228
228
Err ( err) => {
229
229
if let IdempotentCheckError :: Mismatch ( msg) = err {
230
- print_mismatches ( msg) ;
230
+ print_mismatches_default_message ( msg, file_name . display ( ) ) ;
231
231
}
232
232
fails += 1 ;
233
233
}
@@ -239,15 +239,22 @@ where
239
239
( reports, count, fails)
240
240
}
241
241
242
- fn print_mismatches ( result : HashMap < PathBuf , Vec < Mismatch > > ) {
243
- let mut t = term:: stdout ( ) . unwrap ( ) ;
242
+ fn print_mismatches_default_message (
243
+ result : HashMap < PathBuf , Vec < Mismatch > > ,
244
+ file_name : std:: path:: Display ,
245
+ ) {
246
+ print_mismatches ( result, |line_num| {
247
+ format ! ( "\n Mismatch at {}:{}:" , file_name, line_num)
248
+ } ) ;
249
+ }
244
250
245
- for ( file_name, diff) in result {
246
- print_diff (
247
- diff,
248
- |line_num| format ! ( "\n Mismatch at {}:{}:" , file_name. display( ) , line_num) ,
249
- Color :: Auto ,
250
- ) ;
251
+ fn print_mismatches < T : Fn ( u32 ) -> String > (
252
+ result : HashMap < PathBuf , Vec < Mismatch > > ,
253
+ mismatch_msg_formatter : T ,
254
+ ) {
255
+ let mut t = term:: stdout ( ) . unwrap ( ) ;
256
+ for ( _file_name, diff) in result {
257
+ print_diff ( diff, & mismatch_msg_formatter, Color :: Auto ) ;
251
258
}
252
259
253
260
t. reset ( ) . unwrap ( ) ;
@@ -287,7 +294,7 @@ pub enum IdempotentCheckError {
287
294
Parse ,
288
295
}
289
296
290
- pub fn idempotent_check ( filename : PathBuf ) -> Result < FormatReport , IdempotentCheckError > {
297
+ pub fn idempotent_check ( filename : & PathBuf ) -> Result < FormatReport , IdempotentCheckError > {
291
298
let sig_comments = read_significant_comments ( & filename) ;
292
299
let config = read_config ( & filename) ;
293
300
let ( error_summary, file_map, format_report) = format_file ( filename, & config) ;
@@ -611,7 +618,12 @@ fn check_blocks_idempotency(blocks: &Vec<CodeBlock>) {
611
618
if !compare. is_empty ( ) {
612
619
let mut mismatches = HashMap :: new ( ) ;
613
620
mismatches. insert ( PathBuf :: from ( "Configurations.md" ) , compare) ;
614
- print_mismatches ( mismatches) ;
621
+ print_mismatches ( mismatches, |line_num| {
622
+ format ! (
623
+ "\n Mismatch at Configurations.md:{}:" ,
624
+ line_num + block. code_block_start_line - 1
625
+ )
626
+ } ) ;
615
627
failures += 1 ;
616
628
}
617
629
}
0 commit comments