Skip to content

Commit a6ee63a

Browse files
committed
1 parent 854a546 commit a6ee63a

14 files changed

+74
-83
lines changed

src/sys/signal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ mod tests {
11891189
let mut test_mask = prev_mask;
11901190
test_mask.add(SIGUSR1);
11911191

1192-
assert!(test_mask.thread_set_mask().is_ok());
1192+
test_mask.thread_set_mask().expect("assertion failed");
11931193
let new_mask =
11941194
SigSet::thread_get_mask().expect("Failed to get new mask!");
11951195

@@ -1211,7 +1211,7 @@ mod tests {
12111211
let mut mask = SigSet::empty();
12121212
mask.add(SIGUSR1);
12131213

1214-
assert!(mask.thread_block().is_ok());
1214+
mask.thread_block().expect("assertion failed");
12151215

12161216
assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR1));
12171217
})
@@ -1226,7 +1226,7 @@ mod tests {
12261226
let mut mask = SigSet::empty();
12271227
mask.add(SIGUSR1);
12281228

1229-
assert!(mask.thread_unblock().is_ok());
1229+
mask.thread_unblock().expect("assertion failed");
12301230

12311231
assert!(!SigSet::thread_get_mask().unwrap().contains(SIGUSR1));
12321232
})

src/sys/signalfd.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,17 @@ mod tests {
148148
fn create_signalfd() {
149149
let mask = SigSet::empty();
150150
let fd = SignalFd::new(&mask);
151-
assert!(fd.is_ok());
151+
fd.expect("assert failed");
152152
}
153153

154154
#[test]
155155
fn create_signalfd_with_opts() {
156156
let mask = SigSet::empty();
157-
let fd = SignalFd::with_flags(&mask, SfdFlags::SFD_CLOEXEC | SfdFlags::SFD_NONBLOCK);
158-
assert!(fd.is_ok());
157+
let fd = SignalFd::with_flags(
158+
&mask,
159+
SfdFlags::SFD_CLOEXEC | SfdFlags::SFD_NONBLOCK,
160+
);
161+
fd.expect("assert failed");
159162
}
160163

161164
#[test]

src/sys/termios.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,8 @@ mod test {
11071107
fn try_from() {
11081108
assert_eq!(Ok(BaudRate::B0), BaudRate::try_from(libc::B0));
11091109
#[cfg(not(target_os = "haiku"))]
1110-
assert!(BaudRate::try_from(999999999).is_err());
1110+
BaudRate::try_from(999999999).expect_err("assertion failed");
11111111
#[cfg(target_os = "haiku")]
1112-
assert!(BaudRate::try_from(99).is_err());
1112+
BaudRate::try_from(99).expect_err("assertion failed");
11131113
}
11141114
}

test/sys/test_aio.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mod aio_fsync {
8585
SigevNotify::SigevNone,
8686
));
8787
let err = aiof.as_mut().submit();
88-
assert!(err.is_err());
88+
err.expect_err("assertion failed");
8989
}
9090

9191
#[test]
@@ -102,7 +102,7 @@ mod aio_fsync {
102102
SigevNotify::SigevNone,
103103
));
104104
let err = aiof.as_mut().submit();
105-
assert!(err.is_ok());
105+
err.expect("assert failed");
106106
poll_aio!(&mut aiof).unwrap();
107107
aiof.as_mut().aio_return().unwrap();
108108
}
@@ -149,7 +149,7 @@ mod aio_read {
149149
aior.as_mut().submit().unwrap();
150150

151151
let cancelstat = aior.as_mut().cancel();
152-
assert!(cancelstat.is_ok());
152+
cancelstat.expect("assert failed");
153153

154154
// Wait for aiow to complete, but don't care whether it succeeded
155155
let _ = poll_aio!(&mut aior);
@@ -174,7 +174,7 @@ mod aio_read {
174174
0, //priority
175175
SigevNotify::SigevNone,
176176
));
177-
assert!(aior.as_mut().submit().is_err());
177+
aior.as_mut().submit().expect_err("assertion failed");
178178
}
179179

