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 Serializable(SerializableFormat),
21}
22
23#[derive(Copy, Clone, Debug, Eq, PartialEq)]
25#[cfg_attr(test, derive(test_strategy::Arbitrary))]
26#[non_exhaustive]
27pub enum SerializableFormat {
28 Json,
30 JsonPretty,
32}
33
34impl SerializableFormat {
35 pub fn to_writer(
37 self,
38 value: &impl Serialize,
39 writer: &mut dyn WriteStr,
40 ) -> Result<(), WriteTestListError> {
41 let out = match self {
42 SerializableFormat::Json => {
43 serde_json::to_string(value).map_err(WriteTestListError::Json)?
44 }
45 SerializableFormat::JsonPretty => {
46 serde_json::to_string_pretty(value).map_err(WriteTestListError::Json)?
47 }
48 };
49
50 writer.write_str(&out).map_err(WriteTestListError::Io)
51 }
52}
53
54#[derive(Clone, Debug, Default)]
55pub(crate) struct Styles {
56 pub(crate) binary_id: Style,
57 pub(crate) test_name: Style,
58 pub(crate) module_path: Style,
59 pub(crate) field: Style,
60}
61
62impl Styles {
63 pub(crate) fn colorize(&mut self) {
64 self.binary_id = Style::new().magenta().bold();
65 self.test_name = Style::new().blue().bold();
66 self.field = Style::new().yellow().bold();
67 self.module_path = Style::new().cyan();
68 }
69}