]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/signal-exit-status.rs
auto merge of #13600 : brandonw/rust/master, r=brson
[rust.git] / src / test / run-pass / signal-exit-status.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.
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 // copyright 2013-2014 the rust project developers. see the copyright
12 // file at the top-level directory of this distribution and at
13 // http://rust-lang.org/copyright.
14 //
15 // licensed under the apache license, version 2.0 <license-apache or
16 // http://www.apache.org/licenses/license-2.0> or the mit license
17 // <license-mit or http://opensource.org/licenses/mit>, at your
18 // option. this file may not be copied, modified, or distributed
19 // except according to those terms.
20
21 // ignore-win32
22
23 use std::os;
24 use std::io::process::{Process, ExitSignal, ExitStatus};
25
26 pub fn main() {
27     let args = os::args();
28     if args.len() >= 2 && args[1] == ~"signal" {
29         // Raise a segfault.
30         unsafe { *(0 as *mut int) = 0; }
31     } else {
32         let status = Process::status(args[0], [~"signal"]).unwrap();
33         // Windows does not have signal, so we get exit status 0xC0000028 (STATUS_BAD_STACK).
34         match status {
35             ExitSignal(_) if cfg!(unix) => {},
36             ExitStatus(0xC0000028) if cfg!(windows) => {},
37             _ => fail!("invalid termination (was not signalled): {:?}", status)
38         }
39     }
40 }
41