Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 82 additions & 16 deletions nextest-runner/src/reporter/displayer/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub(crate) struct DisplayReporterBuilder {
pub(crate) failure_output: Option<TestOutputDisplay>,
pub(crate) should_colorize: bool,
pub(crate) no_capture: bool,
pub(crate) verbose: bool,
pub(crate) show_progress: ShowProgress,
pub(crate) no_output_indent: bool,
pub(crate) max_progress_running: MaxProgressRunning,
Expand Down Expand Up @@ -141,6 +142,7 @@ impl DisplayReporterBuilder {
final_status_level: self.status_levels.final_status_level,
},
no_capture: self.no_capture,
verbose: self.verbose,
no_output_indent: self.no_output_indent,
counter_width,
styles,
Expand Down Expand Up @@ -377,6 +379,7 @@ struct DisplayReporterImpl<'a> {
default_filter: CompiledDefaultFilter,
status_levels: StatusLevels,
no_capture: bool,
verbose: bool,
no_output_indent: bool,
// None if no counter is displayed. If a counter is displayed, this is the
// width of the total number of tests to run.
Expand Down Expand Up @@ -623,6 +626,10 @@ impl<'a> DisplayReporterImpl<'a> {
),
)?;
}

if self.verbose {
self.write_test_command_line(test_instance, writer)?;
}
}
TestEventKind::TestSlow {
stress_index,
Expand Down Expand Up @@ -1312,6 +1319,28 @@ impl<'a> DisplayReporterImpl<'a> {
Ok(())
}

fn write_test_command_line(
&self,
test_instance: &TestInstance<'a>,
writer: &mut dyn WriteStr,
) -> io::Result<()> {
// Display the command line that will be used to run this test.
// Format: binary_path --exact test_name --nocapture [--ignored]
write!(
writer,
"{:>12} {} --exact {} --nocapture",
"COMMAND".style(self.styles.count),
test_instance.suite_info.binary_path,
test_instance.name,
)?;
if test_instance.test_info.ignored {
write!(writer, " --ignored")?;
}
writeln!(writer)?;

Ok(())
}

fn write_setup_script_status_line(
&self,
stress_index: Option<StressIndex>,
Expand Down Expand Up @@ -2360,10 +2389,29 @@ mod tests {
use smol_str::SmolStr;
use std::{num::NonZero, sync::Arc};

fn default_builder() -> DisplayReporterBuilder {
DisplayReporterBuilder {
default_filter: CompiledDefaultFilter::for_default_config(),
status_levels: StatusLevels {
status_level: StatusLevel::Fail,
final_status_level: FinalStatusLevel::Fail,
},
test_count: 5000,
success_output: Some(TestOutputDisplay::Immediate),
failure_output: Some(TestOutputDisplay::Immediate),
should_colorize: false,
no_capture: true,
verbose: false,
show_progress: ShowProgress::Counter,
no_output_indent: false,
max_progress_running: MaxProgressRunning::default(),
}
}

Comment on lines +2392 to +2410

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be better as an impl Default instead of a free standing fn?

/// Creates a test reporter with default settings and calls the given function with it.
///
/// Returns the output written to the reporter.
fn with_reporter<'a, F>(f: F, out: &'a mut String)
fn with_reporter<'a, F>(builder: DisplayReporterBuilder, f: F, out: &'a mut String)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're passing default_builder() at every call site isn't it just better to not have it as an argument and always construct a default builder inside the function?

where
F: FnOnce(DisplayReporter<'a>),
{
Expand All @@ -2379,21 +2427,6 @@ mod tests {
)
.unwrap();

let builder = DisplayReporterBuilder {
default_filter: CompiledDefaultFilter::for_default_config(),
status_levels: StatusLevels {
status_level: StatusLevel::Fail,
final_status_level: FinalStatusLevel::Fail,
},
test_count: 5000,
success_output: Some(TestOutputDisplay::Immediate),
failure_output: Some(TestOutputDisplay::Immediate),
should_colorize: false,
no_capture: true,
show_progress: ShowProgress::Counter,
no_output_indent: false,
max_progress_running: MaxProgressRunning::default(),
};
let output = ReporterStderr::Buffer(out);
let reporter = builder.build(&configs, output);
f(reporter);
Expand Down Expand Up @@ -2452,6 +2485,7 @@ mod tests {
let mut out = String::new();

with_reporter(
default_builder(),
|mut reporter| {
// TODO: write a bunch more outputs here.
reporter
Expand Down Expand Up @@ -2508,6 +2542,7 @@ mod tests {
let mut out = String::new();

with_reporter(
default_builder(),
|mut reporter| {
// Test single run with all passing tests
let run_stats_success = RunStats {
Expand Down Expand Up @@ -2685,6 +2720,7 @@ mod tests {
let mut out = String::new();

with_reporter(
default_builder(),
|mut reporter| {
// Info started event.
reporter
Expand Down Expand Up @@ -3130,6 +3166,7 @@ mod tests {
let mut out = String::new();

with_reporter(
default_builder(),
|reporter| {
assert!(reporter.inner.no_capture, "no_capture is true");
assert_eq!(
Expand All @@ -3151,6 +3188,35 @@ mod tests {
&mut out,
);
}

#[test]
fn test_verbose_flag() {
// Test with verbose = false
let mut out_non_verbose = String::new();
let builder = default_builder();
with_reporter(
builder,
|reporter| {
assert!(
!reporter.inner.verbose,
"verbose should be false when not set"
);
},
&mut out_non_verbose,
);

// Test with verbose = true
let mut out_verbose = String::new();
let mut builder_verbose = default_builder();
builder_verbose.verbose = true;
with_reporter(
builder_verbose,
|reporter| {
assert!(reporter.inner.verbose, "verbose should be true when set");
},
&mut out_verbose,
);
}
}

#[cfg(all(windows, test))]
Expand Down
1 change: 1 addition & 0 deletions nextest-runner/src/reporter/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl ReporterBuilder {
failure_output: self.failure_output,
should_colorize: self.should_colorize,
no_capture: self.no_capture,
verbose: self.verbose,
show_progress: self.show_progress,
no_output_indent: self.no_output_indent,
max_progress_running: self.max_progress_running,
Expand Down
Loading