mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-18 20:15:14 +02:00
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:
parent
8497800b13
commit
46c4732f6e
8 changed files with 225 additions and 57 deletions
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue