File tree 1 file changed +9
-13
lines changed
1 file changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use nix::unistd::*;
4
4
use nix:: unistd:: ForkResult :: * ;
5
5
use nix:: sys:: wait:: * ;
6
6
use nix:: sys:: stat;
7
- use std:: iter;
7
+ use std:: { env , iter} ;
8
8
use std:: ffi:: CString ;
9
9
use std:: fs:: File ;
10
10
use std:: io:: Write ;
@@ -64,27 +64,23 @@ fn test_wait() {
64
64
65
65
#[ test]
66
66
fn test_mkstemp ( ) {
67
- #[ cfg( target_os = "android" ) ]
68
- let tmp = "/data/local/tmp/" ;
69
- #[ cfg( not( target_os = "android" ) ) ]
70
- let tmp = "/tmp/" ;
67
+ let mut path = env:: temp_dir ( ) ;
68
+ path. push ( "nix_tempfile.XXXXXX" ) ;
71
69
72
- let result = mkstemp ( ( tmp . to_owned ( ) + "nix_tempfile.XXXXXX" ) . as_str ( ) ) ;
70
+ let result = mkstemp ( & path ) ;
73
71
match result {
74
72
Ok ( ( fd, path) ) => {
75
73
close ( fd) . unwrap ( ) ;
76
74
unlink ( path. as_path ( ) ) . unwrap ( ) ;
77
75
} ,
78
76
Err ( e) => panic ! ( "mkstemp failed: {}" , e)
79
77
}
78
+ }
80
79
81
- let result = mkstemp ( tmp) ;
82
- match result {
83
- Ok ( _) => {
84
- panic ! ( "mkstemp succeeded even though it should fail (provided a directory)" ) ;
85
- } ,
86
- Err ( _) => { }
87
- }
80
+ #[ test]
81
+ fn test_mkstemp_directory ( ) {
82
+ // mkstemp should fail if a directory is given
83
+ assert ! ( mkstemp( & env:: temp_dir( ) ) . is_err( ) ) ;
88
84
}
89
85
90
86
#[ test]
You can’t perform that action at this time.
0 commit comments