nextest_runner/reporter/
imp.rsuse super::{
displayer::{DisplayReporter, DisplayReporterBuilder, StatusLevels},
FinalStatusLevel, StatusLevel, TestOutputDisplay,
};
use crate::{
config::EvaluatableProfile,
errors::WriteEventError,
list::TestList,
reporter::{aggregator::EventAggregator, events::*, structured::StructuredReporter},
};
pub enum ReporterStderr<'a> {
Terminal,
Buffer(&'a mut Vec<u8>),
}
#[derive(Debug, Default)]
pub struct ReporterBuilder {
no_capture: bool,
should_colorize: bool,
failure_output: Option<TestOutputDisplay>,
success_output: Option<TestOutputDisplay>,
status_level: Option<StatusLevel>,
final_status_level: Option<FinalStatusLevel>,
verbose: bool,
hide_progress_bar: bool,
}
impl ReporterBuilder {
pub fn set_no_capture(&mut self, no_capture: bool) -> &mut Self {
self.no_capture = no_capture;
self
}
pub fn set_colorize(&mut self, should_colorize: bool) -> &mut Self {
self.should_colorize = should_colorize;
self
}
pub fn set_failure_output(&mut self, failure_output: TestOutputDisplay) -> &mut Self {
self.failure_output = Some(failure_output);
self
}
pub fn set_success_output(&mut self, success_output: TestOutputDisplay) -> &mut Self {
self.success_output = Some(success_output);
self
}
pub fn set_status_level(&mut self, status_level: StatusLevel) -> &mut Self {
self.status_level = Some(status_level);
self
}
pub fn set_final_status_level(&mut self, final_status_level: FinalStatusLevel) -> &mut Self {
self.final_status_level = Some(final_status_level);
self
}
pub fn set_verbose(&mut self, verbose: bool) -> &mut Self {
self.verbose = verbose;
self
}
pub fn set_hide_progress_bar(&mut self, hide_progress_bar: bool) -> &mut Self {
self.hide_progress_bar = hide_progress_bar;
self
}
}
impl ReporterBuilder {
pub fn build<'a>(
&self,
test_list: &TestList,
profile: &EvaluatableProfile<'a>,
output: ReporterStderr<'a>,
structured_reporter: StructuredReporter<'a>,
) -> Reporter<'a> {
let aggregator = EventAggregator::new(profile);
let status_level = self.status_level.unwrap_or_else(|| profile.status_level());
let final_status_level = self
.final_status_level
.unwrap_or_else(|| profile.final_status_level());
let display_reporter = DisplayReporterBuilder {
default_filter: profile.default_filter().clone(),
status_levels: StatusLevels {
status_level,
final_status_level,
},
test_count: test_list.test_count(),
success_output: self.success_output,
failure_output: self.failure_output,
should_colorize: self.should_colorize,
no_capture: self.no_capture,
hide_progress_bar: self.hide_progress_bar,
}
.build(output);
Reporter {
display_reporter,
structured_reporter,
metadata_reporter: aggregator,
}
}
}
pub struct Reporter<'a> {
display_reporter: DisplayReporter<'a>,
metadata_reporter: EventAggregator<'a>,
structured_reporter: StructuredReporter<'a>,
}
impl<'a> Reporter<'a> {
pub fn report_event(&mut self, event: TestEvent<'a>) -> Result<(), WriteEventError> {
self.write_event(event)
}
pub fn finish(&mut self) {
self.display_reporter.finish();
}
fn write_event(&mut self, event: TestEvent<'a>) -> Result<(), WriteEventError> {
self.display_reporter.write_event(&event)?;
self.structured_reporter.write_event(&event)?;
self.metadata_reporter.write_event(event)?;
Ok(())
}
}