Skip to content

Commit 570f6a8

Browse files
authored
Merge pull request #148 from blt/read_from_env
Allow QC_TESTS and QC_MAX_TESTS to set tests / max_tests
2 parents 1cc9e3e + 5d0aa41 commit 570f6a8

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/tester.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::fmt::Debug;
22
use std::panic;
3+
use std::env;
4+
use std::cmp;
35

46
use rand;
57

@@ -13,6 +15,30 @@ pub struct QuickCheck<G> {
1315
gen: G,
1416
}
1517

18+
fn qc_tests() -> usize {
19+
let default = 100;
20+
match env::var("QUICKCHECK_TESTS") {
21+
Ok(val) => val.parse().unwrap_or(default),
22+
Err(_) => default,
23+
}
24+
}
25+
26+
fn qc_max_tests() -> usize {
27+
let default = 10_000;
28+
match env::var("QUICKCHECK_MAX_TESTS") {
29+
Ok(val) => val.parse().unwrap_or(default),
30+
Err(_) => default,
31+
}
32+
}
33+
34+
fn qc_gen_size() -> usize {
35+
let default = 100;
36+
match env::var("QUICKCHECK_GENERATOR_SIZE") {
37+
Ok(val) => val.parse().unwrap_or(default),
38+
Err(_) => default,
39+
}
40+
}
41+
1642
impl QuickCheck<StdGen<rand::ThreadRng>> {
1743
/// Creates a new QuickCheck value.
1844
///
@@ -24,10 +50,13 @@ impl QuickCheck<StdGen<rand::ThreadRng>> {
2450
/// the max number of overall tests is set to `10000` and the generator
2551
/// is set to a `StdGen` with a default size of `100`.
2652
pub fn new() -> QuickCheck<StdGen<rand::ThreadRng>> {
53+
let tests = qc_tests();
54+
let max_tests = cmp::max(tests, qc_max_tests());
55+
let gen_size = qc_gen_size();
2756
QuickCheck {
28-
tests: 100,
29-
max_tests: 10000,
30-
gen: StdGen::new(rand::thread_rng(), 100),
57+
tests: tests,
58+
max_tests: max_tests,
59+
gen: StdGen::new(rand::thread_rng(), gen_size),
3160
}
3261
}
3362
}

0 commit comments

Comments
 (0)