rust/tests/ui/threads-sendsync/task-stderr.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
623 B
Rust
Raw Normal View History

// run-pass
// ignore-emscripten no threads support
// needs-unwind
#![feature(internal_output_capture)]
2015-03-11 17:24:14 -05:00
use std::io;
use std::str;
use std::sync::{Arc, Mutex};
2014-12-06 20:34:37 -06:00
use std::thread;
2015-03-11 17:24:14 -05:00
fn main() {
let data = Arc::new(Mutex::new(Vec::new()));
2020-11-03 13:49:02 -06:00
let res = thread::Builder::new().spawn({
let data = data.clone();
move || {
io::set_output_capture(Some(data));
2020-11-03 13:49:02 -06:00
panic!("Hello, world!")
}
2015-02-17 17:24:34 -06:00
}).unwrap().join();
assert!(res.is_err());
2015-03-11 17:24:14 -05:00
let output = data.lock().unwrap();
let output = str::from_utf8(&output).unwrap();
assert!(output.contains("Hello, world!"));
}