@@ -14,10 +14,12 @@ pub(crate) trait OutputFormatter {
14
14
fn write_run_start ( & mut self , test_count : usize ) -> io:: Result < ( ) > ;
15
15
fn write_test_start ( & mut self , desc : & TestDesc ) -> io:: Result < ( ) > ;
16
16
fn write_timeout ( & mut self , desc : & TestDesc ) -> io:: Result < ( ) > ;
17
- fn write_result ( & mut self ,
18
- desc : & TestDesc ,
19
- result : & TestResult ,
20
- stdout : & [ u8 ] ) -> io:: Result < ( ) > ;
17
+ fn write_result (
18
+ & mut self ,
19
+ desc : & TestDesc ,
20
+ result : & TestResult ,
21
+ stdout : & [ u8 ] ,
22
+ ) -> io:: Result < ( ) > ;
21
23
fn write_run_finish ( & mut self , state : & ConsoleTestState ) -> io:: Result < bool > ;
22
24
}
23
25
@@ -34,11 +36,13 @@ pub(crate) struct HumanFormatter<T> {
34
36
}
35
37
36
38
impl < T : Write > HumanFormatter < T > {
37
- pub fn new ( out : OutputLocation < T > ,
38
- use_color : bool ,
39
- terse : bool ,
40
- max_name_len : usize ,
41
- is_multithreaded : bool ) -> Self {
39
+ pub fn new (
40
+ out : OutputLocation < T > ,
41
+ use_color : bool ,
42
+ terse : bool ,
43
+ max_name_len : usize ,
44
+ is_multithreaded : bool ,
45
+ ) -> Self {
42
46
HumanFormatter {
43
47
out,
44
48
terse,
@@ -74,8 +78,12 @@ impl<T: Write> HumanFormatter<T> {
74
78
self . write_pretty ( "bench" , term:: color:: CYAN )
75
79
}
76
80
77
- pub fn write_short_result ( & mut self , verbose : & str , quiet : & str , color : term:: color:: Color )
78
- -> io:: Result < ( ) > {
81
+ pub fn write_short_result (
82
+ & mut self ,
83
+ verbose : & str ,
84
+ quiet : & str ,
85
+ color : term:: color:: Color ,
86
+ ) -> io:: Result < ( ) > {
79
87
if self . terse {
80
88
self . write_pretty ( quiet, color) ?;
81
89
if self . test_count % QUIET_MODE_MAX_COLUMN == QUIET_MODE_MAX_COLUMN - 1 {
@@ -182,11 +190,7 @@ impl<T: Write> HumanFormatter<T> {
182
190
183
191
impl < T : Write > OutputFormatter for HumanFormatter < T > {
184
192
fn write_run_start ( & mut self , test_count : usize ) -> io:: Result < ( ) > {
185
- let noun = if test_count != 1 {
186
- "tests"
187
- } else {
188
- "test"
189
- } ;
193
+ let noun = if test_count != 1 { "tests" } else { "test" } ;
190
194
self . write_plain ( & format ! ( "\n running {} {}\n " , test_count, noun) )
191
195
}
192
196
@@ -224,9 +228,11 @@ impl<T: Write> OutputFormatter for HumanFormatter<T> {
224
228
self . write_test_name ( desc) ?;
225
229
}
226
230
227
- self . write_plain ( & format ! ( "test {} has been running for over {} seconds\n " ,
228
- desc. name,
229
- TEST_WARN_TIMEOUT_S ) )
231
+ self . write_plain ( & format ! (
232
+ "test {} has been running for over {} seconds\n " ,
233
+ desc. name,
234
+ TEST_WARN_TIMEOUT_S
235
+ ) )
230
236
}
231
237
232
238
fn write_run_finish ( & mut self , state : & ConsoleTestState ) -> io:: Result < bool > {
@@ -255,15 +261,17 @@ impl<T: Write> OutputFormatter for HumanFormatter<T> {
255
261
state. allowed_fail,
256
262
state. ignored,
257
263
state. measured,
258
- state. filtered_out)
264
+ state. filtered_out
265
+ )
259
266
} else {
260
267
format ! (
261
268
". {} passed; {} failed; {} ignored; {} measured; {} filtered out\n \n " ,
262
269
state. passed,
263
270
state. failed,
264
271
state. ignored,
265
272
state. measured,
266
- state. filtered_out)
273
+ state. filtered_out
274
+ )
267
275
} ;
268
276
269
277
self . write_plain ( & s) ?;
@@ -273,7 +281,7 @@ impl<T: Write> OutputFormatter for HumanFormatter<T> {
273
281
}
274
282
275
283
pub ( crate ) struct JsonFormatter < T > {
276
- out : OutputLocation < T >
284
+ out : OutputLocation < T > ,
277
285
}
278
286
279
287
impl < T : Write > JsonFormatter < T > {
@@ -288,108 +296,121 @@ impl<T: Write> JsonFormatter<T> {
288
296
self . out . write_all ( b"\n " )
289
297
}
290
298
291
- fn write_event ( & mut self ,
292
- ty : & str ,
293
- name : & str ,
294
- evt : & str ,
295
- extra : Option < String > ) -> io:: Result < ( ) > {
299
+ fn write_event (
300
+ & mut self ,
301
+ ty : & str ,
302
+ name : & str ,
303
+ evt : & str ,
304
+ extra : Option < String > ,
305
+ ) -> io:: Result < ( ) > {
296
306
if let Some ( extras) = extra {
297
- self . write_message ( & * format ! ( r#"{{ "type": "{}", "name": "{}", "event": "{}", {} }}"# ,
298
- ty,
299
- name,
300
- evt,
301
- extras) )
302
- }
303
- else {
304
- self . write_message ( & * format ! ( r#"{{ "type": "{}", "name": "{}", "event": "{}" }}"# ,
305
- ty,
306
- name,
307
- evt) )
307
+ self . write_message ( & * format ! (
308
+ r#"{{ "type": "{}", "name": "{}", "event": "{}", {} }}"# ,
309
+ ty,
310
+ name,
311
+ evt,
312
+ extras
313
+ ) )
314
+ } else {
315
+ self . write_message ( & * format ! (
316
+ r#"{{ "type": "{}", "name": "{}", "event": "{}" }}"# ,
317
+ ty,
318
+ name,
319
+ evt
320
+ ) )
308
321
}
309
322
}
310
323
}
311
324
312
325
impl < T : Write > OutputFormatter for JsonFormatter < T > {
313
326
fn write_run_start ( & mut self , test_count : usize ) -> io:: Result < ( ) > {
314
- self . write_message (
315
- & * format ! ( r#"{{ "type": "suite", "event": "started", "test_count": "{}" }}"# ,
316
- test_count) )
327
+ self . write_message ( & * format ! (
328
+ r#"{{ "type": "suite", "event": "started", "test_count": "{}" }}"# ,
329
+ test_count
330
+ ) )
317
331
}
318
332
319
333
fn write_test_start ( & mut self , desc : & TestDesc ) -> io:: Result < ( ) > {
320
- self . write_message ( & * format ! ( r#"{{ "type": "test", "event": "started", "name": "{}" }}"# ,
321
- desc. name) )
334
+ self . write_message ( & * format ! (
335
+ r#"{{ "type": "test", "event": "started", "name": "{}" }}"# ,
336
+ desc. name
337
+ ) )
322
338
}
323
339
324
- fn write_result ( & mut self ,
325
- desc : & TestDesc ,
326
- result : & TestResult ,
327
- stdout : & [ u8 ] ) -> io:: Result < ( ) > {
340
+ fn write_result (
341
+ & mut self ,
342
+ desc : & TestDesc ,
343
+ result : & TestResult ,
344
+ stdout : & [ u8 ] ,
345
+ ) -> io:: Result < ( ) > {
328
346
match * result {
329
- TrOk => {
330
- self . write_event ( "test" , desc. name . as_slice ( ) , "ok" , None )
331
- } ,
347
+ TrOk => self . write_event ( "test" , desc. name . as_slice ( ) , "ok" , None ) ,
332
348
333
349
TrFailed => {
334
350
let extra_data = if stdout. len ( ) > 0 {
335
- Some ( format ! ( r#""stdout": "{}""# ,
336
- EscapedString ( String :: from_utf8_lossy( stdout) ) ) )
337
- }
338
- else {
351
+ Some ( format ! (
352
+ r#""stdout": "{}""# ,
353
+ EscapedString ( String :: from_utf8_lossy( stdout) )
354
+ ) )
355
+ } else {
339
356
None
340
357
} ;
341
358
342
359
self . write_event ( "test" , desc. name . as_slice ( ) , "failed" , extra_data)
343
- } ,
360
+ }
344
361
345
362
TrFailedMsg ( ref m) => {
346
- self . write_event ( "test" ,
347
- desc. name . as_slice ( ) ,
348
- "failed" ,
349
- Some ( format ! ( r#""message": "{}""# , EscapedString ( m) ) ) )
350
- } ,
363
+ self . write_event (
364
+ "test" ,
365
+ desc. name . as_slice ( ) ,
366
+ "failed" ,
367
+ Some ( format ! ( r#""message": "{}""# , EscapedString ( m) ) ) ,
368
+ )
369
+ }
351
370
352
- TrIgnored => {
353
- self . write_event ( "test" , desc. name . as_slice ( ) , "ignored" , None )
354
- } ,
371
+ TrIgnored => self . write_event ( "test" , desc. name . as_slice ( ) , "ignored" , None ) ,
355
372
356
373
TrAllowedFail => {
357
374
self . write_event ( "test" , desc. name . as_slice ( ) , "allowed_failure" , None )
358
- } ,
375
+ }
359
376
360
377
TrBench ( ref bs) => {
361
378
let median = bs. ns_iter_summ . median as usize ;
362
379
let deviation = ( bs. ns_iter_summ . max - bs. ns_iter_summ . min ) as usize ;
363
380
364
381
let mbps = if bs. mb_s == 0 {
365
382
"" . into ( )
366
- }
367
- else {
383
+ } else {
368
384
format ! ( r#", "mib_per_second": {}"# , bs. mb_s)
369
385
} ;
370
386
371
- let line = format ! ( "{{ \" type\" : \" bench\" , \
387
+ let line = format ! (
388
+ "{{ \" type\" : \" bench\" , \
372
389
\" name\" : \" {}\" , \
373
390
\" median\" : {}, \
374
391
\" deviation\" : {}{} }}",
375
- desc. name,
376
- median,
377
- deviation,
378
- mbps) ;
392
+ desc. name,
393
+ median,
394
+ deviation,
395
+ mbps
396
+ ) ;
379
397
380
398
self . write_message ( & * line)
381
- } ,
399
+ }
382
400
}
383
401
}
384
402
385
403
fn write_timeout ( & mut self , desc : & TestDesc ) -> io:: Result < ( ) > {
386
- self . write_message ( & * format ! ( r#"{{ "type": "test", "event": "timeout", "name": "{}" }}"# ,
387
- desc. name) )
404
+ self . write_message ( & * format ! (
405
+ r#"{{ "type": "test", "event": "timeout", "name": "{}" }}"# ,
406
+ desc. name
407
+ ) )
388
408
}
389
409
390
410
fn write_run_finish ( & mut self , state : & ConsoleTestState ) -> io:: Result < bool > {
391
411
392
- self . write_message ( & * format ! ( "{{ \" type\" : \" suite\" , \
412
+ self . write_message ( & * format ! (
413
+ "{{ \" type\" : \" suite\" , \
393
414
\" event\" : \" {}\" , \
394
415
\" passed\" : {}, \
395
416
\" failed\" : {}, \
@@ -403,7 +424,8 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
403
424
state. allowed_fail,
404
425
state. ignored,
405
426
state. measured,
406
- state. filtered_out) ) ?;
427
+ state. filtered_out
428
+ ) ) ?;
407
429
408
430
Ok ( state. failed == 0 )
409
431
}
@@ -454,7 +476,9 @@ impl<S: AsRef<str>> ::std::fmt::Display for EscapedString<S> {
454
476
b'\x1e' => "\\ u001e" ,
455
477
b'\x1f' => "\\ u001f" ,
456
478
b'\x7f' => "\\ u007f" ,
457
- _ => { continue ; }
479
+ _ => {
480
+ continue ;
481
+ }
458
482
} ;
459
483
460
484
if start < i {
0 commit comments