Skip to content

fix clippy assertions_on_result_states #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");

Expand All @@ -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));
})
Expand All @@ -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));
})
Expand Down
9 changes: 6 additions & 3 deletions src/sys/signalfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/sys/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
14 changes: 7 additions & 7 deletions test/sys/test_aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/sys/test_epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion test/sys/test_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
2 changes: 1 addition & 1 deletion test/sys/test_termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
35 changes: 10 additions & 25 deletions test/sys/test_uio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down
24 changes: 12 additions & 12 deletions test/sys/test_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)));
}

Expand All @@ -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(
Expand All @@ -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)),
Expand Down
6 changes: 2 additions & 4 deletions test/test_fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion test/test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
4 changes: 2 additions & 2 deletions test/test_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand All @@ -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();
Expand Down
15 changes: 8 additions & 7 deletions test/test_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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");
}
Loading