nextest_runner/reporter/
imp.rs1use super::{
9 FinalStatusLevel, StatusLevel, TestOutputDisplay,
10 displayer::{DisplayReporter, DisplayReporterBuilder, StatusLevels},
11};
12use crate::{
13 config::EvaluatableProfile,
14 errors::WriteEventError,
15 list::TestList,
16 reporter::{aggregator::EventAggregator, events::*, structured::StructuredReporter},
17};
18
19pub enum ReporterStderr<'a> {
23 Terminal,
27
28 Buffer(&'a mut Vec<u8>),
30}
31
32#[derive(Debug, Default)]
34pub struct ReporterBuilder {
35 no_capture: bool,
36 should_colorize: bool,
37 failure_output: Option<TestOutputDisplay>,
38 success_output: Option<TestOutputDisplay>,
39 status_level: Option<StatusLevel>,
40 final_status_level: Option<FinalStatusLevel>,
41
42 verbose: bool,
43 hide_progress_bar: bool,
44 no_output_indent: bool,
45}
46
47impl ReporterBuilder {
48 pub fn set_no_capture(&mut self, no_capture: bool) -> &mut Self {
53 self.no_capture = no_capture;
54 self
55 }
56
57 pub fn set_colorize(&mut self, should_colorize: bool) -> &mut Self {
59 self.should_colorize = should_colorize;
60 self
61 }
62
63 pub fn set_failure_output(&mut self, failure_output: TestOutputDisplay) -> &mut Self {
65 self.failure_output = Some(failure_output);
66 self
67 }
68
69 pub fn set_success_output(&mut self, success_output: TestOutputDisplay) -> &mut Self {
71 self.success_output = Some(success_output);
72 self
73 }
74
75 pub fn set_status_level(&mut self, status_level: StatusLevel) -> &mut Self {
77 self.status_level = Some(status_level);
78 self
79 }
80
81 pub fn set_final_status_level(&mut self, final_status_level: FinalStatusLevel) -> &mut Self {
83 self.final_status_level = Some(final_status_level);
84 self
85 }
86
87 pub fn set_verbose(&mut self, verbose: bool) -> &mut Self {
89 self.verbose = verbose;
90 self
91 }
92
93 pub fn set_hide_progress_bar(&mut self, hide_progress_bar: bool) -> &mut Self {
96 self.hide_progress_bar = hide_progress_bar;
97 self
98 }
99
100 pub fn set_no_output_indent(&mut self, no_output_indent: bool) -> &mut Self {
102 self.no_output_indent = no_output_indent;
103 self
104 }
105}
106
107impl ReporterBuilder {
108 pub fn build<'a>(
110 &self,
111 test_list: &TestList,
112 profile: &EvaluatableProfile<'a>,
113 output: ReporterStderr<'a>,
114 structured_reporter: StructuredReporter<'a>,
115 ) -> Reporter<'a> {
116 let aggregator = EventAggregator::new(profile);
117
118 let status_level = self.status_level.unwrap_or_else(|| profile.status_level());
119 let final_status_level = self
120 .final_status_level
121 .unwrap_or_else(|| profile.final_status_level());
122
123 let display_reporter = DisplayReporterBuilder {
124 default_filter: profile.default_filter().clone(),
125 status_levels: StatusLevels {
126 status_level,
127 final_status_level,
128 },
129 test_count: test_list.test_count(),
130 success_output: self.success_output,
131 failure_output: self.failure_output,
132 should_colorize: self.should_colorize,
133 no_capture: self.no_capture,
134 hide_progress_bar: self.hide_progress_bar,
135 no_output_indent: self.no_output_indent,
136 }
137 .build(output);
138
139 Reporter {
140 display_reporter,
141 structured_reporter,
142 metadata_reporter: aggregator,
143 }
144 }
145}
146
147pub struct Reporter<'a> {
150 display_reporter: DisplayReporter<'a>,
152 metadata_reporter: EventAggregator<'a>,
154 structured_reporter: StructuredReporter<'a>,
156}
157
158impl<'a> Reporter<'a> {
159 pub fn report_event(&mut self, event: TestEvent<'a>) -> Result<(), WriteEventError> {
161 self.write_event(event)
162 }
163
164 pub fn finish(&mut self) {
166 self.display_reporter.finish();
167 }
168
169 fn write_event(&mut self, event: TestEvent<'a>) -> Result<(), WriteEventError> {
175 self.display_reporter.write_event(&event)?;
177 self.structured_reporter.write_event(&event)?;
178 self.metadata_reporter.write_event(event)?;
179 Ok(())
180 }
181}