@@ -72,11 +72,10 @@ impl<G: Gen> QuickCheck<G> {
72
72
if ntests >= self . tests {
73
73
break
74
74
}
75
- let r = f. result ( & mut self . gen ) ;
76
- match r. status {
77
- Pass => ntests += 1 ,
78
- Discard => continue ,
79
- Fail => return Err ( r) ,
75
+ match f. result ( & mut self . gen ) {
76
+ TestResult { status : Pass , .. } => ntests += 1 ,
77
+ TestResult { status : Discard , .. } => continue ,
78
+ r @ TestResult { status : Fail , .. } => return Err ( r) ,
80
79
}
81
80
}
82
81
Ok ( ntests)
@@ -128,7 +127,7 @@ pub fn quickcheck<A: Testable>(f: A) { QuickCheck::new().quickcheck(f) }
128
127
pub struct TestResult {
129
128
status : Status ,
130
129
arguments : Vec < String > ,
131
- err : String ,
130
+ err : Option < String > ,
132
131
}
133
132
134
133
/// Whether a test has passed, failed or been discarded.
@@ -142,11 +141,10 @@ impl TestResult {
142
141
/// Produces a test result that indicates the current test has failed.
143
142
pub fn failed ( ) -> TestResult { TestResult :: from_bool ( false ) }
144
143
145
- /// Produces a test result that indicates failure from a runtime
146
- /// error.
147
- pub fn error ( msg : & str ) -> TestResult {
144
+ /// Produces a test result that indicates failure from a runtime error.
145
+ pub fn error < S : Into < String > > ( msg : S ) -> TestResult {
148
146
let mut r = TestResult :: from_bool ( false ) ;
149
- r. err = msg. to_string ( ) ;
147
+ r. err = Some ( msg. into ( ) ) ;
150
148
r
151
149
}
152
150
@@ -158,7 +156,7 @@ impl TestResult {
158
156
TestResult {
159
157
status : Discard ,
160
158
arguments : vec ! [ ] ,
161
- err : "" . to_string ( ) ,
159
+ err : None ,
162
160
}
163
161
}
164
162
@@ -169,7 +167,7 @@ impl TestResult {
169
167
TestResult {
170
168
status : if b { Pass } else { Fail } ,
171
169
arguments : vec ! [ ] ,
172
- err : "" . to_string ( ) ,
170
+ err : None ,
173
171
}
174
172
}
175
173
@@ -197,19 +195,20 @@ impl TestResult {
197
195
/// Returns `true` if and only if this test result describes a failing
198
196
/// test as a result of a run time error.
199
197
pub fn is_error ( & self ) -> bool {
200
- self . is_failure ( ) && self . err . len ( ) > 0
198
+ self . is_failure ( ) && self . err . is_some ( )
201
199
}
202
200
203
201
fn failed_msg ( & self ) -> String {
204
- if self . err . len ( ) == 0 {
205
- format ! (
206
- "[quickcheck] TEST FAILED. Arguments: ({})" ,
207
- self . arguments. connect( ", " ) )
208
- } else {
209
- format ! (
210
- "[quickcheck] TEST FAILED (runtime error). \
211
- Arguments: ({})\n Error: {}",
212
- self . arguments. connect( ", " ) , self . err)
202
+ match self . err {
203
+ None => {
204
+ format ! ( "[quickcheck] TEST FAILED. Arguments: ({})" ,
205
+ self . arguments. connect( ", " ) )
206
+ }
207
+ Some ( ref err) => {
208
+ format ! ( "[quickcheck] TEST FAILED (runtime error). \
209
+ Arguments: ({})\n Error: {}",
210
+ self . arguments. connect( ", " ) , err)
211
+ }
213
212
}
214
213
}
215
214
}
@@ -365,7 +364,7 @@ impl<A, B, C, D, T> Fun<A, B, C, D, T> for fn(A, B, C, D) -> T
365
364
fn shrink < G , T , A , B , C , D , F > ( g : & mut G , fun : & F ) -> TestResult
366
365
where G : Gen , T : Testable , A : AShow , B : AShow , C : AShow , D : AShow ,
367
366
F : Fun < A , B , C , D , T > {
368
- let ( a, b, c, d) : ( A , B , C , D ) = arby ( g) ;
367
+ let ( a, b, c, d) : ( A , B , C , D ) = Arbitrary :: arbitrary ( g) ;
369
368
let r = fun. call ( g, Some ( & a) , Some ( & b) , Some ( & c) , Some ( & d) ) ;
370
369
match r. status {
371
370
Pass |Discard => r,
@@ -416,4 +415,3 @@ fn safe<T, F>(fun: F) -> Result<T, String>
416
415
/// Convenient aliases.
417
416
trait AShow : Arbitrary + Debug { }
418
417
impl < A : Arbitrary + Debug > AShow for A { }
419
- fn arby < A : Arbitrary , G : Gen > ( g : & mut G ) -> A { Arbitrary :: arbitrary ( g) }
0 commit comments