180180
// Test a simple aio operation with no completion notification. We must
@@ -342,7 +342,7 @@ mod aio_write {
342342
assert!(err == Ok(()) || err == Err(Errno::EINPROGRESS));
343343

344344
let cancelstat = aiow.as_mut().cancel();
345-
assert!(cancelstat.is_ok());
345+
cancelstat.expect("assert failed");
346346

347347
// Wait for aiow to complete, but don't care whether it succeeded
348348
let _ = poll_aio!(&mut aiow);
@@ -426,7 +426,7 @@ mod aio_write {
426426
0, //priority
427427
SigevNotify::SigevNone,
428428
));
429-
assert!(aiow.as_mut().submit().is_err());
429+
aiow.as_mut().submit().expect_err("assertion failed");
430430
// Dropping the AioWrite at this point should not panic
431431
}
432432
}
@@ -565,7 +565,7 @@ fn test_aio_cancel_all() {
565565
assert!(err == Ok(()) || err == Err(Errno::EINPROGRESS));
566566

567567
let cancelstat = aio_cancel_all(f.as_raw_fd());
568-
assert!(cancelstat.is_ok());
568+
cancelstat.expect("assert failed");
569569

570570
// Wait for aiocb to complete, but don't care whether it succeeded
571571
let _ = poll_aio!(&mut aiocb);

test/sys/test_epoll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use nix::sys::epoll::{EpollCreateFlags, EpollEvent, EpollFlags, EpollOp};
66
pub fn test_epoll_errno() {
77
let efd = epoll_create1(EpollCreateFlags::empty()).unwrap();
88
let result = epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None);
9-
assert!(result.is_err());
9+
result.expect_err("assertion failed");
1010
assert_eq!(result.unwrap_err(), Errno::ENOENT);
1111

1212
let result = epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, None);
13-
assert!(result.is_err());
13+
result.expect_err("assertion failed");
1414
assert_eq!(result.unwrap_err(), Errno::EINVAL);
1515
}
1616

test/sys/test_socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub fn test_addr_equality_path() {
204204
pub fn test_abstract_sun_path_too_long() {
205205
let name = String::from("nix\0abstract\0tesnix\0abstract\0tesnix\0abstract\0tesnix\0abstract\0tesnix\0abstract\0testttttnix\0abstract\0test\0make\0sure\0this\0is\0long\0enough");
206206
let addr = UnixAddr::new_abstract(name.as_bytes());
207-
assert!(addr.is_err());
207+
addr.expect_err("assertion failed");
208208
}
209209

210210
#[cfg(any(target_os = "android", target_os = "linux"))]

test/sys/test_termios.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn test_tcgetattr_pty() {
2222
let _m = crate::PTSNAME_MTX.lock();
2323

2424
let pty = openpty(None, None).expect("openpty failed");
25-
assert!(termios::tcgetattr(pty.slave).is_ok());
25+
termios::tcgetattr(pty.slave).expect("assert failed");
2626
close(pty.master).expect("closing the master failed");
2727
close(pty.slave).expect("closing the slave failed");
2828
}

test/sys/test_uio.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,22 @@ fn test_writev() {
4141
consumed += slice_len;
4242
}
4343
let pipe_res = pipe();
44-
assert!(pipe_res.is_ok());
45-
let (reader, writer) = pipe_res.ok().unwrap();
44+
let (reader, writer) = pipe_res.expect("Couldn't create pipe");
4645
// FileDesc will close its filedesc (reader).
4746
let mut read_buf: Vec<u8> = iter::repeat(0u8).take(128 * 16).collect();
4847
// Blocking io, should write all data.
4948
let write_res = writev(writer, &iovecs);
50-
// Successful write
51-
assert!(write_res.is_ok());
52-
let written = write_res.ok().unwrap();
49+
let written = write_res.expect("couldn't write");
5350
// Check whether we written all data
5451
assert_eq!(to_write.len(), written);
5552
let read_res = read(reader, &mut read_buf[..]);
56-
// Successful read
57-
assert!(read_res.is_ok());
58-
let read = read_res.ok().unwrap() as usize;
53+
let read = read_res.expect("couldn't read");
5954
// Check we have read as much as we written
6055
assert_eq!(read, written);
6156
// Check equality of written and read data
6257
assert_eq!(&to_write, &read_buf);
63-
let close_res = close(writer);
64-
assert!(close_res.is_ok());
65-
let close_res = close(reader);
66-
assert!(close_res.is_ok());
58+
close(writer).expect("closed writer");
59+
close(reader).expect("closed reader");
6760
}
6861

