This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-37
lines changed Expand file tree Collapse file tree 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-
71use std:: env;
8- use std:: ffi:: OsStr ;
92use std:: fs;
10- use std:: path:: PathBuf ;
113use std:: process;
124use std:: str;
135
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;
287
29- fn test ( ) {
8+ #[ test]
9+ fn issue_15149 ( ) {
3010 // If we're the parent, copy our own binary to a new directory.
3111 let my_path = env:: current_exe ( ) . unwrap ( ) ;
32- let my_dir = my_path. parent ( ) . unwrap ( ) ;
3312
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" ) ;
3615 fs:: create_dir_all ( & child_dir) . unwrap ( ) ;
3716
3817 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" ) ) ]
32
4- use std:: env;
53use std:: fs:: File ;
64use std:: io:: { Read , Write } ;
7- use std:: path:: PathBuf ;
5+
6+ mod common;
87
98#[ cfg( unix) ]
109fn switch_stdout_to ( file : File ) {
@@ -35,16 +34,18 @@ fn switch_stdout_to(file: File) {
3534 }
3635}
3736
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" ) ;
4141 let f = File :: create ( & path) . unwrap ( ) ;
4242
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 ( ) ;
4546 switch_stdout_to ( f) ;
46- println ! ( "bar" ) ;
47- std :: io :: stdout ( ) . flush ( ) . unwrap ( ) ;
47+ stdout . write ( b "bar\n " ) . unwrap ( ) ;
48+ stdout. flush ( ) . unwrap ( ) ;
4849
4950 let mut contents = String :: new ( ) ;
5051 File :: open ( & path) . unwrap ( ) . read_to_string ( & mut contents) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments