2014-02-19 23:01:50 -06:00
|
|
|
// Copyright 2012-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-04-03 19:55:06 -05:00
|
|
|
#![feature(asm)]
|
2014-02-19 23:01:50 -06:00
|
|
|
|
2014-05-05 16:33:55 -05:00
|
|
|
use std::io::process::Command;
|
2014-02-19 23:01:50 -06:00
|
|
|
use std::os;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
// lifted from the test module
|
2014-04-02 00:07:37 -05:00
|
|
|
// Inlining to avoid llvm turning the recursive functions into tail calls,
|
|
|
|
// which doesn't consume stack.
|
|
|
|
#[inline(always)]
|
2014-02-19 23:01:50 -06:00
|
|
|
pub fn black_box<T>(dummy: T) { unsafe { asm!("" : : "r"(&dummy)) } }
|
|
|
|
|
|
|
|
fn silent_recurse() {
|
|
|
|
let buf = [0, ..1000];
|
|
|
|
black_box(buf);
|
|
|
|
silent_recurse();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn loud_recurse() {
|
|
|
|
println!("hello!");
|
|
|
|
loud_recurse();
|
2014-03-27 06:54:41 -05:00
|
|
|
black_box(()); // don't optimize this into a tail call. please.
|
2014-02-19 23:01:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = os::args();
|
2014-05-04 15:20:47 -05:00
|
|
|
let args = args.as_slice();
|
2014-02-19 23:01:50 -06:00
|
|
|
if args.len() > 1 && args[1].as_slice() == "silent" {
|
|
|
|
silent_recurse();
|
|
|
|
} else if args.len() > 1 && args[1].as_slice() == "loud" {
|
|
|
|
loud_recurse();
|
|
|
|
} else {
|
2014-05-05 16:33:55 -05:00
|
|
|
let silent = Command::new(args[0].as_slice()).arg("silent").output().unwrap();
|
2014-02-19 23:01:50 -06:00
|
|
|
assert!(!silent.status.success());
|
2014-03-26 11:24:16 -05:00
|
|
|
let error = str::from_utf8_lossy(silent.error.as_slice());
|
2014-02-19 23:01:50 -06:00
|
|
|
assert!(error.as_slice().contains("has overflowed its stack"));
|
|
|
|
|
2014-05-05 16:33:55 -05:00
|
|
|
let loud = Command::new(args[0].as_slice()).arg("loud").output().unwrap();
|
2014-02-19 23:01:50 -06:00
|
|
|
assert!(!loud.status.success());
|
2014-03-26 11:24:16 -05:00
|
|
|
let error = str::from_utf8_lossy(silent.error.as_slice());
|
2014-02-19 23:01:50 -06:00
|
|
|
assert!(error.as_slice().contains("has overflowed its stack"));
|
|
|
|
}
|
|
|
|
}
|