summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhang Miaolei <zmlcc@outlook.com>2019-09-30 14:44:47 +0800
committerZhang Miaolei <zmlcc@outlook.com>2019-09-30 14:44:47 +0800
commit6ea84dc3ce288b3daf494e7e1e6ea5411097fe6c (patch)
treebe57c302d7b33d8e1832495ada3bd6e36b322b7b
parent4fe8418608e887aec9a1e9363ea6935c345654c8 (diff)
downloadnix-6ea84dc3ce288b3daf494e7e1e6ea5411097fe6c.zip
refactored test cases
ignore mkfifoat in OSX and andriod
-rw-r--r--src/unistd.rs6
-rw-r--r--test/test_unistd.rs31
2 files changed, 28 insertions, 9 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index c29096e7..886084e8 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -515,10 +515,12 @@ pub fn mkfifo<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
/// # References
///
/// [mkfifoat(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mkfifoat.html).
+// mkfifoat is not implemented in OSX or android
#[inline]
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
pub fn mkfifoat<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P, mode: Mode) -> Result<()> {
- let res = path.with_nix_path(|cstr| {
- unsafe { libc::mkfifoat(at_rawfd(dirfd), cstr.as_ptr(), mode.bits() as mode_t) }
+ let res = path.with_nix_path(|cstr| unsafe {
+ libc::mkfifoat(at_rawfd(dirfd), cstr.as_ptr(), mode.bits() as mode_t)
})?;
Errno::result(res).map(drop)
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 6dbbb9ff..94975049 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -99,7 +99,8 @@ fn test_mkfifo_directory() {
}
#[test]
-fn test_mkfifoat() {
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
+fn test_mkfifoat_none() {
let tempdir = tempfile::tempdir().unwrap();
let mkfifoat_fifo = tempdir.path().join("mkfifoat_fifo");
@@ -107,9 +108,13 @@ fn test_mkfifoat() {
let stats = stat::stat(&mkfifoat_fifo).unwrap();
let typ = stat::SFlag::from_bits_truncate(stats.st_mode);
- assert!(typ == SFlag::S_IFIFO);
-
+ assert_eq!(typ, SFlag::S_IFIFO);
+}
+#[test]
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
+fn test_mkfifoat() {
+ let tempdir = tempfile::tempdir().unwrap();
let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap();
let mkfifoat_name = "mkfifoat_name";
@@ -117,20 +122,32 @@ fn test_mkfifoat() {
let stats = stat::fstatat(dirfd, mkfifoat_name, fcntl::AtFlags::empty()).unwrap();
let typ = stat::SFlag::from_bits_truncate(stats.st_mode);
- assert!(typ == SFlag::S_IFIFO);
+ assert_eq!(typ, SFlag::S_IFIFO);
}
#[test]
-fn test_mkfifoat_directory() {
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
+fn test_mkfifoat_directory_none() {
// mkfifoat should fail if a directory is given
- assert!(mkfifoat(None, &env::temp_dir(), Mode::S_IRUSR).is_err());
+ assert_eq!(
+ mkfifoat(None, &env::temp_dir(), Mode::S_IRUSR).is_ok(),
+ false
+ );
+}
+#[test]
+#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
+fn test_mkfifoat_directory() {
+ // mkfifoat should fail if a directory is given
let tempdir = tempfile::tempdir().unwrap();
let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap();
let mkfifoat_dir = "mkfifoat_dir";
stat::mkdirat(dirfd, mkfifoat_dir, Mode::S_IRUSR).unwrap();
- assert!(mkfifoat(Some(dirfd), mkfifoat_dir, Mode::S_IRUSR).is_err());
+ assert_eq!(
+ mkfifoat(Some(dirfd), mkfifoat_dir, Mode::S_IRUSR).is_ok(),
+ false
+ );
}
#[test]