@@ -117,7 +117,8 @@ async fn async_expr_test_prop_assert_false() {
117
117
prop_assert ! ( false ) ;
118
118
}
119
119
120
- struct NotImplError ;
120
+ struct NotImplError0 ;
121
+ struct NotImplError1 ;
121
122
122
123
#[ derive( Debug ) ]
123
124
struct CustomError ( #[ allow( dead_code) ] TestCaseError ) ;
@@ -133,30 +134,63 @@ impl From<TestCaseError> for CustomError {
133
134
CustomError ( e)
134
135
}
135
136
}
136
- impl From < NotImplError > for CustomError {
137
- fn from ( _: NotImplError ) -> Self {
137
+ impl From < NotImplError0 > for CustomError {
138
+ fn from ( _: NotImplError0 ) -> Self {
139
+ CustomError ( TestCaseError :: fail ( "Custom" ) )
140
+ }
141
+ }
142
+ impl From < NotImplError1 > for CustomError {
143
+ fn from ( _: NotImplError1 ) -> Self {
138
144
CustomError ( TestCaseError :: fail ( "Custom" ) )
139
145
}
140
146
}
141
147
148
+ macro_rules! prop_assert2 {
149
+ ( $cond: expr) => {
150
+ prop_assert2!( $cond, concat!( "assertion failed: " , stringify!( $cond) ) )
151
+ } ;
152
+ ( $cond: expr, $( $fmt: tt) * ) => {
153
+ if !$cond {
154
+ let message = format!( $( $fmt) * ) ;
155
+ let message = format!( "{} at {}:{}" , message, file!( ) , line!( ) ) ;
156
+ :: core:: result:: Result :: Err ( :: proptest:: test_runner:: TestCaseError :: fail( message) ) ?;
157
+ }
158
+ } ;
159
+ }
160
+
142
161
#[ proptest]
143
162
fn custom_error_ok ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
144
- assert ! ( x < 10 ) ;
163
+ prop_assert2 ! ( x < 10 ) ;
145
164
not_impl_error_ok ( ) ?;
146
165
Ok ( ( ) )
147
166
}
148
167
168
+ #[ should_panic]
169
+ #[ proptest]
170
+ fn custom_error_ok_prop_assesrt_fail ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
171
+ prop_assert2 ! ( x >= 10 ) ;
172
+ Ok ( ( ) )
173
+ }
174
+
149
175
#[ proptest]
150
176
#[ should_panic]
151
177
fn custom_error_err ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
152
- assert ! ( x < 10 ) ;
178
+ prop_assert2 ! ( x < 10 ) ;
153
179
not_impl_error_err ( ) ?;
154
180
Ok ( ( ) )
155
181
}
156
182
183
+ #[ proptest]
184
+ fn custom_error_ok_2 ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
185
+ prop_assert2 ! ( x < 10 ) ;
186
+ not_impl_error_ok ( ) ?;
187
+ not_impl_error_ok_1 ( ) ?;
188
+ Ok ( ( ) )
189
+ }
190
+
157
191
#[ proptest( async = "tokio" ) ]
158
192
async fn custom_error_async_ok ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
159
- assert ! ( x < 10 ) ;
193
+ prop_assert2 ! ( x < 10 ) ;
160
194
not_impl_error_ok ( ) ?;
161
195
yield_now ( ) . await ;
162
196
Ok ( ( ) )
@@ -165,15 +199,19 @@ async fn custom_error_async_ok(#[strategy(1..10u8)] x: u8) -> Result<(), CustomE
165
199
#[ proptest( async = "tokio" ) ]
166
200
#[ should_panic]
167
201
async fn custom_error_async_err ( #[ strategy( 1 ..10u8 ) ] x : u8 ) -> Result < ( ) , CustomError > {
168
- assert ! ( x < 10 ) ;
202
+ prop_assert2 ! ( x < 10 ) ;
169
203
not_impl_error_err ( ) ?;
170
204
yield_now ( ) . await ;
171
205
Ok ( ( ) )
172
206
}
173
207
174
- fn not_impl_error_ok ( ) -> Result < ( ) , NotImplError > {
208
+ fn not_impl_error_ok ( ) -> Result < ( ) , NotImplError0 > {
175
209
Ok ( ( ) )
176
210
}
177
- fn not_impl_error_err ( ) -> Result < ( ) , NotImplError > {
178
- Err ( NotImplError )
211
+ fn not_impl_error_err ( ) -> Result < ( ) , NotImplError0 > {
212
+ Err ( NotImplError0 )
213
+ }
214
+
215
+ fn not_impl_error_ok_1 ( ) -> Result < ( ) , NotImplError1 > {
216
+ Ok ( ( ) )
179
217
}
0 commit comments