8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use std:: io:: { TempDir , Command , fs} ;
11
+ use std:: io:: { Command , fs, USER_RWX } ;
12
12
use std:: os;
13
13
14
14
fn main ( ) {
@@ -22,19 +22,23 @@ fn main() {
22
22
}
23
23
24
24
fn test ( ) {
25
- // If we're the parent, copy our own binary to a tempr directory, and then
26
- // make it executable.
27
- let dir = TempDir :: new ( "mytest" ) . unwrap ( ) ;
28
- let me = os:: self_exe_name ( ) . unwrap ( ) ;
29
- let dest = dir. path ( ) . join ( format ! ( "mytest{}" , os:: consts:: EXE_SUFFIX ) ) ;
30
- fs:: copy ( & me, & dest) . unwrap ( ) ;
31
-
32
- // Append the temp directory to our own PATH.
25
+ // If we're the parent, copy our own binary to a new directory.
26
+ let my_path = os:: self_exe_name ( ) . unwrap ( ) ;
27
+ let my_dir = my_path. dir_path ( ) ;
28
+
29
+ let child_dir = Path :: new ( my_dir. join ( "issue-15149-child" ) ) ;
30
+ drop ( fs:: mkdir ( & child_dir, USER_RWX ) ) ;
31
+
32
+ let child_path = child_dir. join ( format ! ( "mytest{}" ,
33
+ os:: consts:: EXE_SUFFIX ) ) ;
34
+ fs:: copy ( & my_path, & child_path) . unwrap ( ) ;
35
+
36
+ // Append the new directory to our own PATH.
33
37
let mut path = os:: split_paths ( os:: getenv ( "PATH" ) . unwrap_or ( String :: new ( ) ) ) ;
34
- path. push ( dir . path ( ) . clone ( ) ) ;
38
+ path. push ( child_dir . clone ( ) ) ;
35
39
let path = os:: join_paths ( path. as_slice ( ) ) . unwrap ( ) ;
36
40
37
- Command :: new ( "mytest" ) . env ( "PATH" , path. as_slice ( ) )
38
- . arg ( "child" )
39
- . spawn ( ) . unwrap ( ) ;
41
+ assert ! ( Command :: new( "mytest" ) . env( "PATH" , path. as_slice( ) )
42
+ . arg( "child" )
43
+ . status ( ) . unwrap( ) . success ( ) ) ;
40
44
}
0 commit comments