nextest_runner/list/
output_format.rsuse crate::{errors::WriteTestListError, write_str::WriteStr};
use owo_colors::Style;
use serde::Serialize;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
#[non_exhaustive]
pub enum OutputFormat {
Human {
verbose: bool,
},
Serializable(SerializableFormat),
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
#[non_exhaustive]
pub enum SerializableFormat {
Json,
JsonPretty,
}
impl SerializableFormat {
pub fn to_writer(
self,
value: &impl Serialize,
writer: &mut dyn WriteStr,
) -> Result<(), WriteTestListError> {
let out = match self {
SerializableFormat::Json => {
serde_json::to_string(value).map_err(WriteTestListError::Json)?
}
SerializableFormat::JsonPretty => {
serde_json::to_string_pretty(value).map_err(WriteTestListError::Json)?
}
};
writer.write_str(&out).map_err(WriteTestListError::Io)
}
}
#[derive(Clone, Debug, Default)]
pub(crate) struct Styles {
pub(crate) binary_id: Style,
pub(crate) test_name: Style,
pub(crate) module_path: Style,
pub(crate) field: Style,
}
impl Styles {
pub(crate) fn colorize(&mut self) {
self.binary_id = Style::new().magenta().bold();
self.test_name = Style::new().blue().bold();
self.field = Style::new().yellow().bold();
self.module_path = Style::new().cyan();
}
}