From f3cb6b321fa1e16dc14b9bcdc37f001375a8c85c Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 22 Aug 2021 09:17:05 -0600 Subject: Fix building the tests for Redox and Illumos Also, split the overbroad test_mknod_family into two tests --- test/test_stat.rs | 71 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 32 deletions(-) (limited to 'test/test_stat.rs') 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); } -- cgit v1.2.3