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);
});
```
reviewable/pr656/r1
Tamir Duberstein 2 years ago
parent 76ad93268f
commit 50b39a71ae
No known key found for this signature in database

@ -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]

@ -1486,7 +1486,7 @@ pub fn copy_instructions(data: &[u8]) -> Result<Vec<bpf_insn>, ParseError> {
#[cfg(test)]
mod tests {
use alloc::vec;
use matches::assert_matches;
use assert_matches::assert_matches;
use object::Endianness;
use super::*;

@ -2,7 +2,7 @@
name = "aya"
version = "0.11.0"
description = "An eBPF library with a focus on developer experience and operability."
keywords = ["ebpf", "bpf", "linux", "kernel"]
keywords = ["bpf", "ebpf", "kernel", "linux"]
license = "MIT OR Apache-2.0"
authors = ["The Aya Contributors"]
repository = "https://github.com/aya-rs/aya"
@ -19,30 +19,30 @@ lazy_static = "1"
libc = { version = "0.2.105" }
log = "0.4"
object = { version = "0.31", default-features = false, features = [
"std",
"read_core",
"elf",
"read_core",
"std",
] }
parking_lot = { version = "0.12.0", features = ["send_guard"] }
text_io = "0.1.12"
thiserror = "1"
tokio = { version = "1.24.0", features = [
"macros",
"net",
"rt",
"rt-multi-thread",
"net",
], optional = true }
[dev-dependencies]
assert_matches = "1.5.0"
futures = { version = "0.3.12", default-features = false, features = ["std"] }
matches = "0.1.8"
[features]
default = []
async = []
async_tokio = ["tokio", "async"]
async_std = ["async-io", "async"]
async_tokio = ["async", "tokio"]
async_std = ["async", "async-io"]
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs", "-D", "warnings"]
rustdoc-args = ["--cfg", "-D", "docsrs", "warnings"]

@ -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 {

@ -107,8 +107,8 @@ impl<T: Borrow<MapData>, K: Pod, V: Pod> IterableMap<K, V> for HashMap<T, K, V>
mod tests {
use std::io;
use assert_matches::assert_matches;
use libc::{EFAULT, ENOENT};
use matches::assert_matches;
use crate::{
bpf_map_def,

@ -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 {

@ -842,8 +842,8 @@ impl<T: Pod> Deref for PerCpuValues<T> {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use libc::EFAULT;
use matches::assert_matches;
use crate::{
bpf_map_def,

@ -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;

@ -357,7 +357,7 @@ pub enum LinkError {
#[cfg(test)]
mod tests {
use matches::assert_matches;
use assert_matches::assert_matches;
use std::{cell::RefCell, env, fs::File, mem, os::unix::io::AsRawFd, rc::Rc};
use crate::{programs::ProgramError, sys::override_syscall};

@ -6,16 +6,16 @@ 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 = [
"std",
"read_core",
"elf",
"read_core",
"std",
] }
rbpf = "0.2.0"
tokio = { version = "1.24", default-features = false, features = ["time"] }

@ -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 { .. }
);

Loading…
Cancel
Save