]> git.lizzy.rs Git - rust.git/blob - src/test/ui/multi-panic.rs
Rollup merge of #82259 - osa1:issue82156, r=petrochenkov
[rust.git] / src / test / ui / multi-panic.rs
1 // run-pass
2 // ignore-emscripten no processes
3 // ignore-sgx no processes
4
5 fn check_for_no_backtrace(test: std::process::Output) {
6     assert!(!test.status.success());
7     let err = String::from_utf8_lossy(&test.stderr);
8     let mut it = err.lines();
9
10     assert_eq!(it.next().map(|l| l.starts_with("thread '<unnamed>' panicked at")), Some(true));
11     assert_eq!(it.next(), Some("note: run with `RUST_BACKTRACE=1` \
12                                 environment variable to display a backtrace"));
13     assert_eq!(it.next().map(|l| l.starts_with("thread 'main' panicked at")), Some(true));
14     assert_eq!(it.next(), None);
15 }
16
17 fn main() {
18     let args: Vec<String> = std::env::args().collect();
19     if args.len() > 1 && args[1] == "run_test" {
20         let _ = std::thread::spawn(|| {
21             panic!();
22         }).join();
23
24         panic!();
25     } else {
26         let test = std::process::Command::new(&args[0]).arg("run_test")
27                                                        .env_remove("RUST_BACKTRACE")
28                                                        .output()
29                                                        .unwrap();
30         check_for_no_backtrace(test);
31         let test = std::process::Command::new(&args[0]).arg("run_test")
32                                                        .env("RUST_BACKTRACE","0")
33                                                        .output()
34                                                        .unwrap();
35         check_for_no_backtrace(test);
36     }
37 }