diff options
| author | bors <bors@rust-lang.org> | 2020-10-27 11:43:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-10-27 11:43:18 +0000 |
| commit | 56d288fa46e04cd5faf53d369a1a640a97e2bb08 (patch) | |
| tree | c2f7e816a443a91a45a9038ce7ecc46ede60f97c /src | |
| parent | 20b1e05a8d0e1773dc840a3286aa37916e87d84b (diff) | |
| parent | 7c4fe002131f1160f2054885ab40c74464951a64 (diff) | |
| download | rust-56d288fa46e04cd5faf53d369a1a640a97e2bb08.tar.gz rust-56d288fa46e04cd5faf53d369a1a640a97e2bb08.zip | |
Auto merge of #78227 - SergioBenitez:test-stdout-threading, r=m-ou-se
Capture output from threads spawned in tests This is revival of #75172. Original text: > Fixes #42474. > > r? `@​dtolnay` since you expressed interest in this, but feel free to redirect if you aren't the right person anymore. --- Closes #75172.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/panic-while-printing.rs | 19 | ||||
| -rw-r--r-- | src/test/ui/test-thread-capture.rs | 31 | ||||
| -rw-r--r-- | src/test/ui/test-thread-capture.run.stdout | 21 | ||||
| -rw-r--r-- | src/test/ui/test-thread-nocapture.rs | 31 | ||||
| -rw-r--r-- | src/test/ui/test-thread-nocapture.run.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/test-thread-nocapture.run.stdout | 20 | ||||
| -rw-r--r-- | src/test/ui/threads-sendsync/task-stderr.rs | 5 |
7 files changed, 127 insertions, 2 deletions
diff --git a/src/test/ui/panic-while-printing.rs b/src/test/ui/panic-while-printing.rs index 7e9fa16b084..21fc12759f8 100644 --- a/src/test/ui/panic-while-printing.rs +++ b/src/test/ui/panic-while-printing.rs @@ -5,7 +5,7 @@ use std::fmt; use std::fmt::{Display, Formatter}; -use std::io::set_panic; +use std::io::{self, set_panic, LocalOutput, Write}; pub struct A; @@ -15,8 +15,23 @@ impl Display for A { } } +struct Sink; +impl Write for Sink { + fn write(&mut self, buf: &[u8]) -> io::Result<usize> { + Ok(buf.len()) + } + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} +impl LocalOutput for Sink { + fn clone_box(&self) -> Box<dyn LocalOutput> { + Box::new(Sink) + } +} + fn main() { - set_panic(Some(Box::new(Vec::new()))); + set_panic(Some(Box::new(Sink))); assert!(std::panic::catch_unwind(|| { eprintln!("{}", A); }) diff --git a/src/test/ui/test-thread-capture.rs b/src/test/ui/test-thread-capture.rs new file mode 100644 index 00000000000..6bec48cd816 --- /dev/null +++ b/src/test/ui/test-thread-capture.rs @@ -0,0 +1,31 @@ +// compile-flags: --test +// run-fail +// run-flags: --test-threads=1 +// check-run-results +// exec-env:RUST_BACKTRACE=0 +// ignore-emscripten no threads support + +#[test] +fn thready_pass() { + println!("fee"); + std::thread::spawn(|| { + println!("fie"); + println!("foe"); + }) + .join() + .unwrap(); + println!("fum"); +} + +#[test] +fn thready_fail() { + println!("fee"); + std::thread::spawn(|| { + println!("fie"); + println!("foe"); + }) + .join() + .unwrap(); + println!("fum"); + panic!(); +} diff --git a/src/test/ui/test-thread-capture.run.stdout b/src/test/ui/test-thread-capture.run.stdout new file mode 100644 index 00000000000..1102aadab02 --- /dev/null +++ b/src/test/ui/test-thread-capture.run.stdout @@ -0,0 +1,21 @@ + +running 2 tests +test thready_fail ... FAILED +test thready_pass ... ok + +failures: + +---- thready_fail stdout ---- +fee +fie +foe +fum +thread 'main' panicked at 'explicit panic', $DIR/test-thread-capture.rs:30:5 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace + + +failures: + thready_fail + +test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out + diff --git a/src/test/ui/test-thread-nocapture.rs b/src/test/ui/test-thread-nocapture.rs new file mode 100644 index 00000000000..82df6e77cb1 --- /dev/null +++ b/src/test/ui/test-thread-nocapture.rs @@ -0,0 +1,31 @@ +// compile-flags: --test +// run-fail +// run-flags: --test-threads=1 --nocapture +// check-run-results +// exec-env:RUST_BACKTRACE=0 +// ignore-emscripten no threads support + +#[test] +fn thready_pass() { + println!("fee"); + std::thread::spawn(|| { + println!("fie"); + println!("foe"); + }) + .join() + .unwrap(); + println!("fum"); +} + +#[test] +fn thready_fail() { + println!("fee"); + std::thread::spawn(|| { + println!("fie"); + println!("foe"); + }) + .join() + .unwrap(); + println!("fum"); + panic!(); +} diff --git a/src/test/ui/test-thread-nocapture.run.stderr b/src/test/ui/test-thread-nocapture.run.stderr new file mode 100644 index 00000000000..98bd96d0abe --- /dev/null +++ b/src/test/ui/test-thread-nocapture.run.stderr @@ -0,0 +1,2 @@ +thread 'main' panicked at 'explicit panic', $DIR/test-thread-nocapture.rs:30:5 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/src/test/ui/test-thread-nocapture.run.stdout b/src/test/ui/test-thread-nocapture.run.stdout new file mode 100644 index 00000000000..77b42ed88d6 --- /dev/null +++ b/src/test/ui/test-thread-nocapture.run.stdout @@ -0,0 +1,20 @@ + +running 2 tests +test thready_fail ... fee +fie +foe +fum +FAILED +test thready_pass ... fee +fie +foe +fum +ok + +failures: + +failures: + thready_fail + +test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out + diff --git a/src/test/ui/threads-sendsync/task-stderr.rs b/src/test/ui/threads-sendsync/task-stderr.rs index d474084bf20..bc4bedac196 100644 --- a/src/test/ui/threads-sendsync/task-stderr.rs +++ b/src/test/ui/threads-sendsync/task-stderr.rs @@ -16,6 +16,11 @@ impl Write for Sink { } fn flush(&mut self) -> io::Result<()> { Ok(()) } } +impl io::LocalOutput for Sink { + fn clone_box(&self) -> Box<dyn io::LocalOutput> { + Box::new(Sink(self.0.clone())) + } +} fn main() { let data = Arc::new(Mutex::new(Vec::new())); |
