@@ -19,6 +19,11 @@ use super::{
1919 types:: { NamePadding , TestDesc , TestDescAndFn } ,
2020} ;
2121
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+
2227/// Generic wrapper over stdout.
2328pub enum OutputLocation < T > {
2429 Pretty ( Box < term:: StdoutTerminal > ) ,
@@ -41,8 +46,8 @@ impl<T: Write> Write for OutputLocation<T> {
4146 }
4247}
4348
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 < ( ) > {
4651 match self {
4752 OutputLocation :: Pretty ( ref mut term) => {
4853 term. fg ( color) ?;
@@ -57,7 +62,7 @@ impl<T: Write> OutputLocation<T> {
5762 self . flush ( )
5863 }
5964
60- pub fn write_plain ( & mut self , word : & str ) -> io:: Result < ( ) > {
65+ fn write_plain ( & mut self , word : & str ) -> io:: Result < ( ) > {
6166 self . write_all ( word. as_bytes ( ) ) ?;
6267 self . flush ( )
6368 }
@@ -193,14 +198,14 @@ impl ConsoleTestState {
193198
194199// List the tests to console, and optionally to logfile. Filters are honored.
195200pub fn list_tests_console ( opts : & TestOpts , tests : Vec < TestDescAndFn > ) -> io:: Result < ( ) > {
196- let output = match term:: stdout ( ) {
201+ let mut output = match term:: stdout ( ) {
197202 None => OutputLocation :: Raw ( io:: stdout ( ) . lock ( ) ) ,
198203 Some ( t) => OutputLocation :: Pretty ( t) ,
199204 } ;
200205
201206 let mut out: Box < dyn OutputFormatter > = match opts. format {
202207 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 ) )
204209 }
205210 OutputFormat :: Terse => Box :: new ( TerseFormatter :: new ( output, false , 0 , false ) ) ,
206211 OutputFormat :: Json => Box :: new ( JsonFormatter :: new ( output) ) ,
@@ -306,7 +311,7 @@ fn on_test_event(
306311/// A simple console test runner.
307312/// Runs provided tests reporting process and results to the stdout.
308313pub 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 ( ) {
310315 None => OutputLocation :: Raw ( io:: stdout ( ) ) ,
311316 Some ( t) => OutputLocation :: Pretty ( t) ,
312317 } ;
@@ -321,7 +326,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
321326
322327 let mut out: Box < dyn OutputFormatter > = match opts. format {
323328 OutputFormat :: Pretty => Box :: new ( PrettyFormatter :: new (
324- output,
329+ & mut output,
325330 opts. use_color ( ) ,
326331 max_name_len,
327332 is_multithreaded,
0 commit comments