Skip to content

Commit 7cba750

Browse files
committed
use std::env::temp_dir() to retrieve the temp directory in test_mkstemp
1 parent f72287e commit 7cba750

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

test/test_unistd.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,27 @@ fn test_wait() {
6464

6565
#[test]
6666
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+
use std::env;
7168

72-
let result = mkstemp((tmp.to_owned() + "nix_tempfile.XXXXXX").as_str());
69+
let mut path = env::temp_dir();
70+
path.push("nix_tempfile.XXXXXX");
71+
72+
let result = mkstemp(&path);
7373
match result {
7474
Ok((fd, path)) => {
7575
close(fd).unwrap();
7676
unlink(path.as_path()).unwrap();
7777
},
7878
Err(e) => panic!("mkstemp failed: {}", e)
7979
}
80+
}
8081

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-
}
82+
#[test]
83+
fn test_mkstemp_directory() {
84+
use std::env;
85+
86+
// mkstemp should fail if a directory is given
87+
assert!(mkstemp(&env::temp_dir()).is_err());
8888
}
8989

9090
#[test]

0 commit comments

Comments
 (0)