Skip to content

Commit

Permalink
Fix output bug
Browse files Browse the repository at this point in the history
Running was the _total_ number of running tests, not just the ones in
the same binary, which would result
in only one binary output being written
  • Loading branch information
Jake-Shadle committed Nov 8, 2023
1 parent 1c62c95 commit 1ba42b3
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions nextest-runner/src/reporter/structured/libtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ struct LibtestSuite {
ignored: usize,
/// The number of tests that were not executed due to filters
filtered: usize,
/// The number of tests in this suite that are still running
running: usize,
/// The accumulated duration of every test that has been executed
total: std::time::Duration,
/// Libtest outputs outputs a `started` event for every test that isn't
Expand Down Expand Up @@ -277,6 +279,7 @@ impl<'cfg> LibtestReporter<'cfg> {
out.extend_from_slice(b"}\n");

e.insert(LibtestSuite {
running: suite_info.status.test_count(),
failed: 0,
succeeded: 0,
ignored: 0,
Expand Down Expand Up @@ -322,15 +325,12 @@ impl<'cfg> LibtestReporter<'cfg> {
out.extend_from_slice(b"\"");
}

Check warning on line 326 in nextest-runner/src/reporter/structured/libtest.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter/structured/libtest.rs#L322-L326

Added lines #L322 - L326 were not covered by tests

let done = match &event.kind {
TestEventKind::TestFinished {
run_statuses,
running,
..
} => {
match &event.kind {
TestEventKind::TestFinished { run_statuses, .. } => {
let last_status = run_statuses.last_status();

test_suite.total += last_status.time_taken;
test_suite.running -= 1;

// libtest actually requires an additional `--report-time` flag to be
// passed for the exec_time information to be written. This doesn't
Expand Down Expand Up @@ -375,8 +375,6 @@ impl<'cfg> LibtestReporter<'cfg> {
test_suite.succeeded += 1;
}

Check warning on line 376 in nextest-runner/src/reporter/structured/libtest.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter/structured/libtest.rs#L370-L376

Added lines #L370 - L376 were not covered by tests
}

*running == 0
}
TestEventKind::TestSkipped { reason, .. } => {
if matches!(reason, MismatchReason::Ignored) {
Expand All @@ -385,6 +383,8 @@ impl<'cfg> LibtestReporter<'cfg> {
test_suite.filtered += 1;
}

Check warning on line 384 in nextest-runner/src/reporter/structured/libtest.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter/structured/libtest.rs#L379-L384

Added lines #L379 - L384 were not covered by tests

test_suite.running -= 1;

if test_suite.ignore_block.is_none() {
test_suite.ignore_block = Some(bytes::BytesMut::with_capacity(1024));
}

Check warning on line 390 in nextest-runner/src/reporter/structured/libtest.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter/structured/libtest.rs#L386-L390

Added lines #L386 - L390 were not covered by tests
Expand All @@ -401,17 +401,15 @@ impl<'cfg> LibtestReporter<'cfg> {
test_instance.name,
)
.map_err(fmt_err)?;

Check warning on line 403 in nextest-runner/src/reporter/structured/libtest.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter/structured/libtest.rs#L392-L403

Added lines #L392 - L403 were not covered by tests

false
}
_ => false,
_ => {}

Check warning on line 405 in nextest-runner/src/reporter/structured/libtest.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter/structured/libtest.rs#L405

Added line #L405 was not covered by tests
};

out.extend_from_slice(b"}\n");

// If this is the last test of the suite, emit the test suite summary
// before emitting the entire block
if !done {
if test_suite.running > 0 {
return Ok(());
}

Check warning on line 414 in nextest-runner/src/reporter/structured/libtest.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter/structured/libtest.rs#L408-L414

Added lines #L408 - L414 were not covered by tests

Expand Down Expand Up @@ -443,10 +441,13 @@ impl<'cfg> LibtestReporter<'cfg> {

out.extend_from_slice(b"}\n");

use std::io::Write as _;
std::io::stdout()
.write_all(out)
.map_err(WriteEventError::Io)?;
{
use std::io::Write as _;

let mut stdout = std::io::stdout().lock();
stdout.write_all(out).map_err(WriteEventError::Io)?;
stdout.flush().map_err(WriteEventError::Io)?;

Check warning on line 449 in nextest-runner/src/reporter/structured/libtest.rs

View check run for this annotation

Codecov / codecov/patch

nextest-runner/src/reporter/structured/libtest.rs#L442-L449

Added lines #L442 - L449 were not covered by tests
}

// Once we've emitted the output block we can remove the suite accumulator
// to free up memory since we won't use it again
Expand Down

0 comments on commit 1ba42b3

Please sign in to comment.