Skip to content

Commit

Permalink
Cleanup before landing
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshowers committed Jan 9, 2024
1 parent fdc28ef commit 1b8b6ff
Show file tree
Hide file tree
Showing 14 changed files with 452 additions and 702 deletions.
11 changes: 6 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
]

[workspace.dependencies]
bstr = { version = "1.9.0", default-features = false, features = ["std"] }
globset = "0.4.14"
nextest-metadata = { version = "0.10.0", path = "nextest-metadata" }
nextest-workspace-hack = "0.1.0"
Expand Down
1 change: 1 addition & 0 deletions nextest-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ atomicwrites = "0.4.3"
aho-corasick = "1.1.2"
async-scoped = { version = "0.8.0", features = ["use-tokio"] }
future-queue = "0.3.0"
bstr.workspace = true
bytes = "1.5.0"
camino = { version = "1.1.6", features = ["serde1"] }
camino-tempfile = "1.1.1"
Expand Down
110 changes: 73 additions & 37 deletions nextest-runner/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
AbortStatus, ExecuteStatus, ExecutionDescription, ExecutionResult, ExecutionStatuses,
RetryData, RunStats, SetupScriptExecuteStatus,
},
test_output::{TestOutput, TestSingleOutput},
};
pub use aggregator::heuristic_extract_description;
use debug_ignore::DebugIgnore;
Expand Down Expand Up @@ -750,7 +751,7 @@ impl<'a> TestReporterImpl<'a> {
"only failing tests are retried"
);
if self.failure_output(*failure_output).is_immediate() {
self.write_stdout_stderr(test_instance, run_status, true, writer)?;
self.write_output(test_instance, run_status, true, writer)?;

Check warning on line 754 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L754

Added line #L754 was not covered by tests
}

// The final output doesn't show retries, so don't store this result in
Expand Down Expand Up @@ -816,7 +817,7 @@ impl<'a> TestReporterImpl<'a> {
self.write_status_line(*test_instance, describe, writer)?;
}
if output_on_test_finished.show_immediate {
self.write_stdout_stderr(test_instance, last_status, true, writer)?;
self.write_output(test_instance, last_status, true, writer)?;
}
if let OutputStoreFinal::Yes { display_output } =
output_on_test_finished.store_final
Expand Down Expand Up @@ -1018,12 +1019,7 @@ impl<'a> TestReporterImpl<'a> {
writer,
)?;
if *display_output {
self.write_stdout_stderr(
test_instance,
last_status,
false,
writer,
)?;
self.write_output(test_instance, last_status, false, writer)?;

Check warning on line 1022 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1022

Added line #L1022 was not covered by tests
}
}
}
Expand Down Expand Up @@ -1313,21 +1309,21 @@ impl<'a> TestReporterImpl<'a> {
self.write_setup_script(script_id, command, args, writer)?;
writeln!(writer, "{}", " ---".style(header_style))?;

self.write_test_output(&run_status.stdout, writer)?;
self.write_test_single_output(&run_status.stdout, writer)?;

Check warning on line 1312 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1312

Added line #L1312 was not covered by tests
}
if !run_status.stderr.is_empty() {
write!(writer, "\n{}", "--- ".style(header_style))?;
write!(writer, "{:21}", "STDERR:".style(header_style))?;
self.write_setup_script(script_id, command, args, writer)?;
writeln!(writer, "{}", " ---".style(header_style))?;

self.write_test_output(&run_status.stderr, writer)?;
self.write_test_single_output(&run_status.stderr, writer)?;

Check warning on line 1320 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1320

Added line #L1320 was not covered by tests
}

writeln!(writer)
}

