assertions: use assert_eq! where possible

Using `assert_eq!` instead of `assert!` has the advantage that when the
assertion fails, the debug representation of both sides will be shown,
which can provide more information about the failure than only seeing
that the assertion failed.

Part of #12336
This commit is contained in:
Daniel Rainer
2026-01-16 19:12:12 +01:00
committed by Johannes Altmanninger
parent 939fa25a5b
commit 8718d62b11
33 changed files with 138 additions and 99 deletions

View File

@@ -269,7 +269,10 @@ pub fn next(&mut self) -> Option<io::Result<&DirEntry>> {
};
// dent.d_name is c_char; pretend it's u8.
assert!(std::mem::size_of::<libc::c_char>() == std::mem::size_of::<u8>());
assert_eq!(
std::mem::size_of::<libc::c_char>(),
std::mem::size_of::<u8>()
);
// Do not rely on `libc::dirent::d_name.len()` as dirent names may exceed
// the nominal buffer size; instead use the terminating nul byte.
@@ -463,8 +466,9 @@ fn test_dir_iter() {
}
// If we have a fast type, it should be correct.
assert!(entry.fast_type().is_none() || entry.fast_type() == expected);
assert!(
entry.check_type() == expected,
assert_eq!(
entry.check_type(),
expected,
"Wrong type for {}. Expected {:?}, got {:?}",
entry.name,
expected,

View File

@@ -685,7 +685,7 @@ fn test_wwrite_to_fd() {
input.len(),
)
};
assert!(usize::try_from(read_amt).unwrap() == input.len());
assert_eq!(usize::try_from(read_amt).unwrap(), input.len());
assert_eq!(&contents, &input);
}
}