File tree 2 files changed +17
-37
lines changed
2 files changed +17
-37
lines changed Original file line number Diff line number Diff line change 1
- // run-pass
2
-
3
- #![ allow( unused_variables) ]
4
- // no-prefer-dynamic
5
- // ignore-cross-compile
6
-
7
1
use std:: env;
8
- use std:: ffi:: OsStr ;
9
2
use std:: fs;
10
- use std:: path:: PathBuf ;
11
3
use std:: process;
12
4
use std:: str;
13
5
14
- fn main ( ) {
15
- // If we're the child, make sure we were invoked correctly
16
- let args: Vec < String > = env:: args ( ) . collect ( ) ;
17
- if args. len ( ) > 1 && args[ 1 ] == "child" {
18
- // FIXME: This should check the whole `args[0]` instead of just
19
- // checking that it ends_with the executable name. This
20
- // is needed because of Windows, which has a different behavior.
21
- // See #15149 for more info.
22
- let my_path = env:: current_exe ( ) . unwrap ( ) ;
23
- return assert_eq ! ( my_path. file_stem( ) , Some ( OsStr :: new( "mytest" ) ) ) ;
24
- }
25
-
26
- test ( ) ;
27
- }
6
+ mod common;
28
7
29
- fn test ( ) {
8
+ #[ test]
9
+ fn issue_15149 ( ) {
30
10
// If we're the parent, copy our own binary to a new directory.
31
11
let my_path = env:: current_exe ( ) . unwrap ( ) ;
32
- let my_dir = my_path. parent ( ) . unwrap ( ) ;
33
12
34
- let child_dir = PathBuf :: from ( env :: var_os ( "RUST_TEST_TMPDIR" ) . unwrap ( ) ) ;
35
- let child_dir = child_dir . join ( "issue-15140-child" ) ;
13
+ let temp = common :: tmpdir ( ) ;
14
+ let child_dir = temp . join ( "issue-15140-child" ) ;
36
15
fs:: create_dir_all ( & child_dir) . unwrap ( ) ;
37
16
38
17
let child_path = child_dir. join ( & format ! ( "mytest{}" , env:: consts:: EXE_SUFFIX ) ) ;
Original file line number Diff line number Diff line change 1
- // run-pass
2
- // ignore-wasm (needs file descriptors and env variables)
1
+ #[ cfg( any( target_family = "unix" , target_family = "windows" ) ) ]
3
2
4
- use std:: env;
5
3
use std:: fs:: File ;
6
4
use std:: io:: { Read , Write } ;
7
- use std:: path:: PathBuf ;
5
+
6
+ mod common;
8
7
9
8
#[ cfg( unix) ]
10
9
fn switch_stdout_to ( file : File ) {
@@ -35,16 +34,18 @@ fn switch_stdout_to(file: File) {
35
34
}
36
35
}
37
36
38
- fn main ( ) {
39
- let path = PathBuf :: from ( env:: var_os ( "RUST_TEST_TMPDIR" ) . unwrap ( ) ) ;
40
- let path = path. join ( "switch-stdout-output" ) ;
37
+ #[ test]
38
+ fn switch_stdout ( ) {
39
+ let temp = common:: tmpdir ( ) ;
40
+ let path = temp. join ( "switch-stdout-output" ) ;
41
41
let f = File :: create ( & path) . unwrap ( ) ;
42
42
43
- println ! ( "foo" ) ;
44
- std:: io:: stdout ( ) . flush ( ) . unwrap ( ) ;
43
+ let mut stdout = std:: io:: stdout ( ) ;
44
+ stdout. write ( b"foo\n " ) . unwrap ( ) ;
45
+ stdout. flush ( ) . unwrap ( ) ;
45
46
switch_stdout_to ( f) ;
46
- println ! ( "bar" ) ;
47
- std :: io :: stdout ( ) . flush ( ) . unwrap ( ) ;
47
+ stdout . write ( b "bar\n " ) . unwrap ( ) ;
48
+ stdout. flush ( ) . unwrap ( ) ;
48
49
49
50
let mut contents = String :: new ( ) ;
50
51
File :: open ( & path) . unwrap ( ) . read_to_string ( & mut contents) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments