summaryrefslogtreecommitdiff
path: root/test/test_stat.rs
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2021-08-22 09:17:05 -0600
committerAlan Somers <asomers@gmail.com>2021-08-22 10:31:39 -0600
commitf3cb6b321fa1e16dc14b9bcdc37f001375a8c85c (patch)
tree204a669147d64f9b928660685cb4f0920a0f4e4a /test/test_stat.rs
parent28f547fa120cf842278c6749254edcd0ce6fea6a (diff)
downloadnix-f3cb6b321fa1e16dc14b9bcdc37f001375a8c85c.zip
Fix building the tests for Redox and Illumos
Also, split the overbroad test_mknod_family into two tests
Diffstat (limited to 'test/test_stat.rs')
-rw-r--r--test/test_stat.rs71
1 files changed, 39 insertions, 32 deletions
diff --git a/test/test_stat.rs b/test/test_stat.rs
index 42c536a8..922c25fd 100644
--- a/test/test_stat.rs
+++ b/test/test_stat.rs
@@ -11,7 +11,6 @@ use std::path::Path;
#[cfg(not(any(target_os = "netbsd", target_os = "redox")))]
use libc::{S_IFMT, S_IFLNK};
-#[cfg(not(target_os = "redox"))]
use libc::mode_t;
#[cfg(not(target_os = "redox"))]
@@ -312,39 +311,47 @@ fn test_mkdirat_fail() {
target_os = "ios",
target_os = "macos",
target_os = "redox")))]
-fn test_mknod_family() {
+fn test_mknod() {
+ use stat::{lstat, mknod, SFlag};
+
+ let file_name = "test_file";
+ let tempdir = tempfile::tempdir().unwrap();
+ let target = tempdir.path().join(file_name);
+ mknod(&target, SFlag::S_IFREG, Mode::S_IRWXU, 0).unwrap();
+ let mode = lstat(&target).unwrap().st_mode as mode_t;
+ assert!(mode & libc::S_IFREG == libc::S_IFREG);
+ assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
+}
+
+#[test]
+#[cfg(not(any(target_os = "freebsd",
+ target_os = "illumos",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "redox")))]
+fn test_mknodat() {
use fcntl::{AtFlags, OFlag};
use nix::dir::Dir;
- use stat::{fstatat, lstat, mknod, mknodat, SFlag};
+ use stat::{fstatat, mknodat, SFlag};
let file_name = "test_file";
- {
- let tempdir = tempfile::tempdir().unwrap();
- let target = tempdir.path().join(file_name);
- mknod(&target, SFlag::S_IFREG, Mode::S_IRWXU, 0).unwrap();
- let mode = lstat(&target).unwrap().st_mode as mode_t;
- assert!(mode & libc::S_IFREG == libc::S_IFREG);
- assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
- }
- {
- let tempdir = tempfile::tempdir().unwrap();
- let target_dir = Dir::open(tempdir.path(), OFlag::O_DIRECTORY, Mode::S_IRWXU).unwrap();
- mknodat(
- target_dir.as_raw_fd(),
- file_name,
- SFlag::S_IFREG,
- Mode::S_IRWXU,
- 0,
- )
- .unwrap();
- let mode = fstatat(
- target_dir.as_raw_fd(),
- file_name,
- AtFlags::AT_SYMLINK_NOFOLLOW,
- )
- .unwrap()
- .st_mode as mode_t;
- assert!(mode & libc::S_IFREG == libc::S_IFREG);
- assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
- }
+ let tempdir = tempfile::tempdir().unwrap();
+ let target_dir = Dir::open(tempdir.path(), OFlag::O_DIRECTORY, Mode::S_IRWXU).unwrap();
+ mknodat(
+ target_dir.as_raw_fd(),
+ file_name,
+ SFlag::S_IFREG,
+ Mode::S_IRWXU,
+ 0,
+ )
+ .unwrap();
+ let mode = fstatat(
+ target_dir.as_raw_fd(),
+ file_name,
+ AtFlags::AT_SYMLINK_NOFOLLOW,
+ )
+ .unwrap()
+ .st_mode as mode_t;
+ assert!(mode & libc::S_IFREG == libc::S_IFREG);
+ assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
}