Skip to content

Commit 11a23ba

Browse files
authored
RUST-1749 Update log_uncaptured to bypass cargo nextest (#975)
1 parent cb57ada commit 11a23ba

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

.evergreen/cargo-test.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ cargo_test_options() {
2424
}
2525

2626
cargo_test() {
27-
RUST_BACKTRACE=1 cargo nextest run --profile ci $(cargo_test_options $1)
27+
LOG_PATH=$(mktemp)
28+
tail -f ${LOG_PATH} &
29+
TAIL_PID=$!
30+
LOG_UNCAPTURED=${LOG_PATH} RUST_BACKTRACE=1 cargo nextest run --profile ci $(cargo_test_options $1)
2831
((CARGO_RESULT = ${CARGO_RESULT} || $?))
2932
mv target/nextest/ci/junit.xml $2
33+
kill ${TAIL_PID}
34+
rm ${LOG_PATH}
3035
}

src/test/util.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,24 @@ pub(crate) fn log_uncaptured<S: AsRef<str>>(text: S) {
525525
use std::io::Write;
526526

527527
let mut stderr = std::io::stderr();
528-
stderr.write_all(text.as_ref().as_bytes()).unwrap();
529-
stderr.write_all(b"\n").unwrap();
528+
let mut sinks = vec![&mut stderr as &mut dyn Write];
529+
let mut other;
530+
let other_path = std::env::var("LOG_UNCAPTURED").unwrap_or("/dev/tty".to_string());
531+
if let Ok(f) = std::fs::OpenOptions::new().append(true).open(&other_path) {
532+
other = f;
533+
sinks.push(&mut other);
534+
}
535+
536+
for sink in sinks {
537+
sink.write_all(text.as_ref().as_bytes()).unwrap();
538+
sink.write_all(b"\n").unwrap();
539+
}
540+
}
541+
542+
#[test]
543+
fn log_uncaptured_example() {
544+
println!("this is captured");
545+
log_uncaptured("this is not captured");
530546
}
531547

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

0 commit comments

Comments
 (0)