mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Eliminate use of assert!((...).is_ok())
Asserting on .is_ok()/.is_err() leads to hard to debug failures (as if the test fails, it will only say "assertion failed: false". We replace these with `.unwrap()`, which also prints the exact error variant that was unexpectedly encountered (we can to this these days thanks to efforts to implement Display and Debug for our error types). If the assert!((...).is_ok()) was followed by an .unwrap() anyway, we just drop the assert. Inspired by and quoted from @roypat. Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
@@ -628,7 +628,7 @@ mod tests {
|
||||
let ctx = test_ctx.create_epoll_handler_context();
|
||||
|
||||
let _queue: Queue = Queue::new(256).unwrap();
|
||||
assert!(ctx.handler.signal_used_queue(0).is_ok());
|
||||
ctx.handler.signal_used_queue(0).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -711,10 +711,9 @@ mod tests {
|
||||
let mut epoll_helper =
|
||||
EpollHelper::new(&ctx.handler.kill_evt, &ctx.handler.pause_evt).unwrap();
|
||||
|
||||
assert!(
|
||||
ctx.handler.handle_event(&mut epoll_helper, &event).is_err(),
|
||||
"handle_event() should have failed"
|
||||
);
|
||||
ctx.handler
|
||||
.handle_event(&mut epoll_helper, &event)
|
||||
.expect_err("handle_event() should have failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,7 +763,7 @@ mod tests {
|
||||
ctx.guest_rxvq.dtable[0].len.set(0);
|
||||
|
||||
// The chain should've been processed, without employing the backend.
|
||||
assert!(ctx.handler.process_rx().is_ok());
|
||||
ctx.handler.process_rx().unwrap();
|
||||
assert_eq!(ctx.guest_rxvq.used.idx.get(), 1);
|
||||
assert_eq!(ctx.handler.backend.read().unwrap().rx_ok_cnt, 0);
|
||||
}
|
||||
@@ -781,10 +780,9 @@ mod tests {
|
||||
EpollHelper::new(&ctx.handler.kill_evt, &ctx.handler.pause_evt).unwrap();
|
||||
|
||||
assert_eq!(ctx.guest_rxvq.used.idx.get(), 0);
|
||||
assert!(
|
||||
ctx.handler.handle_event(&mut epoll_helper, &event).is_err(),
|
||||
"handle_event() should have failed"
|
||||
);
|
||||
ctx.handler
|
||||
.handle_event(&mut epoll_helper, &event)
|
||||
.expect_err("handle_event() should have failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -802,10 +800,10 @@ mod tests {
|
||||
EpollHelper::new(&ctx.handler.kill_evt, &ctx.handler.pause_evt).unwrap();
|
||||
|
||||
assert_eq!(ctx.guest_evvq.used.idx.get(), 0);
|
||||
assert!(
|
||||
ctx.handler.handle_event(&mut epoll_helper, &event).is_err(),
|
||||
"handle_event() should have failed"
|
||||
);
|
||||
|
||||
ctx.handler
|
||||
.handle_event(&mut epoll_helper, &event)
|
||||
.expect_err("handle_event() should have failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -824,7 +822,7 @@ mod tests {
|
||||
let event = epoll::Event::new(events, BACKEND_EVENT as u64);
|
||||
let mut epoll_helper =
|
||||
EpollHelper::new(&ctx.handler.kill_evt, &ctx.handler.pause_evt).unwrap();
|
||||
assert!(ctx.handler.handle_event(&mut epoll_helper, &event).is_ok());
|
||||
ctx.handler.handle_event(&mut epoll_helper, &event).unwrap();
|
||||
|
||||
// The backend should've received this event.
|
||||
assert_eq!(
|
||||
@@ -850,7 +848,7 @@ mod tests {
|
||||
let event = epoll::Event::new(events, BACKEND_EVENT as u64);
|
||||
let mut epoll_helper =
|
||||
EpollHelper::new(&ctx.handler.kill_evt, &ctx.handler.pause_evt).unwrap();
|
||||
assert!(ctx.handler.handle_event(&mut epoll_helper, &event).is_ok());
|
||||
ctx.handler.handle_event(&mut epoll_helper, &event).unwrap();
|
||||
|
||||
// The backend should've received this event.
|
||||
assert_eq!(
|
||||
@@ -874,9 +872,8 @@ mod tests {
|
||||
let mut epoll_helper =
|
||||
EpollHelper::new(&ctx.handler.kill_evt, &ctx.handler.pause_evt).unwrap();
|
||||
|
||||
assert!(
|
||||
ctx.handler.handle_event(&mut epoll_helper, &event).is_err(),
|
||||
"handle_event() should have failed"
|
||||
);
|
||||
ctx.handler
|
||||
.handle_event(&mut epoll_helper, &event)
|
||||
.expect_err("handle_event() should have failed");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user