summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Baikov <manpacket@gmail.com>2022-08-04 07:54:45 +0800
committerMichael Baikov <manpacket@gmail.com>2022-08-04 09:44:40 +0800
commita6ee63ac3212e62518c97252581cfa48e2ad056e (patch)
treea57022d55d6c819491a1ac9c510049748034440e
parent854a5469c0475acf2e57b63740c9e447d3b9e4f8 (diff)
downloadnix-a6ee63ac3212e62518c97252581cfa48e2ad056e.zip
fix clippy assertions_on_result_states
https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_result_states
-rw-r--r--src/sys/signal.rs6
-rw-r--r--src/sys/signalfd.rs9
-rw-r--r--src/sys/termios.rs4
-rw-r--r--test/sys/test_aio.rs14
-rw-r--r--test/sys/test_epoll.rs4
-rw-r--r--test/sys/test_socket.rs2
-rw-r--r--test/sys/test_termios.rs2
-rw-r--r--test/sys/test_uio.rs35
-rw-r--r--test/sys/test_wait.rs24
-rw-r--r--test/test_fcntl.rs6
-rw-r--r--test/test_net.rs2
-rw-r--r--test/test_stat.rs4
-rw-r--r--test/test_time.rs15
-rw-r--r--test/test_unistd.rs30
14 files changed, 74 insertions, 83 deletions
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 4a468b62..0da9c74a 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -1189,7 +1189,7 @@ mod tests {
let mut test_mask = prev_mask;
test_mask.add(SIGUSR1);
- assert!(test_mask.thread_set_mask().is_ok());
+ test_mask.thread_set_mask().expect("assertion failed");
let new_mask =
SigSet::thread_get_mask().expect("Failed to get new mask!");
@@ -1211,7 +1211,7 @@ mod tests {
let mut mask = SigSet::empty();
mask.add(SIGUSR1);
- assert!(mask.thread_block().is_ok());
+ mask.thread_block().expect("assertion failed");
assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR1));
})
@@ -1226,7 +1226,7 @@ mod tests {
let mut mask = SigSet::empty();
mask.add(SIGUSR1);
- assert!(mask.thread_unblock().is_ok());
+ mask.thread_unblock().expect("assertion failed");
assert!(!SigSet::thread_get_mask().unwrap().contains(SIGUSR1));
})
diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs
index bc4a4522..3d82b5ba 100644
--- a/src/sys/signalfd.rs
+++ b/src/sys/signalfd.rs
@@ -148,14 +148,17 @@ mod tests {
fn create_signalfd() {
let mask = SigSet::empty();
let fd = SignalFd::new(&mask);
- assert!(fd.is_ok());
+ fd.expect("assert failed");
}
#[test]
fn create_signalfd_with_opts() {
let mask = SigSet::empty();
- let fd = SignalFd::with_flags(&mask, SfdFlags::SFD_CLOEXEC | SfdFlags::SFD_NONBLOCK);
- assert!(fd.is_ok());
+ let fd = SignalFd::with_flags(
+ &mask,
+ SfdFlags::SFD_CLOEXEC | SfdFlags::SFD_NONBLOCK,
+ );
+ fd.expect("assert failed");
}
#[test]
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 2e1b53d7..feb52c0a 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -1107,8 +1107,8 @@ mod test {
fn try_from() {
assert_eq!(Ok(BaudRate::B0), BaudRate::try_from(libc::B0));
#[cfg(not(target_os = "haiku"))]
- assert!(BaudRate::try_from(999999999).is_err());
+ BaudRate::try_from(999999999).expect_err("assertion failed");
#[cfg(target_os = "haiku")]
- assert!(BaudRate::try_from(99).is_err());
+ BaudRate::try_from(99).expect_err("assertion failed");
}
}
diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs
index b4ea6757..12749b1d 100644
--- a/test/sys/test_aio.rs
+++ b/test/sys/test_aio.rs
@@ -85,7 +85,7 @@ mod aio_fsync {
SigevNotify::SigevNone,
));
let err = aiof.as_mut().submit();
- assert!(err.is_err());
+ err.expect_err("assertion failed");
}
#[test]
@@ -102,7 +102,7 @@ mod aio_fsync {
SigevNotify::SigevNone,
));
let err = aiof.as_mut().submit();
- assert!(err.is_ok());
+ err.expect("assert failed");
poll_aio!(&mut aiof).unwrap();
aiof.as_mut().aio_return().unwrap();
}
@@ -149,7 +149,7 @@ mod aio_read {
aior.as_mut().submit().unwrap();
let cancelstat = aior.as_mut().cancel();
- assert!(cancelstat.is_ok());
+ cancelstat.expect("assert failed");
// Wait for aiow to complete, but don't care whether it succeeded
let _ = poll_aio!(&mut aior);
@@ -174,7 +174,7 @@ mod aio_read {
0, //priority
SigevNotify::SigevNone,
));
- assert!(aior.as_mut().submit().is_err());
+ aior.as_mut().submit().expect_err("assertion failed");
}
// Test a simple aio operation with no completion notification. We must
@@ -342,7 +342,7 @@ mod aio_write {
assert!(err == Ok(()) || err == Err(Errno::EINPROGRESS));
let cancelstat = aiow.as_mut().cancel();
- assert!(cancelstat.is_ok());
+ cancelstat.expect("assert failed");
// Wait for aiow to complete, but don't care whether it succeeded
let _ = poll_aio!(&mut aiow);
@@ -426,7 +426,7 @@ mod aio_write {
0, //priority
SigevNotify::SigevNone,
));
- assert!(aiow.as_mut().submit().is_err());
+ aiow.as_mut().submit().expect_err("assertion failed");
// Dropping the AioWrite at this point should not panic
}
}
@@ -565,7 +565,7 @@ fn test_aio_cancel_all() {
assert!(err == Ok(()) || err == Err(Errno::EINPROGRESS));
let cancelstat = aio_cancel_all(f.as_raw_fd());
- assert!(cancelstat.is_ok());
+ cancelstat.expect("assert failed");
// Wait for aiocb to complete, but don't care whether it succeeded
let _ = poll_aio!(&mut aiocb);
diff --git a/test/sys/test_epoll.rs b/test/sys/test_epoll.rs
index fafbd749..91569159 100644
--- a/test/sys/test_epoll.rs
+++ b/test/sys/test_epoll.rs
@@ -6,11 +6,11 @@ use nix::sys::epoll::{EpollCreateFlags, EpollEvent, EpollFlags, EpollOp};
pub fn test_epoll_errno() {
let efd = epoll_create1(EpollCreateFlags::empty()).unwrap();
let result = epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None);
- assert!(result.is_err());
+ result.expect_err("assertion failed");
assert_eq!(result.unwrap_err(), Errno::ENOENT);
let result = epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, None);
- assert!(result.is_err());
+ result.expect_err("assertion failed");
assert_eq!(result.unwrap_err(), Errno::EINVAL);
}
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index 0a74b5e1..06d5b761 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -204,7 +204,7 @@ pub fn test_addr_equality_path() {
pub fn test_abstract_sun_path_too_long() {
let name = String::from("nix\0abstract\0tesnix\0abstract\0tesnix\0abstract\0tesnix\0abstract\0tesnix\0abstract\0testttttnix\0abstract\0test\0make\0sure\0this\0is\0long\0enough");
let addr = UnixAddr::new_abstract(name.as_bytes());
- assert!(addr.is_err());
+ addr.expect_err("assertion failed");
}
#[cfg(any(target_os = "android", target_os = "linux"))]
diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs
index e567a52c..11a08cb5 100644
--- a/test/sys/test_termios.rs
+++ b/test/sys/test_termios.rs
@@ -22,7 +22,7 @@ fn test_tcgetattr_pty() {
let _m = crate::PTSNAME_MTX.lock();
let pty = openpty(None, None).expect("openpty failed");
- assert!(termios::tcgetattr(pty.slave).is_ok());
+ termios::tcgetattr(pty.slave).expect("assert failed");
close(pty.master).expect("closing the master failed");
close(pty.slave).expect("closing the slave failed");
}
diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs
index f46b1940..0f4b8a65 100644
--- a/test/sys/test_uio.rs
+++ b/test/sys/test_uio.rs
@@ -41,29 +41,22 @@ fn test_writev() {
consumed += slice_len;
}
let pipe_res = pipe();
- assert!(pipe_res.is_ok());
- let (reader, writer) = pipe_res.ok().unwrap();
+ let (reader, writer) = pipe_res.expect("Couldn't create pipe");
// FileDesc will close its filedesc (reader).
let mut read_buf: Vec<u8> = iter::repeat(0u8).take(128 * 16).collect();
// Blocking io, should write all data.
let write_res = writev(writer, &iovecs);
- // Successful write
- assert!(write_res.is_ok());
- let written = write_res.ok().unwrap();
+ let written = write_res.expect("couldn't write");
// Check whether we written all data
assert_eq!(to_write.len(), written);
let read_res = read(reader, &mut read_buf[..]);
- // Successful read
- assert!(read_res.is_ok());
- let read = read_res.ok().unwrap() as usize;
+ let read = read_res.expect("couldn't read");
// Check we have read as much as we written
assert_eq!(read, written);
// Check equality of written and read data
assert_eq!(&to_write, &read_buf);
- let close_res = close(writer);
- assert!(close_res.is_ok());
- let close_res = close(reader);
- assert!(close_res.is_ok());
+ close(writer).expect("closed writer");
+ close(reader).expect("closed reader");
}
#[test]
@@ -92,16 +85,10 @@ fn test_readv() {
for v in &mut storage {
iovecs.push(IoSliceMut::new(&mut v[..]));
}
- let pipe_res = pipe();
- assert!(pipe_res.is_ok());
- let (reader, writer) = pipe_res.ok().unwrap();
+ let (reader, writer) = pipe().expect("couldn't create pipe");
// Blocking io, should write all data.
- let write_res = write(writer, &to_write);
- // Successful write
- assert!(write_res.is_ok());
- let read_res = readv(reader, &mut iovecs[..]);
- assert!(read_res.is_ok());
- let read = read_res.ok().unwrap();
+ write(writer, &to_write).expect("write failed");
+ let read = readv(reader, &mut iovecs[..]).expect("read failed");
// Check whether we've read all data
assert_eq!(to_write.len(), read);
// Cccumulate data from iovecs
@@ -113,10 +100,8 @@ fn test_readv() {
assert_eq!(read_buf.len(), to_write.len());
// Check equality of written and read data
assert_eq!(&read_buf, &to_write);
- let close_res = close(reader);
- assert!(close_res.is_ok());
- let close_res = close(writer);
- assert!(close_res.is_ok());
+ close(reader).expect("couldn't close reader");
+ close(writer).expect("couldn't close writer");
}
#[test]
diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs
index 1a4a0f87..d472f1ec 100644
--- a/test/sys/test_wait.rs
+++ b/test/sys/test_wait.rs
@@ -167,17 +167,17 @@ mod ptrace {
Ok(WaitStatus::Stopped(child, SIGTRAP))
);
// We want to test a syscall stop and a PTRACE_EVENT stop
- assert!(ptrace::setoptions(
+ ptrace::setoptions(
child,
- Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT
+ Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT,
)
- .is_ok());
+ .expect("setoptions failed");
// First, stop on the next system call, which will be exit()
- assert!(ptrace::syscall(child, None).is_ok());
+ ptrace::syscall(child, None).expect("syscall failed");
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceSyscall(child)));
// Then get the ptrace event for the process exiting
- assert!(ptrace::cont(child, None).is_ok());
+ ptrace::cont(child, None).expect("cont failed");
assert_eq!(
waitpid(child, None),
Ok(WaitStatus::PtraceEvent(
@@ -187,7 +187,7 @@ mod ptrace {
))
);
// Finally get the normal wait() result, now that the process has exited
- assert!(ptrace::cont(child, None).is_ok());
+ ptrace::cont(child, None).expect("cont failed");
assert_eq!(waitpid(child, None), Ok(WaitStatus::Exited(child, 0)));
}
@@ -202,20 +202,20 @@ mod ptrace {
Ok(WaitStatus::PtraceEvent(child, SIGTRAP, 0)),
);
// We want to test a syscall stop and a PTRACE_EVENT stop
- assert!(ptrace::setoptions(
+ ptrace::setoptions(
child,
- Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT
+ Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT,
)
- .is_ok());
+ .expect("setopts failed");
// First, stop on the next system call, which will be exit()
- assert!(ptrace::syscall(child, None).is_ok());
+ ptrace::syscall(child, None).expect("syscall failed");
assert_eq!(
waitid(Id::Pid(child), WaitPidFlag::WEXITED),
Ok(WaitStatus::PtraceSyscall(child)),
);
// Then get the ptrace event for the process exiting
- assert!(ptrace::cont(child, None).is_ok());
+ ptrace::cont(child, None).expect("cont failed");
assert_eq!(
waitid(Id::Pid(child), WaitPidFlag::WEXITED),
Ok(WaitStatus::PtraceEvent(
@@ -225,7 +225,7 @@ mod ptrace {
)),
);
// Finally get the normal wait() result, now that the process has exited
- assert!(ptrace::cont(child, None).is_ok());
+ ptrace::cont(child, None).expect("cont failed");
assert_eq!(
waitid(Id::Pid(child), WaitPidFlag::WEXITED),
Ok(WaitStatus::Exited(child, 0)),
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index d4a12718..f4adee21 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -492,10 +492,8 @@ mod test_posix_fadvise {
fn test_success() {
let tmp = NamedTempFile::new().unwrap();
let fd = tmp.as_raw_fd();
- let res =
- posix_fadvise(fd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED);
-
- assert!(res.is_ok());
+ posix_fadvise(fd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED)
+ .expect("posix_fadvise failed");
}
#[test]
diff --git a/test/test_net.rs b/test/test_net.rs
index d1050c16..c44655a4 100644
--- a/test/test_net.rs
+++ b/test/test_net.rs
@@ -15,5 +15,5 @@ const LOOPBACK: &[u8] = b"loop";
#[test]
fn test_if_nametoindex() {
- assert!(if_nametoindex(LOOPBACK).is_ok());
+ if_nametoindex(LOOPBACK).expect("assertion failed");
}
diff --git a/test/test_stat.rs b/test/test_stat.rs
index de5a964e..1888c649 100644
--- a/test/test_stat.rs
+++ b/test/test_stat.rs
@@ -323,7 +323,7 @@ fn test_mkdirat_success_path() {
let dirfd =
fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty())
.unwrap();
- assert!((mkdirat(dirfd, filename, Mode::S_IRWXU)).is_ok());
+ mkdirat(dirfd, filename, Mode::S_IRWXU).expect("mkdirat failed");
assert!(Path::exists(&tempdir.path().join(filename)));
}
@@ -337,7 +337,7 @@ fn test_mkdirat_success_mode() {
let dirfd =
fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty())
.unwrap();
- assert!((mkdirat(dirfd, filename, Mode::S_IRWXU)).is_ok());
+ mkdirat(dirfd, filename, Mode::S_IRWXU).expect("mkdirat failed");
let permissions = fs::metadata(tempdir.path().join(filename))
.unwrap()
.permissions();
diff --git a/test/test_time.rs b/test/test_time.rs
index dc307e57..3e8af653 100644
--- a/test/test_time.rs
+++ b/test/test_time.rs
@@ -11,12 +11,12 @@ use nix::time::{clock_gettime, ClockId};
#[cfg(not(target_os = "redox"))]
#[test]
pub fn test_clock_getres() {
- assert!(nix::time::clock_getres(ClockId::CLOCK_REALTIME).is_ok());
+ nix::time::clock_getres(ClockId::CLOCK_REALTIME).expect("assertion failed");
}
#[test]
pub fn test_clock_gettime() {
- assert!(clock_gettime(ClockId::CLOCK_REALTIME).is_ok());
+ clock_gettime(ClockId::CLOCK_REALTIME).expect("assertion failed");
}
#[cfg(any(
@@ -29,18 +29,18 @@ pub fn test_clock_gettime() {
#[test]
pub fn test_clock_getcpuclockid() {
let clock_id = clock_getcpuclockid(nix::unistd::Pid::this()).unwrap();
- assert!(clock_gettime(clock_id).is_ok());
+ clock_gettime(clock_id).expect("assert failed");
}
#[cfg(not(target_os = "redox"))]
#[test]
pub fn test_clock_id_res() {
- assert!(ClockId::CLOCK_REALTIME.res().is_ok());
+ ClockId::CLOCK_REALTIME.res().expect("assert failed");
}
#[test]
pub fn test_clock_id_now() {
- assert!(ClockId::CLOCK_REALTIME.now().is_ok());
+ ClockId::CLOCK_REALTIME.now().expect("assert failed");
}
#[cfg(any(
@@ -52,7 +52,8 @@ pub fn test_clock_id_now() {
))]
#[test]
pub fn test_clock_id_pid_cpu_clock_id() {
- assert!(ClockId::pid_cpu_clock_id(nix::unistd::Pid::this())
+ ClockId::pid_cpu_clock_id(nix::unistd::Pid::this())
.map(ClockId::now)
- .is_ok());
+ .expect("assert failed")
+ .expect("assert failed");
}
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 38d31a3f..337ebe46 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -101,7 +101,7 @@ fn test_mkstemp() {
#[test]
fn test_mkstemp_directory() {
// mkstemp should fail if a directory is given
- assert!(mkstemp(&env::temp_dir()).is_err());
+ mkstemp(&env::temp_dir()).expect_err("assertion failed");
}
#[test]
@@ -121,7 +121,7 @@ fn test_mkfifo() {
#[cfg(not(target_os = "redox"))]
fn test_mkfifo_directory() {
// mkfifo should fail if a directory is given
- assert!(mkfifo(&env::temp_dir(), Mode::S_IRUSR).is_err());
+ mkfifo(&env::temp_dir(), Mode::S_IRUSR).expect_err("assertion failed");
}
#[test]
@@ -180,7 +180,8 @@ fn test_mkfifoat_directory_none() {
let _m = crate::CWD_LOCK.read();
// mkfifoat should fail if a directory is given
- assert!(mkfifoat(None, &env::temp_dir(), Mode::S_IRUSR).is_err());
+ mkfifoat(None, &env::temp_dir(), Mode::S_IRUSR)
+ .expect_err("assertion failed");
}
#[test]
@@ -198,7 +199,8 @@ fn test_mkfifoat_directory() {
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());
+ mkfifoat(Some(dirfd), mkfifoat_dir, Mode::S_IRUSR)
+ .expect_err("assertion failed");
}
#[test]
@@ -456,10 +458,10 @@ fn test_fchdir() {
let tmpdir_path = tmpdir.path().canonicalize().unwrap();
let tmpdir_fd = File::open(&tmpdir_path).unwrap().into_raw_fd();
- assert!(fchdir(tmpdir_fd).is_ok());
+ fchdir(tmpdir_fd).expect("assertion failed");
assert_eq!(getcwd().unwrap(), tmpdir_path);
- assert!(close(tmpdir_fd).is_ok());
+ close(tmpdir_fd).expect("assertion failed");
}
#[test]
@@ -469,7 +471,7 @@ fn test_getcwd() {
let tmpdir = tempdir().unwrap();
let tmpdir_path = tmpdir.path().canonicalize().unwrap();
- assert!(chdir(&tmpdir_path).is_ok());
+ chdir(&tmpdir_path).expect("assertion failed");
assert_eq!(getcwd().unwrap(), tmpdir_path);
// make path 500 chars longer so that buffer doubling in getcwd
@@ -480,9 +482,10 @@ fn test_getcwd() {
for _ in 0..5 {
let newdir = "a".repeat(100);
inner_tmp_dir.push(newdir);
- assert!(mkdir(inner_tmp_dir.as_path(), Mode::S_IRWXU).is_ok());
+ mkdir(inner_tmp_dir.as_path(), Mode::S_IRWXU)
+ .expect("assertion failed");
}
- assert!(chdir(inner_tmp_dir.as_path()).is_ok());
+ chdir(inner_tmp_dir.as_path()).expect("assertion failed");
assert_eq!(getcwd().unwrap(), inner_tmp_dir.as_path());
}
@@ -1166,7 +1169,8 @@ fn test_access_file_exists() {
let tempdir = 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());
+ access(&path, AccessFlags::R_OK | AccessFlags::W_OK)
+ .expect("assertion failed");
}
//Clippy false positive https://github.com/rust-lang/rust-clippy/issues/9111
@@ -1210,8 +1214,8 @@ fn test_setfsuid() {
let fuid = setfsuid(nobody.uid);
// trying to open the temporary file should fail with EACCES
let res = fs::File::open(&temp_path);
- assert!(res.is_err());
- assert_eq!(res.err().unwrap().kind(), io::ErrorKind::PermissionDenied);
+ let err = res.expect_err("assertion failed");
+ assert_eq!(err.kind(), io::ErrorKind::PermissionDenied);
// assert fuid actually changes
let prev_fuid = setfsuid(Uid::from_raw(-1i32 as u32));
@@ -1302,5 +1306,5 @@ fn test_getpeereid() {
))]
fn test_getpeereid_invalid_fd() {
// getpeereid is not POSIX, so error codes are inconsistent between different Unices.
- assert!(getpeereid(-1).is_err());
+ getpeereid(-1).expect_err("assertion failed");
}