]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/multi-panic.rs
Update panic message to be clearer about env-vars
[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 // ignore-cloudabi no processes
12 // ignore-emscripten no processes
13
14 fn check_for_no_backtrace(test: std::process::Output) {
15     assert!(!test.status.success());
16     let err = String::from_utf8_lossy(&test.stderr);
17     let mut it = err.lines();
18
19     assert_eq!(it.next().map(|l| l.starts_with("thread '<unnamed>' panicked at")), Some(true));
20     assert_eq!(it.next(), Some("note: Run with `RUST_BACKTRACE=1` \
21                                 environment variable to display a backtrace."));
22     assert_eq!(it.next().map(|l| l.starts_with("thread 'main' panicked at")), Some(true));
23     assert_eq!(it.next(), None);
24 }
25
26 fn main() {
27     let args: Vec<String> = std::env::args().collect();
28     if args.len() > 1 && args[1] == "run_test" {
29         let _ = std::thread::spawn(|| {
30             panic!();
31         }).join();
32
33         panic!();
34     } else {
35         let test = std::process::Command::new(&args[0]).arg("run_test")
36                                                        .env_remove("RUST_BACKTRACE")
37                                                        .output()
38                                                        .unwrap();
39         check_for_no_backtrace(test);
40         let test = std::process::Command::new(&args[0]).arg("run_test")
41                                                        .env("RUST_BACKTRACE","0")
42                                                        .output()
43                                                        .unwrap();
44         check_for_no_backtrace(test);
45     }
46 }