Skip to content

Commit

Permalink
QCHECK_COUNT_MULTIPLIER environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
vch9 committed Jan 7, 2022
1 parent 5513b52 commit 3d8e302
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/core/QCheck2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1394,13 +1394,21 @@ module Test = struct

let default_count = 100

let multiplier_count () =
let mult = match Sys.getenv_opt "QCHECK_COUNT_MULTIPLIER" with
| Some mult -> int_of_string mult
| None -> 1
in
if mult <= 0 then invalid_arg ("QCHECK_COUNT_MULTIPLIER must be > 0 but value is " ^ string_of_int mult)
else mult

let global_count count =
let count = match (count, Sys.getenv_opt "QCHECK_COUNT") with
| (Some x, _) -> x
| (Some x, _) -> x * (multiplier_count ())
| (_, Some x) -> int_of_string x
| (None, None) -> default_count
in
if count < 0 then invalid_arg ("count must be > 0 but value is " ^ string_of_int count) else count
if count <= 0 then invalid_arg ("count must be > 0 but value is " ^ string_of_int count) else count

let fresh_name =
let r = ref 0 in
Expand Down
3 changes: 0 additions & 3 deletions test/core/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ module Test = struct

let test_count_10 () = test_count_n ~count:10 10

let test_count_0 () = test_count_n ~count:0 0

let test_count_default () = test_count_n 100

let test_count_env () =
Expand All @@ -114,7 +112,6 @@ module Test = struct
let tests =
("Test", Alcotest.[
test_case "make with custom count" `Quick test_count_10;
test_case "make with custom count" `Quick test_count_0;
test_case "make with default count" `Quick test_count_default;
test_case "make with env count" `Quick test_count_env;
])
Expand Down

0 comments on commit 3d8e302

Please sign in to comment.