6962
#[test]
@@ -92,16 +85,10 @@ fn test_readv() {
9285
for v in &mut storage {
9386
iovecs.push(IoSliceMut::new(&mut v[..]));
9487
}
95-
let pipe_res = pipe();
96-
assert!(pipe_res.is_ok());
97-
let (reader, writer) = pipe_res.ok().unwrap();
88+
let (reader, writer) = pipe().expect("couldn't create pipe");
9889
// Blocking io, should write all data.
99-
let write_res = write(writer, &to_write);
100-
// Successful write
101-
assert!(write_res.is_ok());
102-
let read_res = readv(reader, &mut iovecs[..]);
103-
assert!(read_res.is_ok());
104-
let read = read_res.ok().unwrap();
90+
write(writer, &to_write).expect("write failed");
91+
let read = readv(reader, &mut iovecs[..]).expect("read failed");
10592
// Check whether we've read all data
10693
assert_eq!(to_write.len(), read);
10794
// Cccumulate data from iovecs
@@ -113,10 +100,8 @@ fn test_readv() {
113100
assert_eq!(read_buf.len(), to_write.len());
114101
// Check equality of written and read data
115102
assert_eq!(&read_buf, &to_write);
116-
let close_res = close(reader);
117-
assert!(close_res.is_ok());
118-
let close_res = close(writer);
119-
assert!(close_res.is_ok());
103+
close(reader).expect("couldn't close reader");
104+
close(writer).expect("couldn't close writer");
120105
}
121106

122107
#[test]

test/sys/test_wait.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,17 @@ mod ptrace {
167167
Ok(WaitStatus::Stopped(child, SIGTRAP))
168168
);
169169
// We want to test a syscall stop and a PTRACE_EVENT stop
170-
assert!(ptrace::setoptions(
170+
ptrace::setoptions(
171171
child,
172-
Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT
172+
Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT,
173173
)
174-
.is_ok());
174+
.expect("setoptions failed");
175175

176176
// First, stop on the next system call, which will be exit()
177-
assert!(ptrace::syscall(child, None).is_ok());
177+
ptrace::syscall(child, None).expect("syscall failed");
178178
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceSyscall(child)));
179179
// Then get the ptrace event for the process exiting
180-
assert!(ptrace::cont(child, None).is_ok());
180+
ptrace::cont(child, None).expect("cont failed");
181181
assert_eq!(
182182
waitpid(child, None),
183183
Ok(WaitStatus::PtraceEvent(
@@ -187,7 +187,7 @@ mod ptrace {
187187
))
188188
);
189189
// Finally get the normal wait() result, now that the process has exited
190-
assert!(ptrace::cont(child, None).is_ok());
190+
ptrace::cont(child, None).expect("cont failed");
191191
assert_eq!(waitpid(child, None), Ok(WaitStatus::Exited(child, 0)));
192192
}
193193

