2014-06-17 16:48:54 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-04-20 21:01:20 -05:00
|
|
|
#![feature(box_syntax, set_stdio)]
|
2015-01-07 19:25:56 -06:00
|
|
|
|
2015-03-11 17:24:14 -05:00
|
|
|
use std::io::prelude::*;
|
|
|
|
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
|
|
|
struct Sink(Arc<Mutex<Vec<u8>>>);
|
|
|
|
impl Write for Sink {
|
|
|
|
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
|
|
|
Write::write(&mut *self.0.lock().unwrap(), data)
|
|
|
|
}
|
|
|
|
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
|
|
|
}
|
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()));
|
|
|
|
let sink = Sink(data.clone());
|
|
|
|
let res = thread::Builder::new().spawn(move|| -> () {
|
|
|
|
io::set_panic(Box::new(sink));
|
2014-10-09 14:17:22 -05: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
|
|
|
}
|