]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/out-of-stack.rs
Replace all ~"" with "".to_owned()
[rust.git] / src / test / run-pass / out-of-stack.rs
1 // Copyright 2012-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.
4 //
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.
10
11 #![feature(asm)]
12
13 use std::io::Process;
14 use std::os;
15 use std::str;
16
17 // lifted from the test module
18 // Inlining to avoid llvm turning the recursive functions into tail calls,
19 // which doesn't consume stack.
20 #[inline(always)]
21 pub fn black_box<T>(dummy: T) { unsafe { asm!("" : : "r"(&dummy)) } }
22
23 fn silent_recurse() {
24     let buf = [0, ..1000];
25     black_box(buf);
26     silent_recurse();
27 }
28
29 fn loud_recurse() {
30     println!("hello!");
31     loud_recurse();
32     black_box(()); // don't optimize this into a tail call. please.
33 }
34
35 fn main() {
36     let args = os::args();
37     if args.len() > 1 && args[1].as_slice() == "silent" {
38         silent_recurse();
39     } else if args.len() > 1 && args[1].as_slice() == "loud" {
40         loud_recurse();
41     } else {
42         let silent = Process::output(args[0], ["silent".to_owned()]).unwrap();
43         assert!(!silent.status.success());
44         let error = str::from_utf8_lossy(silent.error.as_slice());
45         assert!(error.as_slice().contains("has overflowed its stack"));
46
47         let loud = Process::output(args[0], ["loud".to_owned()]).unwrap();
48         assert!(!loud.status.success());
49         let error = str::from_utf8_lossy(silent.error.as_slice());
50         assert!(error.as_slice().contains("has overflowed its stack"));
51     }
52 }