Skip to content

Commit a546ef9

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

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

test/test_unistd.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use nix::unistd::*;
44
use nix::unistd::ForkResult::*;
55
use nix::sys::wait::*;
66
use nix::sys::stat;
7-
use std::iter;
7+
use std::{env, iter};
88
use std::ffi::CString;
99
use std::fs::File;
1010
use std::io::Write;
@@ -64,27 +64,23 @@ 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+
let mut path = env::temp_dir();
68+
path.push("nix_tempfile.XXXXXX");
7169

72-
let result = mkstemp((tmp.to_owned() + "nix_tempfile.XXXXXX").as_str());
70+
let result = mkstemp(&path);
7371
match result {
7472
Ok((fd, path)) => {
7573
close(fd).unwrap();
7674
unlink(path.as_path()).unwrap();
7775
},
7876
Err(e) => panic!("mkstemp failed: {}", e)
7977
}
78+
}
8079

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());
8884
}
8985

9086
#[test]

0 commit comments

Comments
 (0)