]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/multi-panic.rs
don't leak RUST_BACKTRACE into test process
[rust.git] / src / test / run-pass / multi-panic.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 fn main() {
12     let args: Vec<String> = std::env::args().collect();
13     if args.len() > 1 && args[1] == "run_test" {
14         let _ = std::thread::spawn(|| {
15             panic!();
16         }).join();
17
18         panic!();
19     } else {
20         let test = std::process::Command::new(&args[0]).arg("run_test")
21                                                        .env_remove("RUST_BACKTRACE")
22                                                        .output()
23                                                        .unwrap();
24         assert!(!test.status.success());
25         let err = String::from_utf8_lossy(&test.stderr);
26         let mut it = err.lines();
27
28         assert_eq!(it.next().map(|l| l.starts_with("thread '<unnamed>' panicked at")), Some(true));
29         assert_eq!(it.next(), Some("note: Run with `RUST_BACKTRACE=1` for a backtrace."));
30         assert_eq!(it.next().map(|l| l.starts_with("thread '<main>' panicked at")), Some(true));
31         assert_eq!(it.next(), None);
32     }
33 }