From 6f3cce75cf11af27a9267dd88a688fc24e6b17b5 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 1 Aug 2023 11:06:48 -0400 Subject: [PATCH] test: s/assert!(.*) ==/assert_eq!\1,/ One case manually adjusted to `assert_matches!`. --- aya/src/programs/links.rs | 32 +++++++++---------- .../src/tests/bpf_probe_read.rs | 2 +- test/integration-test/src/tests/rbpf.rs | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/aya/src/programs/links.rs b/aya/src/programs/links.rs index debe7b49..2e727612 100644 --- a/aya/src/programs/links.rs +++ b/aya/src/programs/links.rs @@ -403,16 +403,16 @@ mod tests { let id1 = links.insert(l1).unwrap(); let id2 = links.insert(l2).unwrap(); - assert!(*l1_detached.borrow() == 0); - assert!(*l2_detached.borrow() == 0); + assert_eq!(*l1_detached.borrow(), 0); + assert_eq!(*l2_detached.borrow(), 0); assert!(links.remove(id1).is_ok()); - assert!(*l1_detached.borrow() == 1); - assert!(*l2_detached.borrow() == 0); + assert_eq!(*l1_detached.borrow(), 1); + assert_eq!(*l2_detached.borrow(), 0); assert!(links.remove(id2).is_ok()); - assert!(*l1_detached.borrow() == 1); - assert!(*l2_detached.borrow() == 1); + assert_eq!(*l1_detached.borrow(), 1); + assert_eq!(*l2_detached.borrow(), 1); } #[test] @@ -451,12 +451,12 @@ mod tests { links.insert(l2).unwrap(); // manually remove one link assert!(links.remove(id1).is_ok()); - assert!(*l1_detached.borrow() == 1); - assert!(*l2_detached.borrow() == 0); + assert_eq!(*l1_detached.borrow(), 1); + assert_eq!(*l2_detached.borrow(), 0); } // remove the other on drop - assert!(*l1_detached.borrow() == 1); - assert!(*l2_detached.borrow() == 1); + assert_eq!(*l1_detached.borrow(), 1); + assert_eq!(*l2_detached.borrow(), 1); } #[test] @@ -472,19 +472,19 @@ mod tests { links.insert(l2).unwrap(); // manually forget one link let owned_l1 = links.forget(id1); - assert!(*l1_detached.borrow() == 0); - assert!(*l2_detached.borrow() == 0); + assert_eq!(*l1_detached.borrow(), 0); + assert_eq!(*l2_detached.borrow(), 0); owned_l1.unwrap() }; // l2 is detached on `Drop`, but l1 is still alive - assert!(*l1_detached.borrow() == 0); - assert!(*l2_detached.borrow() == 1); + assert_eq!(*l1_detached.borrow(), 0); + assert_eq!(*l2_detached.borrow(), 1); // manually detach l1 assert!(owned_l1.detach().is_ok()); - assert!(*l1_detached.borrow() == 1); - assert!(*l2_detached.borrow() == 1); + assert_eq!(*l1_detached.borrow(), 1); + assert_eq!(*l2_detached.borrow(), 1); } #[test] diff --git a/test/integration-test/src/tests/bpf_probe_read.rs b/test/integration-test/src/tests/bpf_probe_read.rs index 22c3e9b1..b2ceb6d1 100644 --- a/test/integration-test/src/tests/bpf_probe_read.rs +++ b/test/integration-test/src/tests/bpf_probe_read.rs @@ -96,7 +96,7 @@ fn set_kernel_buffer_element(bpf: &mut Bpf, bytes: &[u8]) { fn result_bytes(bpf: &Bpf) -> Vec { let m = Array::<_, TestResult>::try_from(bpf.map("RESULT").unwrap()).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_eq!(result.buf[result.len], 0); result.buf[..result.len].to_vec() diff --git a/test/integration-test/src/tests/rbpf.rs b/test/integration-test/src/tests/rbpf.rs index d29ec66e..1d906ba7 100644 --- a/test/integration-test/src/tests/rbpf.rs +++ b/test/integration-test/src/tests/rbpf.rs @@ -108,7 +108,7 @@ fn use_map_with_rbpf() { } 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 value = *unsafe { (value as usize as *const u64).as_ref().unwrap() }; assert_eq!(key, 0);