diff options
author | Alan Somers <asomers@gmail.com> | 2021-08-22 09:17:05 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2021-08-22 10:31:39 -0600 |
commit | f3cb6b321fa1e16dc14b9bcdc37f001375a8c85c (patch) | |
tree | 204a669147d64f9b928660685cb4f0920a0f4e4a | |
parent | 28f547fa120cf842278c6749254edcd0ce6fea6a (diff) | |
download | nix-f3cb6b321fa1e16dc14b9bcdc37f001375a8c85c.zip |
Fix building the tests for Redox and Illumos
Also, split the overbroad test_mknod_family into two tests
-rw-r--r-- | test/test_fcntl.rs | 2 | ||||
-rw-r--r-- | test/test_stat.rs | 71 | ||||
-rw-r--r-- | test/test_time.rs | 6 | ||||
-rw-r--r-- | test/test_unistd.rs | 1 |
4 files changed, 44 insertions, 36 deletions
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index ae6756ec..e74a8598 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -28,8 +28,6 @@ use std::io::prelude::*; #[cfg(not(target_os = "redox"))] use std::os::unix::fs; -use crate::*; - #[test] #[cfg(not(target_os = "redox"))] fn test_openat() { 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); } diff --git a/test/test_time.rs b/test/test_time.rs index c321352d..dc307e57 100644 --- a/test/test_time.rs +++ b/test/test_time.rs @@ -6,11 +6,12 @@ target_os = "emscripten", ))] use nix::time::clock_getcpuclockid; -use nix::time::{clock_getres, clock_gettime, ClockId}; +use nix::time::{clock_gettime, ClockId}; +#[cfg(not(target_os = "redox"))] #[test] pub fn test_clock_getres() { - assert!(clock_getres(ClockId::CLOCK_REALTIME).is_ok()); + assert!(nix::time::clock_getres(ClockId::CLOCK_REALTIME).is_ok()); } #[test] @@ -31,6 +32,7 @@ pub fn test_clock_getcpuclockid() { assert!(clock_gettime(clock_id).is_ok()); } +#[cfg(not(target_os = "redox"))] #[test] pub fn test_clock_id_res() { assert!(ClockId::CLOCK_REALTIME.res().is_ok()); diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 984dd2c9..37e7a9b3 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -1025,6 +1025,7 @@ fn test_access_file_exists() { assert!(access(&path, AccessFlags::R_OK | AccessFlags::W_OK).is_ok()); } +#[cfg(not(target_os = "redox"))] #[test] fn test_user_into_passwd() { // get the UID of the "nobody" user |