@@ -6,50 +6,7 @@ use std::sync::mpsc::channel;
66use std:: sync:: { Arc , Condvar , MappedMutexGuard , Mutex , MutexGuard , TryLockError } ;
77use std:: { hint, mem, thread} ;
88
9- // Generates two test cases for both the poison and nonpoison locks.
10- //
11- // To write a test that uses both `poison::Mutex` and `nonpoison::Mutex`, simply call the macro
12- // `maybe_unwrap!(...)` on the result of `mutex.lock()`. For the `poison::Mutex`, it will unwrap the
13- // `Result` (usually `LockResult`, but it could be other kinds of results), but for the
14- // `nonpoison::Mutex` it will do nothing.
15- //
16- // The `poison` test will have the same name, but with a suffix of `_unwrap_poisoned`.
17- //
18- // See some of the tests below for examples.
19- macro_rules! nonpoison_and_poison_unwrap_test {
20- (
21- name: $name: ident,
22- test_body: { $( $test_body: tt) * }
23- ) => {
24- // Creates the nonpoison test.
25- #[ test]
26- fn $name( ) {
27- #[ allow( unused_imports) ]
28- use :: std:: sync:: nonpoison:: { Mutex , MappedMutexGuard , MutexGuard } ;
29-
30- #[ allow( unused_macros) ]
31- macro_rules! maybe_unwrap {
32- ( $e: expr) => { $e } ;
33- }
34-
35- $( $test_body) *
36- }
37-
38- // Creates the poison test with the suffix `_unwrap_poisoned`.
39- #[ test]
40- fn ${ concat( $name, _unwrap_poisoned) } ( ) {
41- #[ allow( unused_imports) ]
42- use :: std:: sync:: { Mutex , MappedMutexGuard , MutexGuard } ;
43-
44- #[ allow( unused_macros) ]
45- macro_rules! maybe_unwrap {
46- ( $e: expr) => { Result :: unwrap( $e) } ;
47- }
48-
49- $( $test_body) *
50- }
51- }
52- }
9+ use super :: nonpoison_and_poison_unwrap_test;
5310
5411nonpoison_and_poison_unwrap_test ! (
5512 name: smoke,
@@ -211,6 +168,8 @@ nonpoison_and_poison_unwrap_test!(
211168 }
212169) ;
213170
171+ // FIXME(nonpoison_condvar): Move this to the `condvar.rs` test file once `nonpoison::condvar` gets
172+ // implemented.
214173#[ test]
215174fn test_mutex_arc_condvar ( ) {
216175 struct Packet < T > ( Arc < ( Mutex < T > , Condvar ) > ) ;
@@ -290,6 +249,7 @@ nonpoison_and_poison_unwrap_test!(
290249 }
291250) ;
292251
252+ /// Creates a mutex that is immediately poisoned.
293253fn new_poisoned_mutex < T > ( value : T ) -> Mutex < T > {
294254 let mutex = Mutex :: new ( value) ;
295255
0 commit comments