2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2016-02-11 05:34:41 -06:00
|
|
|
// ignore-emscripten no threads support
|
2021-12-03 09:32:51 -06:00
|
|
|
// needs-unwind
|
2016-02-11 05:34:41 -06:00
|
|
|
|
2020-11-03 17:11:14 -06:00
|
|
|
#![feature(internal_output_capture)]
|
2015-01-07 19:25:56 -06:00
|
|
|
|
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;
|
2014-06-17 16:48:54 -05:00
|
|
|
|
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 || {
|
2020-11-03 17:11:14 -06:00
|
|
|
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();
|
2014-06-17 16:48:54 -05:00
|
|
|
assert!(res.is_err());
|
|
|
|
|
2015-03-11 17:24:14 -05:00
|
|
|
let output = data.lock().unwrap();
|
|
|
|
let output = str::from_utf8(&output).unwrap();
|
2015-01-26 20:21:15 -06:00
|
|
|
assert!(output.contains("Hello, world!"));
|
2014-06-17 16:48:54 -05:00
|
|
|
}
|