@@ -202,20 +202,20 @@ mod ptrace {
202202
Ok(WaitStatus::PtraceEvent(child, SIGTRAP, 0)),
203203
);
204204
// We want to test a syscall stop and a PTRACE_EVENT stop
205-
assert!(ptrace::setoptions(
205+
ptrace::setoptions(
206206
child,
207-
Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT
207+
Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT,
208208
)
209-
.is_ok());
209+
.expect("setopts failed");
210210

211211
// First, stop on the next system call, which will be exit()
212-
assert!(ptrace::syscall(child, None).is_ok());
212+
ptrace::syscall(child, None).expect("syscall failed");
213213
assert_eq!(
214214
waitid(Id::Pid(child), WaitPidFlag::WEXITED),
215215
Ok(WaitStatus::PtraceSyscall(child)),
216216
);
217217
// Then get the ptrace event for the process exiting
218-
assert!(ptrace::cont(child, None).is_ok());
218+
ptrace::cont(child, None).expect("cont failed");
219219
assert_eq!(
220220
waitid(Id::Pid(child), WaitPidFlag::WEXITED),
221221
Ok(WaitStatus::PtraceEvent(
@@ -225,7 +225,7 @@ mod ptrace {
225225
)),
226226
);
227227
// Finally get the normal wait() result, now that the process has exited
228-
assert!(ptrace::cont(child, None).is_ok());
228+
ptrace::cont(child, None).expect("cont failed");
229229
assert_eq!(
230230
waitid(Id::Pid(child), WaitPidFlag::WEXITED),
231231
Ok(WaitStatus::Exited(child, 0)),

test/test_fcntl.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,8 @@ mod test_posix_fadvise {
492492
fn test_success() {
493493
let tmp = NamedTempFile::new().unwrap();
494494
let fd = tmp.as_raw_fd();
495-
let res =
496-
posix_fadvise(fd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED);
497-
498-
assert!(res.is_ok());
495+
posix_fadvise(fd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED)
496+
.expect("posix_fadvise failed");
499497
}
500498

501499
#[test]

test/test_net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ const LOOPBACK: &[u8] = b"loop";
1515

1616
#[test]
1717
fn test_if_nametoindex() {
18-
assert!(if_nametoindex(LOOPBACK).is_ok());
18+
if_nametoindex(LOOPBACK).expect("assertion failed");
1919
}

test/test_stat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ fn test_mkdirat_success_path() {
323323
let dirfd =
324324
fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty())
325325
.unwrap();
326-
assert!((mkdirat(dirfd, filename, Mode::S_IRWXU)).is_ok());
326+
mkdirat(dirfd, filename, Mode::S_IRWXU).expect("mkdirat failed");
327327
assert!(Path::exists(&tempdir.path().join(filename)));
328328
}
329329

@@ -337,7 +337,7 @@ fn test_mkdirat_success_mode() {
337337
let dirfd =
338338
fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty())
339339
.unwrap();
340-
assert!((mkdirat(dirfd, filename, Mode::S_IRWXU)).is_ok());
340+
mkdirat(dirfd, filename, Mode::S_IRWXU).expect("mkdirat failed");
341341
let permissions = fs::metadata(tempdir.path().join(filename))
342342
.unwrap()
343343
.permissions();

test/test_time.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use nix::time::{clock_gettime, ClockId};
1111
#[cfg(not(target_os = "redox"))]
1212
#[test]
1313
pub fn test_clock_getres() {
14-
assert!(nix::time::clock_getres(ClockId::CLOCK_REALTIME).is_ok());
14+
nix::time::clock_getres(ClockId::CLOCK_REALTIME).expect("assertion failed");
1515
}
1616

1717
#[test]
1818
pub fn test_clock_gettime() {
19-
assert!(clock_gettime(ClockId::CLOCK_REALTIME).is_ok());
19+
clock_gettime(ClockId::CLOCK_REALTIME).expect("assertion failed");
2020
}
2121

2222
#[cfg(any(
@@ -29,18 +29,18 @@ pub fn test_clock_gettime() {
2929
#[test]
3030
pub fn test_clock_getcpuclockid() {
3131
let clock_id = clock_getcpuclockid(nix::unistd::Pid::this()).unwrap();
32-
assert!(clock_gettime(clock_id).is_ok());
32+
clock_gettime(clock_id).expect("assert failed");
3333
}
3434

3535
#[cfg(not(target_os = "redox"))]
3636
#[test]
3737
pub fn test_clock_id_res() {
38-
assert!(ClockId::CLOCK_REALTIME.res().is_ok());
38+
ClockId::CLOCK_REALTIME.res().expect("assert failed");
3939
}
4040

4141
#[test]
4242
pub fn test_clock_id_now() {
43-
assert!(ClockId::CLOCK_REALTIME.now().is_ok());
43+
ClockId::CLOCK_REALTIME.now().expect("assert failed");
4444
}
4545

4646
#[cfg(any(
@@ -52,7 +52,8 @@ pub fn test_clock_id_now() {
5252
))]
5353
#[test]
5454
pub fn test_clock_id_pid_cpu_clock_id() {
55-
assert!(ClockId::pid_cpu_clock_id(nix::unistd::Pid::this())
55+
ClockId::pid_cpu_clock_id(nix::unistd::Pid::this())
5656
.map(ClockId::now)
57-
.is_ok());
57+
.expect("assert failed")
58+
.expect("assert failed");
5859
}

0 commit comments

Comments
 (0)