test: Add unit tests for file handling and configuration merging (#7)

* test: Add unit tests for file handling and configuration merging

* test: Update IO error conversion test to use new error creation method
This commit is contained in:
Eli Peter 2025-06-24 23:38:32 +02:00 committed by GitHub
parent 8497800b13
commit 46c4732f6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 225 additions and 57 deletions

View file

@ -61,3 +61,37 @@ impl From<Box<dyn std::error::Error>> for NyxError {
NyxError::Msg(err.to_string())
}
}
#[test]
fn io_conversion_retains_message() {
let e = std::io::Error::other("boom!");
let n: NyxError = e.into();
assert!(matches!(n, NyxError::Io(_)));
assert!(n.to_string().contains("boom"));
}
#[test]
fn poison_conversion_maps_correct_variant() {
let lock = std::sync::Arc::new(std::sync::Mutex::new(()));
{
let lock2 = std::sync::Arc::clone(&lock);
std::thread::spawn(move || {
let _guard = lock2.lock().unwrap();
panic!("intentional poison the mutex");
})
.join()
.ok();
}
let poison = lock.lock().unwrap_err();
let nyx: NyxError = poison.into();
assert!(matches!(nyx, NyxError::Poison(_)));
}
#[test]
fn simple_string_into_msg() {
let nyx: NyxError = "plain msg".into();
assert!(matches!(nyx, NyxError::Msg(s) if s == "plain msg"));
}