@@ -91,6 +91,7 @@ enum test_result { tr_ok, tr_failed, tr_ignored, }
91
91
type console_test_state =
92
92
@{ out : io:: writer,
93
93
log_out: option < io:: writer > ,
94
+ use_color : bool,
94
95
mut total : uint,
95
96
mut passed : uint,
96
97
mut failed : uint,
@@ -116,6 +117,7 @@ fn run_tests_console(opts: test_opts,
116
117
let st =
117
118
@{ out: io:: stdout ( ) ,
118
119
log_out: log_out,
120
+ use_color: use_color ( ) ,
119
121
mut total: 0 u,
120
122
mut passed: 0 u,
121
123
mut failed: 0 u,
@@ -148,18 +150,18 @@ fn run_tests_console(opts: test_opts,
148
150
alt result {
149
151
tr_ok {
150
152
st. passed += 1 u;
151
- write_ok ( st. out ) ;
153
+ write_ok ( st. out , st . use_color ) ;
152
154
st. out . write_line ( "" ) ;
153
155
}
154
156
tr_failed {
155
157
st. failed += 1 u;
156
- write_failed ( st. out ) ;
158
+ write_failed ( st. out , st . use_color ) ;
157
159
st. out . write_line ( "" ) ;
158
160
st. failures += [ test] ;
159
161
}
160
162
tr_ignored {
161
163
st. ignored += 1 u;
162
- write_ignored ( st. out ) ;
164
+ write_ignored ( st. out , st . use_color ) ;
163
165
st. out . write_line ( "" ) ;
164
166
}
165
167
}
@@ -178,9 +180,11 @@ fn run_tests_console(opts: test_opts,
178
180
}
179
181
180
182
st. out . write_str ( #fmt[ "\n result: " ] ) ;
181
- if success { write_ok ( st. out ) ; } else { write_failed ( st. out ) ; }
182
- st. out . write_str ( #fmt[ ". %u passed; %u failed; %u ignored\n \n " ,
183
- st. passed , st. failed , st. ignored ] ) ;
183
+ if success {
184
+ write_ok ( st. out , true ) ;
185
+ } else { write_failed ( st. out , true ) ; }
186
+ st. out . write_str ( #fmt[ ". %u passed; %u failed; %u ignored\n \n " , st. passed ,
187
+ st. failed , st. ignored ] ) ;
184
188
185
189
ret success;
186
190
@@ -193,24 +197,24 @@ fn run_tests_console(opts: test_opts,
193
197
} , test. name ) ) ;
194
198
}
195
199
196
- fn write_ok ( out : io:: writer ) {
197
- write_pretty ( out, "ok" , term:: color_green) ;
200
+ fn write_ok ( out : io:: writer , use_color : bool ) {
201
+ write_pretty ( out, "ok" , term:: color_green, use_color ) ;
198
202
}
199
203
200
- fn write_failed ( out : io:: writer ) {
201
- write_pretty ( out, "FAILED" , term:: color_red) ;
204
+ fn write_failed ( out : io:: writer , use_color : bool ) {
205
+ write_pretty ( out, "FAILED" , term:: color_red, use_color ) ;
202
206
}
203
207
204
- fn write_ignored ( out : io:: writer ) {
205
- write_pretty ( out, "ignored" , term:: color_yellow) ;
208
+ fn write_ignored ( out : io:: writer , use_color : bool ) {
209
+ write_pretty ( out, "ignored" , term:: color_yellow, use_color ) ;
206
210
}
207
211
208
- fn write_pretty ( out : io:: writer , word : str , color : u8 ) {
209
- if term:: color_supported ( ) {
212
+ fn write_pretty ( out : io:: writer , word : str , color : u8 , use_color : bool ) {
213
+ if use_color && term:: color_supported ( ) {
210
214
term:: fg ( out, color) ;
211
215
}
212
216
out. write_str ( word) ;
213
- if term:: color_supported ( ) {
217
+ if use_color && term:: color_supported ( ) {
214
218
term:: reset ( out) ;
215
219
}
216
220
}
@@ -247,6 +251,7 @@ fn should_sort_failures_before_printing_them() {
247
251
let st =
248
252
@{out: writer,
249
253
log_out: option::none,
254
+ use_color: false,
250
255
mut total: 0u,
251
256
mut passed: 0u,
252
257
mut failed: 0u,
@@ -262,6 +267,8 @@ fn should_sort_failures_before_printing_them() {
262
267
assert apos < bpos;
263
268
}
264
269
270
+ fn use_color ( ) -> bool { ret get_concurrency ( ) == 1 u; }
271
+
265
272
enum testevent {
266
273
te_filtered( [ test_desc ] ) ,
267
274
te_wait( test_desc ) ,
0 commit comments