2014-02-05 23:19:40 +00:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-06-26 02:41:16 +00:00
|
|
|
// no-pretty-expanded FIXME #15189
|
2014-08-11 23:24:19 +00:00
|
|
|
// ignore-windows FIXME #13259
|
2014-02-05 23:19:40 +00:00
|
|
|
use std::os;
|
2014-05-05 21:33:55 +00:00
|
|
|
use std::io::process::Command;
|
2014-05-21 05:27:24 +00:00
|
|
|
use std::finally::Finally;
|
2014-02-05 23:19:40 +00:00
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[inline(never)]
|
|
|
|
fn foo() {
|
2014-07-31 15:13:25 +00:00
|
|
|
let _v = vec![1i, 2, 3];
|
|
|
|
if os::getenv("IS_TEST").is_some() {
|
2014-10-09 19:17:22 +00:00
|
|
|
panic!()
|
2014-07-31 15:13:25 +00:00
|
|
|
}
|
2014-02-05 23:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(never)]
|
|
|
|
fn double() {
|
|
|
|
(|| {
|
2014-10-09 19:17:22 +00:00
|
|
|
panic!("once");
|
2014-02-05 23:19:40 +00:00
|
|
|
}).finally(|| {
|
2014-10-09 19:17:22 +00:00
|
|
|
panic!("twice");
|
2014-02-05 23:19:40 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn runtest(me: &str) {
|
2014-07-31 15:13:25 +00:00
|
|
|
let mut template = Command::new(me);
|
|
|
|
template.env("IS_TEST", "1");
|
|
|
|
|
2014-02-05 23:19:40 +00:00
|
|
|
// Make sure that the stack trace is printed
|
2014-07-31 15:13:25 +00:00
|
|
|
let p = template.clone().arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
|
2014-05-05 23:58:42 +00:00
|
|
|
let out = p.wait_with_output().unwrap();
|
2014-02-05 23:19:40 +00:00
|
|
|
assert!(!out.status.success());
|
2014-03-26 16:24:16 +00:00
|
|
|
let s = str::from_utf8(out.error.as_slice()).unwrap();
|
2014-02-05 23:19:40 +00:00
|
|
|
assert!(s.contains("stack backtrace") && s.contains("foo::h"),
|
|
|
|
"bad output: {}", s);
|
|
|
|
|
|
|
|
// Make sure the stack trace is *not* printed
|
2014-07-31 15:13:25 +00:00
|
|
|
let p = template.clone().arg("fail").spawn().unwrap();
|
2014-05-05 23:58:42 +00:00
|
|
|
let out = p.wait_with_output().unwrap();
|
2014-02-05 23:19:40 +00:00
|
|
|
assert!(!out.status.success());
|
2014-03-26 16:24:16 +00:00
|
|
|
let s = str::from_utf8(out.error.as_slice()).unwrap();
|
2014-02-05 23:19:40 +00:00
|
|
|
assert!(!s.contains("stack backtrace") && !s.contains("foo::h"),
|
|
|
|
"bad output2: {}", s);
|
|
|
|
|
|
|
|
// Make sure a stack trace is printed
|
2014-07-31 15:13:25 +00:00
|
|
|
let p = template.clone().arg("double-fail").spawn().unwrap();
|
2014-05-05 23:58:42 +00:00
|
|
|
let out = p.wait_with_output().unwrap();
|
2014-02-05 23:19:40 +00:00
|
|
|
assert!(!out.status.success());
|
2014-03-26 16:24:16 +00:00
|
|
|
let s = str::from_utf8(out.error.as_slice()).unwrap();
|
2014-11-19 05:15:13 +00:00
|
|
|
// loosened the following from double::h to double:: due to
|
|
|
|
// spurious failures on mac, 32bit, optimized
|
|
|
|
assert!(s.contains("stack backtrace") && s.contains("double::"),
|
2014-02-05 23:19:40 +00:00
|
|
|
"bad output3: {}", s);
|
|
|
|
|
|
|
|
// Make sure a stack trace isn't printed too many times
|
2014-07-31 15:13:25 +00:00
|
|
|
let p = template.clone().arg("double-fail")
|
2014-07-02 20:50:45 +00:00
|
|
|
.env("RUST_BACKTRACE", "1").spawn().unwrap();
|
2014-05-05 23:58:42 +00:00
|
|
|
let out = p.wait_with_output().unwrap();
|
2014-02-05 23:19:40 +00:00
|
|
|
assert!(!out.status.success());
|
2014-03-26 16:24:16 +00:00
|
|
|
let s = str::from_utf8(out.error.as_slice()).unwrap();
|
2014-02-05 23:19:40 +00:00
|
|
|
let mut i = 0;
|
2014-04-21 21:58:52 +00:00
|
|
|
for _ in range(0i, 2) {
|
2014-02-05 23:19:40 +00:00
|
|
|
i += s.slice_from(i + 10).find_str("stack backtrace").unwrap() + 10;
|
|
|
|
}
|
|
|
|
assert!(s.slice_from(i + 10).find_str("stack backtrace").is_none(),
|
|
|
|
"bad output4: {}", s);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = os::args();
|
2014-05-04 20:20:47 +00:00
|
|
|
let args = args.as_slice();
|
2014-02-05 23:19:40 +00:00
|
|
|
if args.len() >= 2 && args[1].as_slice() == "fail" {
|
|
|
|
foo();
|
|
|
|
} else if args.len() >= 2 && args[1].as_slice() == "double-fail" {
|
|
|
|
double();
|
|
|
|
} else {
|
2014-05-16 17:45:16 +00:00
|
|
|
runtest(args[0].as_slice());
|
2014-02-05 23:19:40 +00:00
|
|
|
}
|
|
|
|
}
|