16
16
// instead of in std.
17
17
18
18
#![ reexport_test_harness_main = "test_main" ]
19
- #![ feature( old_io , libc, std_misc) ]
19
+ #![ feature( libc, std_misc) ]
20
20
21
21
extern crate libc;
22
22
23
- use std:: old_io:: { Process , Command , timer} ;
24
- use std:: time:: Duration ;
23
+ use std:: process:: { self , Command , Child , Output } ;
25
24
use std:: str;
26
25
use std:: sync:: mpsc:: channel;
27
26
use std:: thread;
27
+ use std:: time:: Duration ;
28
28
29
- macro_rules! succeed { ( $e : expr ) => (
30
- match $e { Ok ( .. ) => { } , Err ( e) => panic!( "panic : {}" , e) }
31
- ) }
29
+ macro_rules! t {
30
+ ( $e : expr ) => ( match $e { Ok ( e ) => e , Err ( e) => panic!( "error : {}" , e) } )
31
+ }
32
32
33
33
fn test_destroy_once ( ) {
34
34
let mut p = sleeper ( ) ;
35
- match p. signal_exit ( ) {
35
+ match p. kill ( ) {
36
36
Ok ( ( ) ) => { }
37
37
Err ( e) => panic ! ( "error: {}" , e) ,
38
38
}
39
39
}
40
40
41
41
#[ cfg( unix) ]
42
- pub fn sleeper ( ) -> Process {
42
+ pub fn sleeper ( ) -> Child {
43
43
Command :: new ( "sleep" ) . arg ( "1000" ) . spawn ( ) . unwrap ( )
44
44
}
45
45
#[ cfg( windows) ]
46
- pub fn sleeper ( ) -> Process {
46
+ pub fn sleeper ( ) -> Child {
47
47
// There's a `timeout` command on windows, but it doesn't like having
48
48
// its output piped, so instead just ping ourselves a few times with
49
49
// gaps in between so we're sure this process is alive for awhile
@@ -52,16 +52,12 @@ pub fn sleeper() -> Process {
52
52
53
53
fn test_destroy_twice ( ) {
54
54
let mut p = sleeper ( ) ;
55
- succeed ! ( p. signal_exit ( ) ) ; // this shouldn't crash...
56
- let _ = p. signal_exit ( ) ; // ...and nor should this (and nor should the destructor)
55
+ t ! ( p. kill ( ) ) ; // this shouldn't crash...
56
+ let _ = p. kill ( ) ; // ...and nor should this (and nor should the destructor)
57
57
}
58
58
59
- pub fn test_destroy_actually_kills ( force : bool ) {
60
- use std:: old_io:: process:: { Command , ProcessOutput , ExitStatus , ExitSignal } ;
61
- use std:: old_io:: timer;
62
- use libc;
63
- use std:: str;
64
-
59
+ #[ test]
60
+ fn test_destroy_actually_kills ( ) {
65
61
#[ cfg( all( unix, not( target_os="android" ) ) ) ]
66
62
static BLOCK_COMMAND : & ' static str = "cat" ;
67
63
@@ -74,34 +70,16 @@ pub fn test_destroy_actually_kills(force: bool) {
74
70
// this process will stay alive indefinitely trying to read from stdin
75
71
let mut p = Command :: new ( BLOCK_COMMAND ) . spawn ( ) . unwrap ( ) ;
76
72
77
- assert ! ( p. signal( 0 ) . is_ok( ) ) ;
78
-
79
- if force {
80
- p. signal_kill ( ) . unwrap ( ) ;
81
- } else {
82
- p. signal_exit ( ) . unwrap ( ) ;
83
- }
73
+ p. kill ( ) . unwrap ( ) ;
84
74
85
75
// Don't let this test time out, this should be quick
86
- let ( tx, rx1) = channel ( ) ;
87
- let mut t = timer:: Timer :: new ( ) . unwrap ( ) ;
88
- let rx2 = t. oneshot ( Duration :: milliseconds ( 1000 ) ) ;
76
+ let ( tx, rx) = channel ( ) ;
89
77
thread:: spawn ( move || {
90
- select ! {
91
- _ = rx2 . recv ( ) => unsafe { libc :: exit ( 1 ) } ,
92
- _ = rx1 . recv ( ) => { }
78
+ thread :: sleep_ms ( 1000 ) ;
79
+ if rx . try_recv ( ) . is_err ( ) {
80
+ process :: exit ( 1 ) ;
93
81
}
94
82
} ) ;
95
- match p. wait ( ) . unwrap ( ) {
96
- ExitStatus ( ..) => panic ! ( "expected a signal" ) ,
97
- ExitSignal ( ..) => tx. send ( ( ) ) . unwrap ( ) ,
98
- }
99
- }
100
-
101
- fn test_unforced_destroy_actually_kills ( ) {
102
- test_destroy_actually_kills ( false ) ;
103
- }
104
-
105
- fn test_forced_destroy_actually_kills ( ) {
106
- test_destroy_actually_kills ( true ) ;
83
+ assert ! ( p. wait( ) . unwrap( ) . code( ) . is_none( ) ) ;
84
+ tx. send ( ( ) ) ;
107
85
}
0 commit comments