fn write_stdout_stderr(
fn write_output(
&self,
test_instance: &TestInstance<'a>,
run_status: &ExecuteStatus,
Expand All @@ -1342,58 +1338,98 @@ impl<'a> TestReporterImpl<'a> {
(self.styles.fail, self.styles.fail_output)
};

{
let stdout = run_status.output.stdout();
if !stdout.is_empty() {
write!(writer, "\n{}", "--- ".style(header_style))?;
let out_len = self.write_attempt(run_status, header_style, writer)?;
// The width is to align test instances.
write!(
writer,
"{:width$}",
"STDOUT:".style(header_style),
width = (21 - out_len)
)?;
self.write_instance(*test_instance, writer)?;
writeln!(writer, "{}", " ---".style(header_style))?;
match &run_status.output {
Some(TestOutput::Split { stdout, stderr }) => {
if !stdout.is_empty() {
write!(writer, "\n{}", "--- ".style(header_style))?;
let out_len = self.write_attempt(run_status, header_style, writer)?;
// The width is to align test instances.
write!(
writer,
"{:width$}",
"STDOUT:".style(header_style),
width = (21 - out_len)
)?;
self.write_instance(*test_instance, writer)?;
writeln!(writer, "{}", " ---".style(header_style))?;

self.write_test_single_output(stdout, writer)?;
}

Check warning on line 1357 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1357

Added line #L1357 was not covered by tests

if !stderr.is_empty() {
write!(writer, "\n{}", "--- ".style(header_style))?;
let out_len = self.write_attempt(run_status, header_style, writer)?;
// The width is to align test instances.
write!(
writer,
"{:width$}",
"STDERR:".style(header_style),
width = (21 - out_len)
)?;
self.write_instance(*test_instance, writer)?;
writeln!(writer, "{}", " ---".style(header_style))?;

self.write_test_output(&stdout, writer)?;
self.write_test_single_output(stderr, writer)?;
}
}
}

{
let stderr = run_status.output.stderr();
if !stderr.is_empty() {
Some(TestOutput::Combined { output }) => {
if !output.is_empty() {
write!(writer, "\n{}", "--- ".style(header_style))?;
let out_len = self.write_attempt(run_status, header_style, writer)?;

Check warning on line 1379 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1376-L1379

Added lines #L1376 - L1379 were not covered by tests
// The width is to align test instances.
write!(
writer,
"{:width$}",
"OUTPUT:".style(header_style),
width = (21 - out_len)
)?;
self.write_instance(*test_instance, writer)?;
writeln!(writer, "{}", " ---".style(header_style))?;

Check warning on line 1388 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1381-L1388

Added lines #L1381 - L1388 were not covered by tests

self.write_test_single_output(output, writer)?;
}

Check warning on line 1391 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1390-L1391

Added lines #L1390 - L1391 were not covered by tests
}

Some(TestOutput::ExecFail { description, .. }) => {
write!(writer, "\n{}", "--- ".style(header_style))?;
let out_len = self.write_attempt(run_status, header_style, writer)?;

Check warning on line 1396 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1394-L1396

Added lines #L1394 - L1396 were not covered by tests
// The width is to align test instances.
write!(
writer,
"{:width$}",
"STDERR:".style(header_style),
"EXECFAIL:".style(header_style),
width = (21 - out_len)
)?;
self.write_instance(*test_instance, writer)?;
writeln!(writer, "{}", " ---".style(header_style))?;

Check warning on line 1405 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1398-L1405

Added lines #L1398 - L1405 were not covered by tests

self.write_test_output(&stderr, writer)?;
writeln!(writer, "{}", description)?;

Check warning on line 1407 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1407

Added line #L1407 was not covered by tests
}

None => {
// The output wasn't captured.
}

Check warning on line 1412 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1410-L1412

Added lines #L1410 - L1412 were not covered by tests
}

writeln!(writer)
}

fn write_test_output(&self, output: &[u8], writer: &mut dyn Write) -> io::Result<()> {
fn write_test_single_output(
&self,
output: &TestSingleOutput,
writer: &mut dyn Write,
) -> io::Result<()> {
if self.styles.is_colorized {
const RESET_COLOR: &[u8] = b"\x1b[0m";
// Output the text without stripping ANSI escapes, then reset the color afterwards in case
// the output is malformed.
writer.write_all(output)?;
// Output the text without stripping ANSI escapes, then reset the color afterwards in
// case the output is malformed.
writer.write_all(&output.buf)?;

Check warning on line 1427 in nextest-runner/src/reporter.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter.rs#L1427

Added line #L1427 was not covered by tests
writer.write_all(RESET_COLOR)?;
} else {
// Strip ANSI escapes from the output if nextest itself isn't colorized.
let mut no_color = strip_ansi_escapes::Writer::new(writer);
no_color.write_all(output)?;
no_color.write_all(&output.buf)?;
}

Ok(())
Expand Down
Loading

0 comments on commit 1b8b6ff

Please sign in to comment.