@@ -3,6 +3,7 @@ use super::*;
33pub ( crate ) struct PrettyFormatter < T > {
44 out : OutputLocation < T > ,
55 use_color : bool ,
6+ time_options : Option < TestTimeOptions > ,
67
78 /// Number of columns to fill when aligning names
89 max_name_len : usize ,
@@ -16,12 +17,14 @@ impl<T: Write> PrettyFormatter<T> {
1617 use_color : bool ,
1718 max_name_len : usize ,
1819 is_multithreaded : bool ,
20+ time_options : Option < TestTimeOptions > ,
1921 ) -> Self {
2022 PrettyFormatter {
2123 out,
2224 use_color,
2325 max_name_len,
2426 is_multithreaded,
27+ time_options
2528 }
2629 }
2730
@@ -30,20 +33,24 @@ impl<T: Write> PrettyFormatter<T> {
3033 & self . out
3134 }
3235
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 )
3538 }
3639
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 )
3942 }
4043
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 )
4346 }
4447
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 )
4754 }
4855
4956 pub fn write_bench ( & mut self ) -> io:: Result < ( ) > {
@@ -54,13 +61,8 @@ impl<T: Write> PrettyFormatter<T> {
5461 & mut self ,
5562 result : & str ,
5663 color : term:: color:: Color ,
57- exec_time : Option < & TestExecTime > ,
5864 ) -> 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)
6466 }
6567
6668 pub fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
@@ -88,12 +90,48 @@ impl<T: Write> PrettyFormatter<T> {
8890 self . out . flush ( )
8991 }
9092
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 ( ) ;
94132 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 ( ) ) ;
97135 if !stdout. is_empty ( ) {
98136 stdouts. push_str ( & format ! ( "---- {} stdout ----\n " , f. name) ) ;
99137 let output = String :: from_utf8_lossy ( stdout) ;
@@ -106,38 +144,24 @@ impl<T: Write> PrettyFormatter<T> {
106144 self . write_plain ( & stdouts) ?;
107145 }
108146
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 {
112150 self . write_plain ( & format ! ( " {}\n " , name) ) ?;
113151 }
114152 Ok ( ( ) )
115153 }
116154
155+ pub fn write_successes ( & mut self , state : & ConsoleTestState ) -> io:: Result < ( ) > {
156+ self . write_results ( & state. not_failures , "successes" )
157+ }
158+
117159 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+ }
134162
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)" )
141165 }
142166
143167 fn write_test_name ( & mut self , desc : & TestDesc ) -> io:: Result < ( ) > {
@@ -179,15 +203,19 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
179203 }
180204
181205 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 ( ) ? ,
186210 TrBench ( ref bs) => {
187211 self . write_bench ( ) ?;
188- self . write_plain ( & format ! ( ": {}\n " , fmt_bench_samples( bs) ) )
212+ self . write_plain ( & format ! ( ": {}\n " , fmt_bench_samples( bs) ) ) ? ;
189213 }
214+ TrTimedFail => self . write_time_failed ( ) ?,
190215 }
216+
217+ self . write_time ( desc, exec_time) ?;
218+ self . write_plain ( "\n " )
191219 }
192220
193221 fn write_timeout ( & mut self , desc : & TestDesc ) -> io:: Result < ( ) > {
@@ -207,7 +235,13 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
207235 }
208236 let success = state. failed == 0 ;
209237 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+ }
211245 }
212246
213247 self . write_plain ( "\n test result: " ) ?;
0 commit comments