From 48aaedad542b9c6cbdc85d22517cd0d151f38443 Mon Sep 17 00:00:00 2001 From: Mica White Date: Sun, 1 Dec 2024 15:28:44 -0500 Subject: Unit testing --- src/poisonable.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/poisonable.rs') diff --git a/src/poisonable.rs b/src/poisonable.rs index 6cc234e..d664291 100644 --- a/src/poisonable.rs +++ b/src/poisonable.rs @@ -1,8 +1,6 @@ use std::marker::PhantomData; use std::sync::atomic::AtomicBool; -use crate::lockable::{Lockable, RawLock}; - mod error; mod flag; mod guard; @@ -92,3 +90,19 @@ pub type PoisonResult = Result>; /// lock might not have been acquired for other reasons. pub type TryLockPoisonableResult<'flag, 'key, G, Key> = Result, TryLockPoisonableError<'flag, 'key, G, Key>>; + +#[cfg(test)] +mod tests { + use super::*; + use crate::{Mutex, ThreadKey}; + + #[test] + fn display_works() { + let key = ThreadKey::get().unwrap(); + let mutex = Poisonable::new(Mutex::new("Hello, world!")); + + let guard = mutex.lock(key).unwrap(); + + assert_eq!(guard.to_string(), "Hello, world!"); + } +} -- cgit v1.2.3