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:
@@ -491,7 +491,7 @@ mod tests {
|
||||
let hv = crate::new().unwrap();
|
||||
let vm = hv.create_vm().unwrap();
|
||||
|
||||
assert!(KvmGicV3Its::new(&*vm, create_test_vgic_config()).is_ok());
|
||||
KvmGicV3Its::new(&*vm, create_test_vgic_config()).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -501,13 +501,10 @@ mod tests {
|
||||
let _ = vm.create_vcpu(0, None).unwrap();
|
||||
let gic = KvmGicV3Its::new(&*vm, create_test_vgic_config()).expect("Cannot create gic");
|
||||
|
||||
let res = get_dist_regs(&gic.device);
|
||||
assert!(res.is_ok());
|
||||
let state = res.unwrap();
|
||||
let state = get_dist_regs(&gic.device).unwrap();
|
||||
assert_eq!(state.len(), 568);
|
||||
|
||||
let res = set_dist_regs(&gic.device, &state);
|
||||
assert!(res.is_ok());
|
||||
set_dist_regs(&gic.device, &state).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -518,13 +515,11 @@ mod tests {
|
||||
let gic = KvmGicV3Its::new(&*vm, create_test_vgic_config()).expect("Cannot create gic");
|
||||
|
||||
let gicr_typer = vec![123];
|
||||
let res = get_redist_regs(&gic.device, &gicr_typer);
|
||||
assert!(res.is_ok());
|
||||
let state = res.unwrap();
|
||||
let state = get_redist_regs(&gic.device, &gicr_typer).unwrap();
|
||||
println!("{}", state.len());
|
||||
assert!(state.len() == 24);
|
||||
|
||||
assert!(set_redist_regs(&gic.device, &gicr_typer, &state).is_ok());
|
||||
set_redist_regs(&gic.device, &gicr_typer, &state).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -535,13 +530,11 @@ mod tests {
|
||||
let gic = KvmGicV3Its::new(&*vm, create_test_vgic_config()).expect("Cannot create gic");
|
||||
|
||||
let gicr_typer = vec![123];
|
||||
let res = get_icc_regs(&gic.device, &gicr_typer);
|
||||
assert!(res.is_ok());
|
||||
let state = res.unwrap();
|
||||
let state = get_icc_regs(&gic.device, &gicr_typer).unwrap();
|
||||
println!("{}", state.len());
|
||||
assert!(state.len() == 9);
|
||||
|
||||
assert!(set_icc_regs(&gic.device, &gicr_typer, &state).is_ok());
|
||||
set_icc_regs(&gic.device, &gicr_typer, &state).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -553,6 +546,6 @@ mod tests {
|
||||
.create_vgic(create_test_vgic_config())
|
||||
.expect("Cannot create gic");
|
||||
|
||||
assert!(gic.lock().unwrap().save_data_tables().is_ok());
|
||||
gic.lock().unwrap().save_data_tables().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user