@@ -10,7 +10,8 @@ use std::{hint, mem, thread};
10
10
//
11
11
// To write a test that uses both `poison::Mutex` and `nonpoison::Mutex`, simply call the macro
12
12
// `maybe_unwrap!(...)` on the result of `mutex.lock()`. For the `poison::Mutex`, it will unwrap the
13
- // `LockResult`, but for the `nonpoison::Mutex` it will do nothing.
13
+ // `Result` (usually `LockResult`, but it could be other kinds of results), but for the
14
+ // `nonpoison::Mutex` it will do nothing.
14
15
//
15
16
// The `poison` test will have the same name, but with a suffix of `_unwrap_poisoned`.
16
17
//
@@ -38,11 +39,11 @@ macro_rules! nonpoison_and_poison_unwrap_test {
38
39
#[ test]
39
40
fn ${ concat( $name, _unwrap_poisoned) } ( ) {
40
41
#[ allow( unused_imports) ]
41
- use :: std:: sync:: { Mutex , MappedMutexGuard , MutexGuard , LockResult } ;
42
+ use :: std:: sync:: { Mutex , MappedMutexGuard , MutexGuard } ;
42
43
43
44
#[ allow( unused_macros) ]
44
45
macro_rules! maybe_unwrap {
45
- ( $e: expr) => { LockResult :: unwrap( $e) } ;
46
+ ( $e: expr) => { Result :: unwrap( $e) } ;
46
47
}
47
48
48
49
$( $test_body) *
@@ -151,17 +152,6 @@ nonpoison_and_poison_unwrap_test!(
151
152
}
152
153
) ;
153
154
154
- // TODO(connor): make this a double test after implementing `lock_value_accessors` on `nonpoison`.
155
- #[ test]
156
- fn test_get_cloned ( ) {
157
- #[ derive( Clone , Eq , PartialEq , Debug ) ]
158
- struct Cloneable ( i32 ) ;
159
-
160
- let m = Mutex :: new ( Cloneable ( 10 ) ) ;
161
-
162
- assert_eq ! ( m. get_cloned( ) . unwrap( ) , Cloneable ( 10 ) ) ;
163
- }
164
-
165
155
nonpoison_and_poison_unwrap_test ! (
166
156
name: test_get_mut,
167
157
test_body: {
@@ -171,41 +161,55 @@ nonpoison_and_poison_unwrap_test!(
171
161
}
172
162
) ;
173
163
174
- // TODO(connor): make this a double test after implementing `lock_value_accessors` on `nonpoison`.
175
- #[ test]
176
- fn test_set ( ) {
177
- fn inner < T > ( mut init : impl FnMut ( ) -> T , mut value : impl FnMut ( ) -> T )
178
- where
179
- T : Debug + Eq ,
180
- {
181
- let m = Mutex :: new ( init ( ) ) ;
164
+ nonpoison_and_poison_unwrap_test ! (
165
+ name: test_get_cloned,
166
+ test_body: {
167
+ #[ derive( Clone , Eq , PartialEq , Debug ) ]
168
+ struct Cloneable ( i32 ) ;
169
+
170
+ let m = Mutex :: new( Cloneable ( 10 ) ) ;
182
171
183
- assert_eq ! ( * m. lock( ) . unwrap( ) , init( ) ) ;
184
- m. set ( value ( ) ) . unwrap ( ) ;
185
- assert_eq ! ( * m. lock( ) . unwrap( ) , value( ) ) ;
172
+ assert_eq!( maybe_unwrap!( m. get_cloned( ) ) , Cloneable ( 10 ) ) ;
186
173
}
174
+ ) ;
187
175
188
- inner ( || NonCopy ( 10 ) , || NonCopy ( 20 ) ) ;
189
- inner ( || NonCopyNeedsDrop ( 10 ) , || NonCopyNeedsDrop ( 20 ) ) ;
190
- }
176
+ nonpoison_and_poison_unwrap_test ! (
177
+ name: test_set,
178
+ test_body: {
179
+ fn inner<T >( mut init: impl FnMut ( ) -> T , mut value: impl FnMut ( ) -> T )
180
+ where
181
+ T : Debug + Eq ,
182
+ {
183
+ let m = Mutex :: new( init( ) ) ;
191
184
192
- // TODO(connor): make this a double test after implementing `lock_value_accessors` on `nonpoison`.
193
- #[ test]
194
- fn test_replace ( ) {
195
- fn inner < T > ( mut init : impl FnMut ( ) -> T , mut value : impl FnMut ( ) -> T )
196
- where
197
- T : Debug + Eq ,
198
- {
199
- let m = Mutex :: new ( init ( ) ) ;
185
+ assert_eq!( * maybe_unwrap!( m. lock( ) ) , init( ) ) ;
186
+ maybe_unwrap!( m. set( value( ) ) ) ;
187
+ assert_eq!( * maybe_unwrap!( m. lock( ) ) , value( ) ) ;
188
+ }
200
189
201
- assert_eq ! ( * m. lock( ) . unwrap( ) , init( ) ) ;
202
- assert_eq ! ( m. replace( value( ) ) . unwrap( ) , init( ) ) ;
203
- assert_eq ! ( * m. lock( ) . unwrap( ) , value( ) ) ;
190
+ inner( || NonCopy ( 10 ) , || NonCopy ( 20 ) ) ;
191
+ inner( || NonCopyNeedsDrop ( 10 ) , || NonCopyNeedsDrop ( 20 ) ) ;
204
192
}
193
+ ) ;
205
194
206
- inner ( || NonCopy ( 10 ) , || NonCopy ( 20 ) ) ;
207
- inner ( || NonCopyNeedsDrop ( 10 ) , || NonCopyNeedsDrop ( 20 ) ) ;
208
- }
195
+ nonpoison_and_poison_unwrap_test ! (
196
+ name: test_replace,
197
+ test_body: {
198
+ fn inner<T >( mut init: impl FnMut ( ) -> T , mut value: impl FnMut ( ) -> T )
199
+ where
200
+ T : Debug + Eq ,
201
+ {
202
+ let m = Mutex :: new( init( ) ) ;
203
+
204
+ assert_eq!( * maybe_unwrap!( m. lock( ) ) , init( ) ) ;
205
+ assert_eq!( maybe_unwrap!( m. replace( value( ) ) ) , init( ) ) ;
206
+ assert_eq!( * maybe_unwrap!( m. lock( ) ) , value( ) ) ;
207
+ }
208
+
209
+ inner( || NonCopy ( 10 ) , || NonCopy ( 20 ) ) ;
210
+ inner( || NonCopyNeedsDrop ( 10 ) , || NonCopyNeedsDrop ( 20 ) ) ;
211
+ }
212
+ ) ;
209
213
210
214
#[ test]
211
215
fn test_mutex_arc_condvar ( ) {
0 commit comments