summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjr <semi1@posteo.de>2019-04-19 23:52:59 +0200
committerjr <semi1@posteo.de>2019-04-20 12:28:54 +0200
commit78d7aea35ef838a88d85a79a0acf36c5506d76ed (patch)
treee552cd853765b1455c521d895211593f9f7b5f5d /test
parentaf59a15c5e03457db7ebd1743e9ecc14bc2de2f1 (diff)
downloadnix-78d7aea35ef838a88d85a79a0acf36c5506d76ed.zip
Add a access(2) wrapper
Diffstat (limited to 'test')
-rw-r--r--test/test_unistd.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 3fb50535..3f13883c 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -4,6 +4,7 @@ use nix::unistd::ForkResult::*;
use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction};
use nix::sys::wait::*;
use nix::sys::stat::{self, Mode, SFlag};
+use nix::errno::Errno;
use std::{env, iter};
use std::ffi::CString;
use std::fs::{self, File};
@@ -574,3 +575,19 @@ fn test_symlinkat() {
target
);
}
+
+#[test]
+fn test_access_not_existing() {
+ let tempdir = tempfile::tempdir().unwrap();
+ let dir = tempdir.path().join("does_not_exist.txt");
+ assert_eq!(access(&dir, AccessFlags::F_OK).err().unwrap().as_errno().unwrap(),
+ Errno::ENOENT);
+}
+
+#[test]
+fn test_access_file_exists() {
+ let tempdir = tempfile::tempdir().unwrap();
+ let path = tempdir.path().join("does_exist.txt");
+ let _file = File::create(path.clone()).unwrap();
+ assert!(access(&path, AccessFlags::R_OK | AccessFlags::W_OK).is_ok());
+}