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 // ignore-win32 FIXME #13259
17 use std::io::process::{Process, ProcessConfig};
18 use std::unstable::finally::Finally;
22 fn start(argc: int, argv: **u8) -> int { native::start(argc, argv, main) }
38 fn runtest(me: &str) {
39 let mut env = os::env().move_iter().collect::<Vec<(~str, ~str)>>();
40 match env.iter().position(|&(ref s, _)| "RUST_BACKTRACE" == *s) {
41 Some(i) => { env.remove(i); }
44 env.push(("RUST_BACKTRACE".to_owned(), "1".to_owned()));
46 // Make sure that the stack trace is printed
47 let mut p = Process::configure(ProcessConfig {
49 args: ["fail".to_owned()],
50 env: Some(env.as_slice()),
51 .. ProcessConfig::new()
53 let out = p.wait_with_output();
54 assert!(!out.status.success());
55 let s = str::from_utf8(out.error.as_slice()).unwrap();
56 assert!(s.contains("stack backtrace") && s.contains("foo::h"),
59 // Make sure the stack trace is *not* printed
60 let mut p = Process::configure(ProcessConfig {
62 args: ["fail".to_owned()],
63 .. ProcessConfig::new()
65 let out = p.wait_with_output();
66 assert!(!out.status.success());
67 let s = str::from_utf8(out.error.as_slice()).unwrap();
68 assert!(!s.contains("stack backtrace") && !s.contains("foo::h"),
69 "bad output2: {}", s);
71 // Make sure a stack trace is printed
72 let mut p = Process::configure(ProcessConfig {
74 args: ["double-fail".to_owned()],
75 .. ProcessConfig::new()
77 let out = p.wait_with_output();
78 assert!(!out.status.success());
79 let s = str::from_utf8(out.error.as_slice()).unwrap();
80 assert!(s.contains("stack backtrace") && s.contains("double::h"),
81 "bad output3: {}", s);
83 // Make sure a stack trace isn't printed too many times
84 let mut p = Process::configure(ProcessConfig {
86 args: ["double-fail".to_owned()],
87 env: Some(env.as_slice()),
88 .. ProcessConfig::new()
90 let out = p.wait_with_output();
91 assert!(!out.status.success());
92 let s = str::from_utf8(out.error.as_slice()).unwrap();
94 for _ in range(0, 2) {
95 i += s.slice_from(i + 10).find_str("stack backtrace").unwrap() + 10;
97 assert!(s.slice_from(i + 10).find_str("stack backtrace").is_none(),
98 "bad output4: {}", s);
102 let args = os::args();
103 if args.len() >= 2 && args[1].as_slice() == "fail" {
105 } else if args.len() >= 2 && args[1].as_slice() == "double-fail" {