1 // Copyright 2014 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.
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.
11 #![feature(rustc_attrs)]
13 // no-pretty-expanded FIXME #15189
14 // ignore-android FIXME #17520
18 use std::process::{Command, Stdio};
21 // FIXME #31005 MIR missing debuginfo currently.
22 #[cfg_attr(target_env = "msvc", rustc_no_mir)]
25 let _v = vec![1, 2, 3];
26 if env::var_os("IS_TEST").is_some() {
31 // FIXME #31005 MIR missing debuginfo currently.
32 #[cfg_attr(target_env = "msvc", rustc_no_mir)]
37 impl Drop for Double {
38 fn drop(&mut self) { panic!("twice") }
46 fn template(me: &str) -> Command {
47 let mut m = Command::new(me);
49 .stdout(Stdio::piped())
50 .stderr(Stdio::piped());
54 fn runtest(me: &str) {
55 // Make sure that the stack trace is printed
56 let p = template(me).arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
57 let out = p.wait_with_output().unwrap();
58 assert!(!out.status.success());
59 let s = str::from_utf8(&out.stderr).unwrap();
60 assert!(s.contains("stack backtrace") && s.contains(" - backtrace::foo"),
63 // Make sure the stack trace is *not* printed
64 // (Remove RUST_BACKTRACE from our own environment, in case developer
65 // is running `make check` with it on.)
66 let p = template(me).arg("fail").env_remove("RUST_BACKTRACE").spawn().unwrap();
67 let out = p.wait_with_output().unwrap();
68 assert!(!out.status.success());
69 let s = str::from_utf8(&out.stderr).unwrap();
70 assert!(!s.contains("stack backtrace") && !s.contains(" - backtrace::foo"),
71 "bad output2: {}", s);
73 // Make sure a stack trace is printed
74 let p = template(me).arg("double-fail").spawn().unwrap();
75 let out = p.wait_with_output().unwrap();
76 assert!(!out.status.success());
77 let s = str::from_utf8(&out.stderr).unwrap();
78 // loosened the following from double::h to double:: due to
79 // spurious failures on mac, 32bit, optimized
80 assert!(s.contains("stack backtrace") && s.contains(" - backtrace::double"),
81 "bad output3: {}", s);
83 // Make sure a stack trace isn't printed too many times
84 let p = template(me).arg("double-fail")
85 .env("RUST_BACKTRACE", "1").spawn().unwrap();
86 let out = p.wait_with_output().unwrap();
87 assert!(!out.status.success());
88 let s = str::from_utf8(&out.stderr).unwrap();
91 i += s[i + 10..].find("stack backtrace").unwrap() + 10;
93 assert!(s[i + 10..].find("stack backtrace").is_none(),
94 "bad output4: {}", s);
98 if cfg!(windows) && cfg!(target_arch = "x86") && cfg!(target_env = "gnu") {
102 let args: Vec<String> = env::args().collect();
103 if args.len() >= 2 && args[1] == "fail" {
105 } else if args.len() >= 2 && args[1] == "double-fail" {