mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
test: add test for nix::Error
conversions
This commit is contained in:
parent
df8ba87516
commit
990bb4224d
1 changed files with 26 additions and 0 deletions
|
@ -729,3 +729,29 @@ impl Display for ClapErrorWrapper {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use nix::errno::Errno;
|
||||||
|
use std::io::ErrorKind;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_nix_error_conversion() {
|
||||||
|
for (nix_error, expected_error_kind) in [
|
||||||
|
(Errno::EACCES, ErrorKind::PermissionDenied),
|
||||||
|
(Errno::ENOENT, ErrorKind::NotFound),
|
||||||
|
(Errno::EEXIST, ErrorKind::AlreadyExists),
|
||||||
|
] {
|
||||||
|
let error = UIoError::from(nix_error);
|
||||||
|
assert_eq!(expected_error_kind, error.inner.kind());
|
||||||
|
}
|
||||||
|
assert_eq!(
|
||||||
|
"test: Permission denied",
|
||||||
|
Err::<(), nix::Error>(Errno::EACCES)
|
||||||
|
.map_err_context(|| String::from("test"))
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue