Skip to content

Commit

Permalink
fix(inoculate): --nocapture disabling output parsing (#511)
Browse files Browse the repository at this point in the history
Currently, the `--nocapture` flag to `cargo inoculate test` incorrectly
disables the processing of test output, so we can't actually detect that
tests are running. This is wrong. This commit makes it just print each
line of output to stdout, but still try to parse them.
  • Loading branch information
hawkw committed Jan 11, 2025
1 parent e43cad5 commit 29d1179
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions inoculate/src/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ struct TestResults {
impl Cmd {
fn should_capture(&self) -> bool {
match self {
Cmd::Test {
nocapture: true, ..
} => {
tracing::debug!("running tests with `--nocapture`, will not capture.");
false
}
Cmd::Test { .. } => true,
Cmd::Run { serial: true, .. } => {
tracing::debug!("running normally with `--serial`, will not capture");
false
Expand Down Expand Up @@ -184,6 +179,7 @@ impl Cmd {
}

Cmd::Test {
nocapture,
qemu_settings,
timeout_secs,
..
Expand All @@ -208,11 +204,11 @@ impl Cmd {
tracing::info!(qemu.test_args = ?TEST_ARGS, "using test mode qemu args");
qemu.args(TEST_ARGS);

let nocapture = *nocapture;
let mut child = self.spawn_qemu(&mut qemu, paths.kernel_bin())?;
let stdout = child
.stdout
.take()
.map(|stdout| std::thread::spawn(move || TestResults::watch_tests(stdout)));
let stdout = child.stdout.take().map(|stdout| {
std::thread::spawn(move || TestResults::watch_tests(stdout, nocapture))
});

let res = match child
.wait_timeout(*timeout_secs)
Expand Down Expand Up @@ -298,7 +294,7 @@ fn parse_secs(s: &str) -> Result<Duration> {
}

impl TestResults {
fn watch_tests(output: impl std::io::Read) -> Result<Self> {
fn watch_tests(output: impl std::io::Read, nocapture: bool) -> Result<Self> {
use std::io::{BufRead, BufReader};
let mut results = Self {
tests: 0,
Expand Down Expand Up @@ -363,8 +359,11 @@ impl TestResults {
.note(format!("line: {line:?}"));
}
}

curr_output.push(line);
if nocapture {
println!("{line}")
} else {
curr_output.push(line);
}
}

match curr_outcome {
Expand All @@ -385,7 +384,9 @@ impl TestResults {
}
None => {
tracing::info!("qemu exited unexpectedly! wtf!");
curr_output.push("<AND THEN QEMU EXITS???>".to_string());
if !nocapture {
curr_output.push("<AND THEN QEMU EXITS???>".to_string());
}
eprintln!(" {}", "exit!".style(red));
results.failed.insert(test.to_static(), curr_output);
break;
Expand Down

0 comments on commit 29d1179

Please sign in to comment.