]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/backtrace.rs
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 expected(fn_name
: &str) -> String
{
57 // On windows, we read the function name from debuginfo using some
58 // system APIs. For whatever reason, these APIs seem to use the
59 // "name" field, which is only the "relative" name, not the full
60 // name with namespace info, so we just see `foo` and not
61 // `backtrace::foo` as we see on linux (which uses the linkage
63 if cfg
!(windows
) && cfg
!(target_env
= "msvc") {
64 format
!(" - {}", fn_name
)
66 format
!(" - backtrace::{}", fn_name
)
70 fn runtest(me
: &str) {
71 // Make sure that the stack trace is printed
72 let p
= template(me
).arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
73 let out
= p
.wait_with_output().unwrap();
74 assert
!(!out
.status
.success());
75 let s
= str::from_utf8(&out
.stderr
).unwrap();
76 assert
!(s
.contains("stack backtrace") && s
.contains(&expected("foo")),
79 // Make sure the stack trace is *not* printed
80 // (Remove RUST_BACKTRACE from our own environment, in case developer
81 // is running `make check` with it on.)
82 let p
= template(me
).arg("fail").env_remove("RUST_BACKTRACE").spawn().unwrap();
83 let out
= p
.wait_with_output().unwrap();
84 assert
!(!out
.status
.success());
85 let s
= str::from_utf8(&out
.stderr
).unwrap();
86 assert
!(!s
.contains("stack backtrace") && !s
.contains(&expected("foo")),
87 "bad output2: {}", s
);
89 // Make sure the stack trace is *not* printed
90 // (RUST_BACKTRACE=0 acts as if it were unset from our own environment,
91 // in case developer is running `make check` with it set.)
92 let p
= template(me
).arg("fail").env("RUST_BACKTRACE","0").spawn().unwrap();
93 let out
= p
.wait_with_output().unwrap();
94 assert
!(!out
.status
.success());
95 let s
= str::from_utf8(&out
.stderr
).unwrap();
96 assert
!(!s
.contains("stack backtrace") && !s
.contains(" - foo"),
97 "bad output3: {}", s
);
99 // Make sure a stack trace is printed
100 let p
= template(me
).arg("double-fail").spawn().unwrap();
101 let out
= p
.wait_with_output().unwrap();
102 assert
!(!out
.status
.success());
103 let s
= str::from_utf8(&out
.stderr
).unwrap();
104 // loosened the following from double::h to double:: due to
105 // spurious failures on mac, 32bit, optimized
106 assert
!(s
.contains("stack backtrace") && s
.contains(&expected("double")),
107 "bad output3: {}", s
);
109 // Make sure a stack trace isn't printed too many times
110 let p
= template(me
).arg("double-fail")
111 .env("RUST_BACKTRACE", "1").spawn().unwrap();
112 let out
= p
.wait_with_output().unwrap();
113 assert
!(!out
.status
.success());
114 let s
= str::from_utf8(&out
.stderr
).unwrap();
117 i
+= s
[i
+ 10..].find("stack backtrace").unwrap() + 10;
119 assert
!(s
[i
+ 10..].find("stack backtrace").is_none(),
120 "bad output4: {}", s
);
124 if cfg
!(windows
) && cfg
!(target_env
= "gnu") {
128 let args
: Vec
<String
> = env
::args().collect();
129 if args
.len() >= 2 && args
[1] == "fail" {
131 } else if args
.len() >= 2 && args
[1] == "double-fail" {