]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/signal-exit-status.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[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 // ignore-windows
12
13 use std::os;
14 use std::io::process::{Command, ExitSignal, ExitStatus};
15
16 pub fn main() {
17     let args = os::args();
18     let args = args.as_slice();
19     if args.len() >= 2 && args[1].as_slice() == "signal" {
20         // Raise a segfault.
21         unsafe { *(0 as *mut int) = 0; }
22     } else {
23         let status = Command::new(args[0].as_slice()).arg("signal").status().unwrap();
24         // Windows does not have signal, so we get exit status 0xC0000028 (STATUS_BAD_STACK).
25         match status {
26             ExitSignal(_) if cfg!(unix) => {},
27             ExitStatus(0xC0000028) if cfg!(windows) => {},
28             _ => panic!("invalid termination (was not signalled): {}", status)
29         }
30     }
31 }