@@ -123,6 +123,12 @@ struct NotImplError1;
123
123
#[ derive( Debug ) ]
124
124
struct CustomError ( #[ allow( dead_code) ] TestCaseError ) ;
125
125
126
+ impl CustomError {
127
+ fn new ( ) -> Self {
128
+ CustomError ( TestCaseError :: fail ( "Custom" ) )
129
+ }
130
+ }
131
+
126
132
impl std:: error:: Error for CustomError { }
127
133
impl std:: fmt:: Display for CustomError {
128
134
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
@@ -145,9 +151,9 @@ impl From<NotImplError1> for CustomError {
145
151
}
146
152
}
147
153
148
- macro_rules! prop_assert2 {
154
+ macro_rules! prop_assert_custom {
149
155
( $cond: expr) => {
150
- prop_assert2 !( $cond, concat!( "assertion failed: " , stringify!( $cond) ) )
156
+ prop_assert_custom !( $cond, concat!( "assertion failed: " , stringify!( $cond) ) )
151
157
} ;
152
158
( $cond: expr, $( $fmt: tt) * ) => {
153
159
if !$cond {
@@ -160,58 +166,128 @@ macro_rules! prop_assert2 {
160
166
161
167
#[ proptest]
162
168
fn custom_error_ok ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
163
- prop_assert2 ! ( x < 10 ) ;
169
+ prop_assert_custom ! ( x < 10 ) ;
164
170
not_impl_error_ok ( ) ?;
165
171
Ok ( ( ) )
166
172
}
173
+ #[ proptest( async = "tokio" ) ]
174
+ async fn custom_error_ok_async ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
175
+ prop_assert_custom ! ( x < 10 ) ;
176
+ not_impl_error_ok ( ) ?;
177
+ yield_now ( ) . await ;
178
+ Ok ( ( ) )
179
+ }
167
180
168
181
#[ should_panic]
169
182
#[ proptest]
170
- fn custom_error_ok_prop_assesrt_fail ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
171
- prop_assert2 ! ( x >= 10 ) ;
183
+ fn custom_error_prop_assesrt_fail ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
184
+ prop_assert_custom ! ( x >= 10 ) ;
172
185
Ok ( ( ) )
173
186
}
174
187
175
188
#[ proptest]
176
189
#[ should_panic]
177
190
fn custom_error_err ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
178
- prop_assert2 ! ( x < 10 ) ;
191
+ prop_assert_custom ! ( x < 10 ) ;
179
192
not_impl_error_err ( ) ?;
180
193
Ok ( ( ) )
181
194
}
182
195
196
+ #[ proptest( async = "tokio" ) ]
197
+ #[ should_panic]
198
+ async fn custom_error_err_async ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
199
+ prop_assert_custom ! ( x < 10 ) ;
200
+ not_impl_error_err ( ) ?;
201
+ yield_now ( ) . await ;
202
+ Ok ( ( ) )
203
+ }
204
+
183
205
#[ proptest]
184
206
fn custom_error_ok_2 ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
185
- prop_assert2 ! ( x < 10 ) ;
207
+ prop_assert_custom ! ( x < 10 ) ;
186
208
not_impl_error_ok ( ) ?;
187
209
not_impl_error_ok_1 ( ) ?;
188
210
Ok ( ( ) )
189
211
}
190
212
213
+ fn not_impl_error_ok ( ) -> Result < ( ) , NotImplError0 > {
214
+ Ok ( ( ) )
215
+ }
216
+ fn not_impl_error_err ( ) -> Result < ( ) , NotImplError0 > {
217
+ Err ( NotImplError0 )
218
+ }
219
+
220
+ fn not_impl_error_ok_1 ( ) -> Result < ( ) , NotImplError1 > {
221
+ Ok ( ( ) )
222
+ }
223
+
224
+ macro_rules! prop_assert_anyhow {
225
+ ( $cond: expr) => {
226
+ prop_assert_anyhow!( $cond, concat!( "assertion failed: " , stringify!( $cond) ) )
227
+ } ;
228
+ ( $cond: expr, $( $fmt: tt) * ) => {
229
+ if !$cond {
230
+ anyhow:: bail!( "{} at {}:{}" , format!( $( $fmt) * ) , file!( ) , line!( ) ) ;
231
+ }
232
+ } ;
233
+ }
234
+
235
+ #[ proptest]
236
+ fn anyhow_result_ok ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> anyhow:: Result < ( ) > {
237
+ prop_assert_anyhow ! ( x < 10 ) ;
238
+ Ok ( ( ) )
239
+ }
240
+
191
241
#[ proptest( async = "tokio" ) ]
192
- async fn custom_error_async_ok ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
193
- prop_assert2 ! ( x < 10 ) ;
194
- not_impl_error_ok ( ) ?;
242
+ async fn anyhow_result_ok_async ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> anyhow:: Result < ( ) > {
243
+ prop_assert_anyhow ! ( x < 10 ) ;
195
244
yield_now ( ) . await ;
196
245
Ok ( ( ) )
197
246
}
198
247
248
+ #[ proptest]
249
+ #[ should_panic]
250
+ fn anyhow_result_prop_assert_fail ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> anyhow:: Result < ( ) > {
251
+ prop_assert_anyhow ! ( x >= 10 ) ;
252
+ Ok ( ( ) )
253
+ }
254
+
199
255
#[ proptest( async = "tokio" ) ]
200
256
#[ should_panic]
201
- async fn custom_error_async_err ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
202
- prop_assert2 ! ( x < 10 ) ;
203
- not_impl_error_err ( ) ?;
257
+ async fn anyhow_result_prop_assert_fail_async ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> anyhow:: Result < ( ) > {
258
+ prop_assert_anyhow ! ( x >= 10 ) ;
204
259
yield_now ( ) . await ;
205
260
Ok ( ( ) )
206
261
}
207
262
208
- fn not_impl_error_ok ( ) -> Result < ( ) , NotImplError0 > {
263
+ #[ proptest]
264
+ #[ should_panic]
265
+ fn anyhow_result_err ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> anyhow:: Result < ( ) > {
266
+ prop_assert_anyhow ! ( x < 10 ) ;
267
+ Err ( CustomError :: new ( ) ) ?;
209
268
Ok ( ( ) )
210
269
}
211
- fn not_impl_error_err ( ) -> Result < ( ) , NotImplError0 > {
212
- Err ( NotImplError0 )
213
- }
214
270
215
- fn not_impl_error_ok_1 ( ) -> Result < ( ) , NotImplError1 > {
271
+ #[ proptest( async = "tokio" ) ]
272
+ #[ should_panic]
273
+ async fn anyhow_result_err_async ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> anyhow:: Result < ( ) > {
274
+ prop_assert_anyhow ! ( x < 10 ) ;
275
+ Err ( CustomError :: new ( ) ) ?;
276
+ yield_now ( ) . await ;
216
277
Ok ( ( ) )
217
278
}
279
+
280
+ #[ proptest]
281
+ #[ should_panic]
282
+ fn anyhow_result_bail ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> anyhow:: Result < ( ) > {
283
+ prop_assert_anyhow ! ( x < 10 ) ;
284
+ anyhow:: bail!( "error" ) ;
285
+ }
286
+
287
+ #[ proptest( async = "tokio" ) ]
288
+ #[ should_panic]
289
+ async fn anyhow_result_bail_async ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> anyhow:: Result < ( ) > {
290
+ prop_assert_anyhow ! ( x < 10 ) ;
291
+ yield_now ( ) . await ;
292
+ anyhow:: bail!( "error" ) ;
293
+ }
0 commit comments