test: s/assert!(.*) ==/assert_eq!\1,/

One case manually adjusted to `assert_matches!`.
reviewable/pr706/r2
Tamir Duberstein 1 year ago
parent 4c3219f754
commit 6f3cce75cf
No known key found for this signature in database

@ -403,16 +403,16 @@ mod tests {
let id1 = links.insert(l1).unwrap(); let id1 = links.insert(l1).unwrap();
let id2 = links.insert(l2).unwrap(); let id2 = links.insert(l2).unwrap();
assert!(*l1_detached.borrow() == 0); assert_eq!(*l1_detached.borrow(), 0);
assert!(*l2_detached.borrow() == 0); assert_eq!(*l2_detached.borrow(), 0);
assert!(links.remove(id1).is_ok()); assert!(links.remove(id1).is_ok());
assert!(*l1_detached.borrow() == 1); assert_eq!(*l1_detached.borrow(), 1);
assert!(*l2_detached.borrow() == 0); assert_eq!(*l2_detached.borrow(), 0);
assert!(links.remove(id2).is_ok()); assert!(links.remove(id2).is_ok());
assert!(*l1_detached.borrow() == 1); assert_eq!(*l1_detached.borrow(), 1);
assert!(*l2_detached.borrow() == 1); assert_eq!(*l2_detached.borrow(), 1);
} }
#[test] #[test]
@ -451,12 +451,12 @@ mod tests {
links.insert(l2).unwrap(); links.insert(l2).unwrap();
// manually remove one link // manually remove one link
assert!(links.remove(id1).is_ok()); assert!(links.remove(id1).is_ok());
assert!(*l1_detached.borrow() == 1); assert_eq!(*l1_detached.borrow(), 1);
assert!(*l2_detached.borrow() == 0); assert_eq!(*l2_detached.borrow(), 0);
} }
// remove the other on drop // remove the other on drop
assert!(*l1_detached.borrow() == 1); assert_eq!(*l1_detached.borrow(), 1);
assert!(*l2_detached.borrow() == 1); assert_eq!(*l2_detached.borrow(), 1);
} }
#[test] #[test]
@ -472,19 +472,19 @@ mod tests {
links.insert(l2).unwrap(); links.insert(l2).unwrap();
// manually forget one link // manually forget one link
let owned_l1 = links.forget(id1); let owned_l1 = links.forget(id1);
assert!(*l1_detached.borrow() == 0); assert_eq!(*l1_detached.borrow(), 0);
assert!(*l2_detached.borrow() == 0); assert_eq!(*l2_detached.borrow(), 0);
owned_l1.unwrap() owned_l1.unwrap()
}; };
// l2 is detached on `Drop`, but l1 is still alive // l2 is detached on `Drop`, but l1 is still alive
assert!(*l1_detached.borrow() == 0); assert_eq!(*l1_detached.borrow(), 0);
assert!(*l2_detached.borrow() == 1); assert_eq!(*l2_detached.borrow(), 1);
// manually detach l1 // manually detach l1
assert!(owned_l1.detach().is_ok()); assert!(owned_l1.detach().is_ok());
assert!(*l1_detached.borrow() == 1); assert_eq!(*l1_detached.borrow(), 1);
assert!(*l2_detached.borrow() == 1); assert_eq!(*l2_detached.borrow(), 1);
} }
#[test] #[test]

@ -96,7 +96,7 @@ fn set_kernel_buffer_element(bpf: &mut Bpf, bytes: &[u8]) {
fn result_bytes(bpf: &Bpf) -> Vec<u8> { fn result_bytes(bpf: &Bpf) -> Vec<u8> {
let m = Array::<_, TestResult>::try_from(bpf.map("RESULT").unwrap()).unwrap(); let m = Array::<_, TestResult>::try_from(bpf.map("RESULT").unwrap()).unwrap();
let result = m.get(&0, 0).unwrap(); let result = m.get(&0, 0).unwrap();
assert!(result.did_error == 0); assert_eq!(result.did_error, 0);
// assert that the buffer is always null terminated // assert that the buffer is always null terminated
assert_eq!(result.buf[result.len], 0); assert_eq!(result.buf[result.len], 0);
result.buf[..result.len].to_vec() result.buf[..result.len].to_vec()

@ -108,7 +108,7 @@ fn use_map_with_rbpf() {
} }
fn bpf_map_update_elem_multimap(map: u64, key: u64, value: u64, _: u64, _: u64) -> u64 { fn bpf_map_update_elem_multimap(map: u64, key: u64, value: u64, _: u64, _: u64) -> u64 {
assert!(map == 0xCAFE00 || map == 0xCAFE01); assert_matches!(map, 0xCAFE00 | 0xCAFE01);
let key = *unsafe { (key as usize as *const u32).as_ref().unwrap() }; let key = *unsafe { (key as usize as *const u32).as_ref().unwrap() };
let value = *unsafe { (value as usize as *const u64).as_ref().unwrap() }; let value = *unsafe { (value as usize as *const u64).as_ref().unwrap() };
assert_eq!(key, 0); assert_eq!(key, 0);

Loading…
Cancel
Save