From 961f45da37616b912d2d4ed594036369f3f8285b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 14 Jul 2023 10:40:07 -0400 Subject: [PATCH] Replace matches with assert_matches The matches crate has been archived now that `matches!` is in std. However `assert_matches!` is still unstable in std, and the assert_matches crate provides a more expressive form: ``` assert_matches!(foo, Ok(bar) => { assert_eq!(bar, baz); }); ``` --- aya-obj/Cargo.toml | 9 ++++++--- aya-obj/src/obj.rs | 2 +- aya/Cargo.toml | 2 +- aya/src/maps/bloom_filter.rs | 2 +- aya/src/maps/hash_map/hash_map.rs | 2 +- aya/src/maps/lpm_trie.rs | 2 +- aya/src/maps/mod.rs | 2 +- aya/src/maps/perf/perf_buffer.rs | 2 +- aya/src/programs/links.rs | 2 +- test/integration-test/Cargo.toml | 2 +- test/integration-test/src/tests/rbpf.rs | 4 ++-- 11 files changed, 17 insertions(+), 14 deletions(-) diff --git a/aya-obj/Cargo.toml b/aya-obj/Cargo.toml index d2a5fb44..305e6008 100644 --- a/aya-obj/Cargo.toml +++ b/aya-obj/Cargo.toml @@ -2,7 +2,7 @@ name = "aya-obj" version = "0.1.0" description = "An eBPF object file parsing library with BTF and relocation support." -keywords = ["ebpf", "bpf", "btf", "elf", "object"] +keywords = ["bpf", "btf", "ebpf", "elf", "object"] license = "MIT OR Apache-2.0" authors = ["The Aya Contributors"] repository = "https://github.com/aya-rs/aya" @@ -13,13 +13,16 @@ edition = "2021" [dependencies] bytes = "1" log = "0.4" -object = { version = "0.31", default-features = false, features = ["read_core", "elf"] } +object = { version = "0.31", default-features = false, features = [ + "elf", + "read_core", +] } hashbrown = { version = "0.14" } thiserror = { version = "1", default-features = false } core-error = { version = "0.0.0" } [dev-dependencies] -matches = "0.1.8" +assert_matches = "1.5.0" rbpf = "0.2.0" [features] diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index d3ccb265..3c5ff126 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -1486,7 +1486,7 @@ pub fn copy_instructions(data: &[u8]) -> Result, ParseError> { #[cfg(test)] mod tests { use alloc::vec; - use matches::assert_matches; + use assert_matches::assert_matches; use object::Endianness; use super::*; diff --git a/aya/Cargo.toml b/aya/Cargo.toml index 28054e44..75980470 100644 --- a/aya/Cargo.toml +++ b/aya/Cargo.toml @@ -29,8 +29,8 @@ thiserror = "1" tokio = { version = "1.24.0", features = ["rt"], optional = true } [dev-dependencies] +assert_matches = "1.5.0" futures = { version = "0.3.12", default-features = false, features = ["std"] } -matches = "0.1.8" tempfile = "3" [features] diff --git a/aya/src/maps/bloom_filter.rs b/aya/src/maps/bloom_filter.rs index 315fe7d4..6135da5b 100644 --- a/aya/src/maps/bloom_filter.rs +++ b/aya/src/maps/bloom_filter.rs @@ -88,8 +88,8 @@ mod tests { obj::{self, maps::LegacyMap, BpfSectionKind}, sys::{override_syscall, SysResult, Syscall}, }; + use assert_matches::assert_matches; use libc::{EFAULT, ENOENT}; - use matches::assert_matches; use std::io; fn new_obj_map() -> obj::Map { diff --git a/aya/src/maps/hash_map/hash_map.rs b/aya/src/maps/hash_map/hash_map.rs index b37e5c8f..34f0b851 100644 --- a/aya/src/maps/hash_map/hash_map.rs +++ b/aya/src/maps/hash_map/hash_map.rs @@ -107,8 +107,8 @@ impl, K: Pod, V: Pod> IterableMap for HashMap mod tests { use std::io; + use assert_matches::assert_matches; use libc::{EFAULT, ENOENT}; - use matches::assert_matches; use crate::{ bpf_map_def, diff --git a/aya/src/maps/lpm_trie.rs b/aya/src/maps/lpm_trie.rs index f2fb10e3..b2e21e88 100644 --- a/aya/src/maps/lpm_trie.rs +++ b/aya/src/maps/lpm_trie.rs @@ -207,8 +207,8 @@ mod tests { obj::{self, maps::LegacyMap, BpfSectionKind}, sys::{override_syscall, SysResult, Syscall}, }; + use assert_matches::assert_matches; use libc::{EFAULT, ENOENT}; - use matches::assert_matches; use std::{io, mem, net::Ipv4Addr}; fn new_obj_map() -> obj::Map { diff --git a/aya/src/maps/mod.rs b/aya/src/maps/mod.rs index 7a455861..fca42110 100644 --- a/aya/src/maps/mod.rs +++ b/aya/src/maps/mod.rs @@ -842,8 +842,8 @@ impl Deref for PerCpuValues { #[cfg(test)] mod tests { + use assert_matches::assert_matches; use libc::EFAULT; - use matches::assert_matches; use crate::{ bpf_map_def, diff --git a/aya/src/maps/perf/perf_buffer.rs b/aya/src/maps/perf/perf_buffer.rs index c5b47e3a..e32be94d 100644 --- a/aya/src/maps/perf/perf_buffer.rs +++ b/aya/src/maps/perf/perf_buffer.rs @@ -319,7 +319,7 @@ mod tests { generated::perf_event_mmap_page, sys::{override_syscall, Syscall, TEST_MMAP_RET}, }; - use matches::assert_matches; + use assert_matches::assert_matches; use std::{fmt::Debug, mem}; const PAGE_SIZE: usize = 4096; diff --git a/aya/src/programs/links.rs b/aya/src/programs/links.rs index 1bfc6d0b..0cd9420d 100644 --- a/aya/src/programs/links.rs +++ b/aya/src/programs/links.rs @@ -353,7 +353,7 @@ pub enum LinkError { #[cfg(test)] mod tests { - use matches::assert_matches; + use assert_matches::assert_matches; use std::{cell::RefCell, fs::File, mem, os::unix::io::AsRawFd, rc::Rc}; use tempfile::tempdir; diff --git a/test/integration-test/Cargo.toml b/test/integration-test/Cargo.toml index 8fb11bda..a606ee1b 100644 --- a/test/integration-test/Cargo.toml +++ b/test/integration-test/Cargo.toml @@ -6,12 +6,12 @@ publish = false [dependencies] anyhow = "1" +assert_matches = "1.5.0" aya = { path = "../../aya" } aya-log = { path = "../../aya-log" } aya-obj = { path = "../../aya-obj" } libc = { version = "0.2.105" } log = "0.4" -matches = "0.1.8" object = { version = "0.31", default-features = false, features = [ "elf", "read_core", diff --git a/test/integration-test/src/tests/rbpf.rs b/test/integration-test/src/tests/rbpf.rs index 1f2fe2cb..790b2fdc 100644 --- a/test/integration-test/src/tests/rbpf.rs +++ b/test/integration-test/src/tests/rbpf.rs @@ -8,7 +8,7 @@ fn run_with_rbpf() { let object = Object::parse(crate::PASS).unwrap(); assert_eq!(object.programs.len(), 1); - matches::assert_matches!(object.programs["pass"].section, ProgramSection::Xdp { .. }); + assert_matches::assert_matches!(object.programs["pass"].section, ProgramSection::Xdp { .. }); assert_eq!(object.programs["pass"].section.name(), "pass"); let instructions = &object @@ -35,7 +35,7 @@ fn use_map_with_rbpf() { let mut object = Object::parse(crate::MULTIMAP_BTF).unwrap(); assert_eq!(object.programs.len(), 1); - matches::assert_matches!( + assert_matches::assert_matches!( object.programs["tracepoint"].section, ProgramSection::TracePoint { .. } );