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