Skip to content

Commit

Permalink
RUST-1749 Update log_uncaptured to bypass cargo nextest (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
abr-egn authored Oct 13, 2023
1 parent cb57ada commit 11a23ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion .evergreen/cargo-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ cargo_test_options() {
}

cargo_test() {
RUST_BACKTRACE=1 cargo nextest run --profile ci $(cargo_test_options $1)
LOG_PATH=$(mktemp)
tail -f ${LOG_PATH} &
TAIL_PID=$!
LOG_UNCAPTURED=${LOG_PATH} RUST_BACKTRACE=1 cargo nextest run --profile ci $(cargo_test_options $1)
((CARGO_RESULT = ${CARGO_RESULT} || $?))
mv target/nextest/ci/junit.xml $2
kill ${TAIL_PID}
rm ${LOG_PATH}
}
20 changes: 18 additions & 2 deletions src/test/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,24 @@ pub(crate) fn log_uncaptured<S: AsRef<str>>(text: S) {
use std::io::Write;

let mut stderr = std::io::stderr();
stderr.write_all(text.as_ref().as_bytes()).unwrap();
stderr.write_all(b"\n").unwrap();
let mut sinks = vec![&mut stderr as &mut dyn Write];
let mut other;
let other_path = std::env::var("LOG_UNCAPTURED").unwrap_or("/dev/tty".to_string());
if let Ok(f) = std::fs::OpenOptions::new().append(true).open(&other_path) {
other = f;
sinks.push(&mut other);
}

for sink in sinks {
sink.write_all(text.as_ref().as_bytes()).unwrap();
sink.write_all(b"\n").unwrap();
}
}

#[test]
fn log_uncaptured_example() {
println!("this is captured");
log_uncaptured("this is not captured");
}

pub(crate) fn file_level_log(message: impl AsRef<str>) {
Expand Down

0 comments on commit 11a23ba

Please sign in to comment.