5
5
// ignore-cross-compile
6
6
7
7
use std:: env;
8
+ use std:: ffi:: OsStr ;
8
9
use std:: fs;
10
+ use std:: path:: PathBuf ;
9
11
use std:: process;
10
12
use std:: str;
11
- use std:: path:: PathBuf ;
12
13
13
14
fn main ( ) {
14
15
// If we're the child, make sure we were invoked correctly
@@ -18,8 +19,8 @@ fn main() {
18
19
// checking that it ends_with the executable name. This
19
20
// is needed because of Windows, which has a different behavior.
20
21
// See #15149 for more info.
21
- return assert ! ( args [ 0 ] . ends_with ( & format! ( "mytest{}" ,
22
- env :: consts :: EXE_SUFFIX ) ) ) ;
22
+ let my_path = env :: current_exe ( ) . unwrap ( ) ;
23
+ return assert_eq ! ( my_path . file_stem ( ) , Some ( OsStr :: new ( "mytest" ) ) ) ;
23
24
}
24
25
25
26
test ( ) ;
@@ -28,14 +29,13 @@ fn main() {
28
29
fn test ( ) {
29
30
// If we're the parent, copy our own binary to a new directory.
30
31
let my_path = env:: current_exe ( ) . unwrap ( ) ;
31
- let my_dir = my_path. parent ( ) . unwrap ( ) ;
32
+ let my_dir = my_path. parent ( ) . unwrap ( ) ;
32
33
33
34
let child_dir = PathBuf :: from ( env:: var_os ( "RUST_TEST_TMPDIR" ) . unwrap ( ) ) ;
34
35
let child_dir = child_dir. join ( "issue-15140-child" ) ;
35
36
fs:: create_dir_all ( & child_dir) . unwrap ( ) ;
36
37
37
- let child_path = child_dir. join ( & format ! ( "mytest{}" ,
38
- env:: consts:: EXE_SUFFIX ) ) ;
38
+ let child_path = child_dir. join ( & format ! ( "mytest{}" , env:: consts:: EXE_SUFFIX ) ) ;
39
39
fs:: copy ( & my_path, & child_path) . unwrap ( ) ;
40
40
41
41
// Append the new directory to our own PATH.
@@ -45,12 +45,13 @@ fn test() {
45
45
env:: join_paths ( paths) . unwrap ( )
46
46
} ;
47
47
48
- let child_output = process:: Command :: new ( "mytest" ) . env ( "PATH" , & path)
49
- . arg ( "child" )
50
- . output ( ) . unwrap ( ) ;
48
+ let child_output =
49
+ process:: Command :: new ( "mytest" ) . env ( "PATH" , & path) . arg ( "child" ) . output ( ) . unwrap ( ) ;
51
50
52
- assert ! ( child_output. status. success( ) ,
53
- "child assertion failed\n child stdout:\n {}\n child stderr:\n {}" ,
54
- str :: from_utf8( & child_output. stdout) . unwrap( ) ,
55
- str :: from_utf8( & child_output. stderr) . unwrap( ) ) ;
51
+ assert ! (
52
+ child_output. status. success( ) ,
53
+ "child assertion failed\n child stdout:\n {}\n child stderr:\n {}" ,
54
+ str :: from_utf8( & child_output. stdout) . unwrap( ) ,
55
+ str :: from_utf8( & child_output. stderr) . unwrap( )
56
+ ) ;
56
57
}
0 commit comments