Skip to content

Commit 6ea84dc

Browse files
committed
refactored test cases
ignore mkfifoat in OSX and andriod
1 parent 4fe8418 commit 6ea84dc

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/unistd.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,12 @@ pub fn mkfifo<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
515515
/// # References
516516
///
517517
/// [mkfifoat(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mkfifoat.html).
518+
// mkfifoat is not implemented in OSX or android
518519
#[inline]
520+
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
519521
pub fn mkfifoat<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P, mode: Mode) -> Result<()> {
520-
let res = path.with_nix_path(|cstr| {
521-
unsafe { libc::mkfifoat(at_rawfd(dirfd), cstr.as_ptr(), mode.bits() as mode_t) }
522+
let res = path.with_nix_path(|cstr| unsafe {
523+
libc::mkfifoat(at_rawfd(dirfd), cstr.as_ptr(), mode.bits() as mode_t)
522524
})?;
523525

524526
Errno::result(res).map(drop)

test/test_unistd.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,38 +99,55 @@ fn test_mkfifo_directory() {
9999
}
100100

101101
#[test]
102-
fn test_mkfifoat() {
102+
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
103+
fn test_mkfifoat_none() {
103104
let tempdir = tempfile::tempdir().unwrap();
104105
let mkfifoat_fifo = tempdir.path().join("mkfifoat_fifo");
105106

106107
mkfifoat(None, &mkfifoat_fifo, Mode::S_IRUSR).unwrap();
107108

108109
let stats = stat::stat(&mkfifoat_fifo).unwrap();
109110
let typ = stat::SFlag::from_bits_truncate(stats.st_mode);
110-
assert!(typ == SFlag::S_IFIFO);
111-
111+
assert_eq!(typ, SFlag::S_IFIFO);
112+
}
112113

114+
#[test]
115+
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
116+
fn test_mkfifoat() {
117+
let tempdir = tempfile::tempdir().unwrap();
113118
let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap();
114119
let mkfifoat_name = "mkfifoat_name";
115120

116121
mkfifoat(Some(dirfd), mkfifoat_name, Mode::S_IRUSR).unwrap();
117122

118123
let stats = stat::fstatat(dirfd, mkfifoat_name, fcntl::AtFlags::empty()).unwrap();
119124
let typ = stat::SFlag::from_bits_truncate(stats.st_mode);
120-
assert!(typ == SFlag::S_IFIFO);
125+
assert_eq!(typ, SFlag::S_IFIFO);
121126
}
122127

123128
#[test]
124-
fn test_mkfifoat_directory() {
129+
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
130+
fn test_mkfifoat_directory_none() {
125131
// mkfifoat should fail if a directory is given
126-
assert!(mkfifoat(None, &env::temp_dir(), Mode::S_IRUSR).is_err());
132+
assert_eq!(
133+
mkfifoat(None, &env::temp_dir(), Mode::S_IRUSR).is_ok(),
134+
false
135+
);
136+
}
127137

138+
#[test]
139+
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
140+
fn test_mkfifoat_directory() {
141+
// mkfifoat should fail if a directory is given
128142
let tempdir = tempfile::tempdir().unwrap();
129143
let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap();
130144
let mkfifoat_dir = "mkfifoat_dir";
131145
stat::mkdirat(dirfd, mkfifoat_dir, Mode::S_IRUSR).unwrap();
132146

133-
assert!(mkfifoat(Some(dirfd), mkfifoat_dir, Mode::S_IRUSR).is_err());
147+
assert_eq!(
148+
mkfifoat(Some(dirfd), mkfifoat_dir, Mode::S_IRUSR).is_ok(),
149+
false
150+
);
134151
}
135152

136153
#[test]

0 commit comments

Comments
 (0)