1 | use std::{io, io::prelude::Write}; |
2 | |
3 | use crate::{ |
4 | console::ConsoleTestState, |
5 | test_result::TestResult, |
6 | time, |
7 | types::{TestDesc, TestName}, |
8 | }; |
9 | |
10 | mod json; |
11 | mod pretty; |
12 | mod terse; |
13 | |
14 | pub(crate) use self::json::JsonFormatter; |
15 | pub(crate) use self::pretty::PrettyFormatter; |
16 | pub(crate) use self::terse::TerseFormatter; |
17 | |
18 | pub(crate) trait OutputFormatter { |
19 | fn write_run_start(&mut self, test_count: usize) -> io::Result<()>; |
20 | fn write_test_start(&mut self, desc: &TestDesc) -> io::Result<()>; |
21 | fn write_timeout(&mut self, desc: &TestDesc) -> io::Result<()>; |
22 | fn write_result( |
23 | &mut self, |
24 | desc: &TestDesc, |
25 | result: &TestResult, |
26 | exec_time: Option<&time::TestExecTime>, |
27 | stdout: &[u8], |
28 | state: &ConsoleTestState, |
29 | ) -> io::Result<()>; |
30 | fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool>; |
31 | } |
32 | |
33 | pub(crate) fn write_stderr_delimiter(test_output: &mut Vec<u8>, test_name: &TestName) { |
34 | match test_output.last() { |
35 | Some(b' \n' ) => (), |
36 | Some(_) => test_output.push(b' \n' ), |
37 | None => (), |
38 | } |
39 | writeln!(test_output, "---- {} stderr ----" , test_name).unwrap(); |
40 | } |
41 | |