nextest_runner/list/
output_format.rs1use crate::{errors::WriteTestListError, write_str::WriteStr};
5use owo_colors::Style;
6use serde::Serialize;
7
8#[derive(Copy, Clone, Debug, Eq, PartialEq)]
10#[cfg_attr(test, derive(test_strategy::Arbitrary))]
11#[non_exhaustive]
12pub enum OutputFormat {
13 Human {
15 verbose: bool,
17 },
18
19 Oneline {
21 verbose: bool,
23 },
24
25 Serializable(SerializableFormat),
27}
28
29#[derive(Copy, Clone, Debug, Eq, PartialEq)]
31#[cfg_attr(test, derive(test_strategy::Arbitrary))]
32#[non_exhaustive]
33pub enum SerializableFormat {
34 Json,
36 JsonPretty,
38}
39
40impl SerializableFormat {
41 pub fn to_writer(
43 self,
44 value: &impl Serialize,
45 writer: &mut dyn WriteStr,
46 ) -> Result<(), WriteTestListError> {
47 let out = match self {
48 SerializableFormat::Json => {
49 serde_json::to_string(value).map_err(WriteTestListError::Json)?
50 }
51 SerializableFormat::JsonPretty => {
52 serde_json::to_string_pretty(value).map_err(WriteTestListError::Json)?
53 }
54 };
55
56 writer.write_str(&out).map_err(WriteTestListError::Io)
57 }
58}
59
60#[derive(Clone, Debug, Default)]
62pub struct Styles {
63 pub(crate) binary_id: Style,
64 pub(crate) test_name: Style,
65 pub(crate) module_path: Style,
66 pub(crate) field: Style,
67 pub(crate) count: Style,
68}
69
70impl Styles {
71 pub fn colorize(&mut self) {
73 self.binary_id = Style::new().magenta().bold();
74 self.test_name = Style::new().blue().bold();
75 self.field = Style::new().yellow().bold();
76 self.module_path = Style::new().cyan();
77 self.count = Style::new().bold();
78 }
79}