1
+ use super :: RunResults ;
2
+ use crate :: { reporters:: Reporter , Args } ;
3
+ use colored:: { ColoredString , Colorize } ;
1
4
use fontspector_checkapi:: { Registry , StatusCode , Testable } ;
2
5
use itertools:: Itertools ;
6
+ use std:: { collections:: HashMap , path:: Path } ;
3
7
4
- use crate :: { reporters:: Reporter , Args } ;
5
-
6
- use super :: RunResults ;
7
8
pub ( crate ) struct TerminalReporter {
8
9
succinct : bool ,
9
10
}
@@ -14,6 +15,21 @@ impl TerminalReporter {
14
15
}
15
16
}
16
17
18
+ fn colored_status ( c : StatusCode , s : Option < & str > ) -> ColoredString {
19
+ let string = match s {
20
+ Some ( s) => s. to_string ( ) ,
21
+ None => c. to_string ( ) ,
22
+ } ;
23
+ match c {
24
+ StatusCode :: Error => string. on_red ( ) ,
25
+ StatusCode :: Fail => string. red ( ) ,
26
+ StatusCode :: Warn => string. yellow ( ) ,
27
+ StatusCode :: Info => string. cyan ( ) ,
28
+ StatusCode :: Skip => string. blue ( ) ,
29
+ StatusCode :: Pass => string. green ( ) ,
30
+ }
31
+ }
32
+
17
33
impl Reporter for TerminalReporter {
18
34
fn report ( & self , results : & RunResults , args : & Args , registry : & Registry ) {
19
35
let organised_results = results. organize ( ) ;
@@ -25,33 +41,41 @@ impl Reporter for TerminalReporter {
25
41
for ( sectionname, results) in sectionresults. iter ( ) {
26
42
let mut sectionheading_done = false ;
27
43
for result in results. iter ( ) {
44
+ let subresults = result
45
+ . subresults
46
+ . iter ( )
47
+ . filter ( |c| c. severity >= args. loglevel )
48
+ . collect :: < Vec < _ > > ( ) ;
49
+ if subresults. is_empty ( ) {
50
+ continue ;
51
+ }
52
+
28
53
if self . succinct {
29
54
println ! (
30
- "{:}: {:} {:}" ,
31
- filename,
32
- result. check_id,
33
- result
34
- . subresults
55
+ "{:}: {:} {:} [{}] " ,
56
+ Path :: new ( filename) . file_name ( ) . unwrap ( ) . to_string_lossy ( ) ,
57
+ result. check_id. bright_cyan ( ) ,
58
+ colored_status ( result. worst_status ( ) , None ) ,
59
+ subresults
35
60
. iter( )
36
- . flat_map( |r| r. code. as_ref( ) )
37
- . join( ", " )
61
+ . map( |r| colored_status(
62
+ r. severity,
63
+ r. code. as_ref( ) . map( |x| x. as_str( ) )
64
+ ) )
65
+ . join( " " )
38
66
) ;
39
67
continue ;
40
68
}
41
69
42
- for subresult in result
43
- . subresults
44
- . iter ( )
45
- . filter ( |c| c. severity >= args. loglevel )
46
- {
47
- if !fileheading_done {
48
- println ! ( "Testing: {:}" , filename) ;
49
- fileheading_done = true ;
50
- }
51
- if !sectionheading_done {
52
- println ! ( " Section: {:}\n " , sectionname) ;
53
- sectionheading_done = true ;
54
- }
70
+ if !fileheading_done {
71
+ println ! ( "Testing: {:}" , filename) ;
72
+ fileheading_done = true ;
73
+ }
74
+ if !sectionheading_done {
75
+ println ! ( " Section: {:}\n " , sectionname) ;
76
+ sectionheading_done = true ;
77
+ }
78
+ for subresult in subresults {
55
79
println ! ( ">> {:}" , result. check_id) ;
56
80
if args. verbose > 1 {
57
81
println ! ( " {:}" , result. check_name) ;
@@ -61,10 +85,6 @@ impl Reporter for TerminalReporter {
61
85
) ) ;
62
86
}
63
87
termimad:: print_inline ( & format ! ( "{:}\n " , subresult) ) ;
64
- if subresult. severity != StatusCode :: Fail {
65
- println ! ( ) ;
66
- continue ;
67
- }
68
88
#[ allow( clippy:: unwrap_used) ]
69
89
// This is a genuine can't-happen. We put it in the hashmap earlier!
70
90
let check = registry. checks . get ( & result. check_id ) . unwrap ( ) ;
@@ -86,3 +106,17 @@ impl Reporter for TerminalReporter {
86
106
}
87
107
}
88
108
}
109
+
110
+ impl TerminalReporter {
111
+ pub fn summary_report ( summary : HashMap < StatusCode , i32 > ) {
112
+ print ! ( "\n Summary:\n " ) ;
113
+ for code in StatusCode :: all ( ) {
114
+ print ! (
115
+ "{:}: {:} " ,
116
+ colored_status( code, None ) ,
117
+ summary. get( & code) . unwrap_or( & 0 )
118
+ ) ;
119
+ }
120
+ println ! ( ) ;
121
+ }
122
+ }
0 commit comments