@@ -4,6 +4,7 @@ use std::fs::File;
4
4
use std:: io;
5
5
use std:: io:: prelude:: Write ;
6
6
use std:: time:: Instant ;
7
+ use std:: vec;
7
8
8
9
use super :: {
9
10
bench:: fmt_bench_samples,
@@ -34,14 +35,14 @@ impl<T: Write> Write for OutputLocation<T> {
34
35
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
35
36
match * self {
36
37
OutputLocation :: Pretty ( ref mut term) => term. write ( buf) ,
37
- OutputLocation :: Raw ( ref mut stdout ) => stdout . write ( buf) ,
38
+ OutputLocation :: Raw ( ref mut stdout_or_file ) => stdout_or_file . write ( buf) ,
38
39
}
39
40
}
40
41
41
42
fn flush ( & mut self ) -> io:: Result < ( ) > {
42
43
match * self {
43
44
OutputLocation :: Pretty ( ref mut term) => term. flush ( ) ,
44
- OutputLocation :: Raw ( ref mut stdout ) => stdout . flush ( ) ,
45
+ OutputLocation :: Raw ( ref mut stdout_or_file ) => stdout_or_file . flush ( ) ,
45
46
}
46
47
}
47
48
}
@@ -68,18 +69,43 @@ impl<T: Write> Output for OutputLocation<T> {
68
69
}
69
70
}
70
71
72
+ struct OutputMultiplexer {
73
+ pub outputs : Vec < Box < dyn Output > > ,
74
+ }
75
+
76
+ impl Output for OutputMultiplexer {
77
+ fn write_pretty ( & mut self , word : & str , color : term:: color:: Color ) -> io:: Result < ( ) > {
78
+ for output in & mut self . outputs {
79
+ output. write_pretty ( word, color) ?;
80
+ }
81
+
82
+ Ok ( ( ) )
83
+ }
84
+
85
+ fn write_plain ( & mut self , word : & str ) -> io:: Result < ( ) > {
86
+ for output in & mut self . outputs {
87
+ output. write_plain ( word) ?;
88
+ }
89
+
90
+ Ok ( ( ) )
91
+ }
92
+ }
93
+
71
94
pub struct ConsoleTestDiscoveryState {
72
- pub log_out : Option < File > ,
95
+ log_out : OutputMultiplexer ,
73
96
pub tests : usize ,
74
97
pub benchmarks : usize ,
75
98
pub ignored : usize ,
76
99
}
77
100
78
101
impl ConsoleTestDiscoveryState {
79
102
pub fn new ( opts : & TestOpts ) -> io:: Result < ConsoleTestDiscoveryState > {
80
- let log_out = match opts. logfile {
81
- Some ( ref path) => Some ( File :: create ( path) ?) ,
82
- None => None ,
103
+ let mut log_out = OutputMultiplexer { outputs : vec ! [ ] } ;
104
+ match opts. logfile {
105
+ Some ( ref path) => {
106
+ log_out. outputs . push ( Box :: new ( OutputLocation :: Raw ( File :: create ( path) ?) ) )
107
+ }
108
+ None => ( ) ,
83
109
} ;
84
110
85
111
Ok ( ConsoleTestDiscoveryState { log_out, tests : 0 , benchmarks : 0 , ignored : 0 } )
@@ -90,14 +116,9 @@ impl ConsoleTestDiscoveryState {
90
116
S : AsRef < str > ,
91
117
F : FnOnce ( ) -> S ,
92
118
{
93
- match self . log_out {
94
- None => Ok ( ( ) ) ,
95
- Some ( ref mut o) => {
96
- let msg = msg ( ) ;
97
- let msg = msg. as_ref ( ) ;
98
- o. write_all ( msg. as_bytes ( ) )
99
- }
100
- }
119
+ let msg = msg ( ) ;
120
+ let msg = msg. as_ref ( ) ;
121
+ self . log_out . write_plain ( msg)
101
122
}
102
123
}
103
124
0 commit comments