@@ -3,6 +3,7 @@ use super::*;
3
3
pub ( crate ) struct PrettyFormatter < T > {
4
4
out : OutputLocation < T > ,
5
5
use_color : bool ,
6
+ time_options : Option < TestTimeOptions > ,
6
7
7
8
/// Number of columns to fill when aligning names
8
9
max_name_len : usize ,
@@ -16,12 +17,14 @@ impl<T: Write> PrettyFormatter<T> {
16
17
use_color : bool ,
17
18
max_name_len : usize ,
18
19
is_multithreaded : bool ,
20
+ time_options : Option < TestTimeOptions > ,
19
21
) -> Self {
20
22
PrettyFormatter {
21
23
out,
22
24
use_color,
23
25
max_name_len,
24
26
is_multithreaded,
27
+ time_options
25
28
}
26
29
}
27
30
@@ -30,20 +33,24 @@ impl<T: Write> PrettyFormatter<T> {
30
33
& self . out
31
34
}
32
35
33
- pub fn write_ok ( & mut self , exec_time : Option < & TestExecTime > ) -> io:: Result < ( ) > {
34
- self . write_short_result ( "ok" , term:: color:: GREEN , exec_time )
36
+ pub fn write_ok ( & mut self ) -> io:: Result < ( ) > {
37
+ self . write_short_result ( "ok" , term:: color:: GREEN )
35
38
}
36
39
37
- pub fn write_failed ( & mut self , exec_time : Option < & TestExecTime > ) -> io:: Result < ( ) > {
38
- self . write_short_result ( "FAILED" , term:: color:: RED , exec_time )
40
+ pub fn write_failed ( & mut self ) -> io:: Result < ( ) > {
41
+ self . write_short_result ( "FAILED" , term:: color:: RED )
39
42
}
40
43
41
- pub fn write_ignored ( & mut self , exec_time : Option < & TestExecTime > ) -> io:: Result < ( ) > {
42
- self . write_short_result ( "ignored" , term:: color:: YELLOW , exec_time )
44
+ pub fn write_ignored ( & mut self ) -> io:: Result < ( ) > {
45
+ self . write_short_result ( "ignored" , term:: color:: YELLOW )
43
46
}
44
47
45
- pub fn write_allowed_fail ( & mut self , exec_time : Option < & TestExecTime > ) -> io:: Result < ( ) > {
46
- self . write_short_result ( "FAILED (allowed)" , term:: color:: YELLOW , exec_time)
48
+ pub fn write_allowed_fail ( & mut self ) -> io:: Result < ( ) > {
49
+ self . write_short_result ( "FAILED (allowed)" , term:: color:: YELLOW )
50
+ }
51
+
52
+ pub fn write_time_failed ( & mut self ) -> io:: Result < ( ) > {
53
+ self . write_short_result ( "FAILED (time limit exceeded)" , term:: color:: RED )
47
54
}
48
55
49
56
pub fn write_bench ( & mut self ) -> io:: Result < ( ) > {
@@ -54,13 +61,8 @@ impl<T: Write> PrettyFormatter<T> {
54
61
& mut self ,
55
62
result : & str ,
56
63
color : term:: color:: Color ,
57
- exec_time : Option < & TestExecTime > ,
58
64
) -> io:: Result < ( ) > {
59
- self . write_pretty ( result, color) ?;
60
- if let Some ( exec_time) = exec_time {
61
- self . write_plain ( format ! ( " {}" , exec_time) ) ?;
62
- }
63
- self . write_plain ( "\n " )
65
+ self . write_pretty ( result, color)
64
66
}
65
67
66
68
pub fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
@@ -88,12 +90,48 @@ impl<T: Write> PrettyFormatter<T> {
88
90
self . out . flush ( )
89
91
}
90
92
91
- pub fn write_successes ( & mut self , state : & ConsoleTestState ) -> io:: Result < ( ) > {
92
- self . write_plain ( "\n successes:\n " ) ?;
93
- let mut successes = Vec :: new ( ) ;
93
+ fn write_time (
94
+ & mut self ,
95
+ desc : & TestDesc ,
96
+ exec_time : Option < & TestExecTime >
97
+ ) -> io:: Result < ( ) > {
98
+ if let ( Some ( opts) , Some ( time) ) = ( self . time_options , exec_time) {
99
+ let time_str = format ! ( " <{}>" , time) ;
100
+
101
+ let color = if opts. colored {
102
+ if opts. is_critical ( desc, time) {
103
+ Some ( term:: color:: RED )
104
+ } else if opts. is_warn ( desc, time) {
105
+ Some ( term:: color:: YELLOW )
106
+ } else {
107
+ None
108
+ }
109
+ } else {
110
+ None
111
+ } ;
112
+
113
+ match color {
114
+ Some ( color) => self . write_pretty ( & time_str, color) ?,
115
+ None => self . write_plain ( & time_str) ?
116
+ }
117
+ }
118
+
119
+ Ok ( ( ) )
120
+ }
121
+
122
+ fn write_results (
123
+ & mut self ,
124
+ inputs : & Vec < ( TestDesc , Vec < u8 > ) > ,
125
+ results_type : & str
126
+ ) -> io:: Result < ( ) > {
127
+ let results_out_str = format ! ( "\n {}:\n " , results_type) ;
128
+
129
+ self . write_plain ( & results_out_str) ?;
130
+
131
+ let mut results = Vec :: new ( ) ;
94
132
let mut stdouts = String :: new ( ) ;
95
- for & ( ref f, ref stdout) in & state . not_failures {
96
- successes . push ( f. name . to_string ( ) ) ;
133
+ for & ( ref f, ref stdout) in inputs {
134
+ results . push ( f. name . to_string ( ) ) ;
97
135
if !stdout. is_empty ( ) {
98
136
stdouts. push_str ( & format ! ( "---- {} stdout ----\n " , f. name) ) ;
99
137
let output = String :: from_utf8_lossy ( stdout) ;
@@ -106,38 +144,24 @@ impl<T: Write> PrettyFormatter<T> {
106
144
self . write_plain ( & stdouts) ?;
107
145
}
108
146
109
- self . write_plain ( " \n successes: \n " ) ?;
110
- successes . sort ( ) ;
111
- for name in & successes {
147
+ self . write_plain ( & results_out_str ) ?;
148
+ results . sort ( ) ;
149
+ for name in & results {
112
150
self . write_plain ( & format ! ( " {}\n " , name) ) ?;
113
151
}
114
152
Ok ( ( ) )
115
153
}
116
154
155
+ pub fn write_successes ( & mut self , state : & ConsoleTestState ) -> io:: Result < ( ) > {
156
+ self . write_results ( & state. not_failures , "successes" )
157
+ }
158
+
117
159
pub fn write_failures ( & mut self , state : & ConsoleTestState ) -> io:: Result < ( ) > {
118
- self . write_plain ( "\n failures:\n " ) ?;
119
- let mut failures = Vec :: new ( ) ;
120
- let mut fail_out = String :: new ( ) ;
121
- for & ( ref f, ref stdout) in & state. failures {
122
- failures. push ( f. name . to_string ( ) ) ;
123
- if !stdout. is_empty ( ) {
124
- fail_out. push_str ( & format ! ( "---- {} stdout ----\n " , f. name) ) ;
125
- let output = String :: from_utf8_lossy ( stdout) ;
126
- fail_out. push_str ( & output) ;
127
- fail_out. push_str ( "\n " ) ;
128
- }
129
- }
130
- if !fail_out. is_empty ( ) {
131
- self . write_plain ( "\n " ) ?;
132
- self . write_plain ( & fail_out) ?;
133
- }
160
+ self . write_results ( & state. failures , "failures" )
161
+ }
134
162
135
- self . write_plain ( "\n failures:\n " ) ?;
136
- failures. sort ( ) ;
137
- for name in & failures {
138
- self . write_plain ( & format ! ( " {}\n " , name) ) ?;
139
- }
140
- Ok ( ( ) )
163
+ pub fn write_time_failures ( & mut self , state : & ConsoleTestState ) -> io:: Result < ( ) > {
164
+ self . write_results ( & state. time_failures , "failures (time limit exceeded)" )
141
165
}
142
166
143
167
fn write_test_name ( & mut self , desc : & TestDesc ) -> io:: Result < ( ) > {
@@ -179,15 +203,19 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
179
203
}
180
204
181
205
match * result {
182
- TrOk => self . write_ok ( exec_time ) ,
183
- TrFailed | TrFailedMsg ( _) => self . write_failed ( exec_time ) ,
184
- TrIgnored => self . write_ignored ( exec_time ) ,
185
- TrAllowedFail => self . write_allowed_fail ( exec_time ) ,
206
+ TrOk => self . write_ok ( ) ? ,
207
+ TrFailed | TrFailedMsg ( _) => self . write_failed ( ) ? ,
208
+ TrIgnored => self . write_ignored ( ) ? ,
209
+ TrAllowedFail => self . write_allowed_fail ( ) ? ,
186
210
TrBench ( ref bs) => {
187
211
self . write_bench ( ) ?;
188
- self . write_plain ( & format ! ( ": {}\n " , fmt_bench_samples( bs) ) )
212
+ self . write_plain ( & format ! ( ": {}\n " , fmt_bench_samples( bs) ) ) ? ;
189
213
}
214
+ TrTimedFail => self . write_time_failed ( ) ?,
190
215
}
216
+
217
+ self . write_time ( desc, exec_time) ?;
218
+ self . write_plain ( "\n " )
191
219
}
192
220
193
221
fn write_timeout ( & mut self , desc : & TestDesc ) -> io:: Result < ( ) > {
@@ -207,7 +235,13 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
207
235
}
208
236
let success = state. failed == 0 ;
209
237
if !success {
210
- self . write_failures ( state) ?;
238
+ if !state. failures . is_empty ( ) {
239
+ self . write_failures ( state) ?;
240
+ }
241
+
242
+ if !state. time_failures . is_empty ( ) {
243
+ self . write_time_failures ( state) ?;
244
+ }
211
245
}
212
246
213
247
self . write_plain ( "\n test result: " ) ?;
0 commit comments