@@ -19,6 +19,11 @@ use super::{
19
19
types:: { NamePadding , TestDesc , TestDescAndFn } ,
20
20
} ;
21
21
22
+ pub trait Output {
23
+ fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > ;
24
+ fn write_plain ( & mut self , word : & str ) -> io:: Result < ( ) > ;
25
+ }
26
+
22
27
/// Generic wrapper over stdout.
23
28
pub enum OutputLocation < T > {
24
29
Pretty ( Box < term:: StdoutTerminal > ) ,
@@ -41,8 +46,8 @@ impl<T: Write> Write for OutputLocation<T> {
41
46
}
42
47
}
43
48
44
- impl < T : Write > OutputLocation < T > {
45
- pub fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
49
+ impl < T : Write > Output for OutputLocation < T > {
50
+ fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
46
51
match self {
47
52
OutputLocation :: Pretty ( ref mut term) => {
48
53
term. fg ( color) ?;
@@ -57,7 +62,7 @@ impl<T: Write> OutputLocation<T> {
57
62
self . flush ( )
58
63
}
59
64
60
- pub fn write_plain ( & mut self , word : & str ) -> io:: Result < ( ) > {
65
+ fn write_plain ( & mut self , word : & str ) -> io:: Result < ( ) > {
61
66
self . write_all ( word. as_bytes ( ) ) ?;
62
67
self . flush ( )
63
68
}
@@ -193,14 +198,14 @@ impl ConsoleTestState {
193
198
194
199
// List the tests to console, and optionally to logfile. Filters are honored.
195
200
pub fn list_tests_console ( opts : & TestOpts , tests : Vec < TestDescAndFn > ) -> io:: Result < ( ) > {
196
- let output = match term:: stdout ( ) {
201
+ let mut output = match term:: stdout ( ) {
197
202
None => OutputLocation :: Raw ( io:: stdout ( ) . lock ( ) ) ,
198
203
Some ( t) => OutputLocation :: Pretty ( t) ,
199
204
} ;
200
205
201
206
let mut out: Box < dyn OutputFormatter > = match opts. format {
202
207
OutputFormat :: Pretty | OutputFormat :: Junit => {
203
- Box :: new ( PrettyFormatter :: new ( output, false , 0 , false , None ) )
208
+ Box :: new ( PrettyFormatter :: new ( & mut output, false , 0 , false , None ) )
204
209
}
205
210
OutputFormat :: Terse => Box :: new ( TerseFormatter :: new ( output, false , 0 , false ) ) ,
206
211
OutputFormat :: Json => Box :: new ( JsonFormatter :: new ( output) ) ,
@@ -306,7 +311,7 @@ fn on_test_event(
306
311
/// A simple console test runner.
307
312
/// Runs provided tests reporting process and results to the stdout.
308
313
pub fn run_tests_console ( opts : & TestOpts , tests : Vec < TestDescAndFn > ) -> io:: Result < bool > {
309
- let output = match term:: stdout ( ) {
314
+ let mut output = match term:: stdout ( ) {
310
315
None => OutputLocation :: Raw ( io:: stdout ( ) ) ,
311
316
Some ( t) => OutputLocation :: Pretty ( t) ,
312
317
} ;
@@ -321,7 +326,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
321
326
322
327
let mut out: Box < dyn OutputFormatter > = match opts. format {
323
328
OutputFormat :: Pretty => Box :: new ( PrettyFormatter :: new (
324
- output,
329
+ & mut output,
325
330
opts. use_color ( ) ,
326
331
max_name_len,
327
332
is_multithreaded,
0 commit comments