QCheck2.TestA test is a pair of an generator and a property thar all generated values must satisfy.
The main features of this module are:
make a testcheck_exn a single testNote that while check_exn is provided for convenience to discover QCheck or to run a single test in utop, to run QCheck tests in your project you probably want to opt for a more advanced runner, or convert QCheck tests to your favorite test framework:
QCheck_base_runner for a QCheck-only runner (useful if you don't have or don't need another test framework)QCheck_alcotest to convert to Alcotest frameworkQCheck_ounit to convert to OUnit frameworkA single property test on a value of type 'a. A Test.t wraps a cell and hides its type parameter.
val make_cell :
?if_assumptions_fail:([ `Fatal | `Warning ] * float) ->
?count:int ->
?long_factor:int ->
?max_gen:int ->
?max_fail:int ->
?name:string ->
?print:'a Print.t ->
?collect:( 'a -> string ) ->
?stats:'a stat list ->
'a Gen.t ->
( 'a -> bool ) ->
'a cellmake_cell gen prop builds a test that checks property prop on instances of the generator gen.
val make_cell_from_QCheck1 :
?if_assumptions_fail:([ `Fatal | `Warning ] * float) ->
?count:int ->
?long_factor:int ->
?max_gen:int ->
?max_fail:int ->
?name:string ->
gen:( Stdlib.Random.State.t -> 'a ) ->
?shrink:( 'a -> ( 'a -> unit ) -> unit ) ->
?print:( 'a -> string ) ->
?collect:( 'a -> string ) ->
stats:'a stat list ->
( 'a -> bool ) ->
'a cell⚠️ Do not use, this is exposed for internal reasons only. ⚠️
val get_law : 'a cell -> 'a -> boolval get_name : _ cell -> stringval get_collect_opt : 'a cell -> ( 'a -> string ) optionval set_name : _ cell -> string -> unitval get_count : _ cell -> intGet the count of a cell.
val get_long_factor : _ cell -> intGet the long factor of a cell.
val make :
?if_assumptions_fail:([ `Fatal | `Warning ] * float) ->
?count:int ->
?long_factor:int ->
?max_gen:int ->
?max_fail:int ->
?name:string ->
?print:'a Print.t ->
?collect:( 'a -> string ) ->
?stats:'a stat list ->
'a Gen.t ->
( 'a -> bool ) ->
tmake gen prop builds a test that checks property prop on instances of the generator gen. See make_cell for a description of the parameters.
val test_get_count : t -> intFormat version of fail_report.
Example:
Test.fail_reportf
"Value N = %i should be greater than M = %i for Foo = %a" n m pp_foo fooinclude module type of Test_exceptionsException raised when a test failed, with the list of counter-examples. Test_fail (name, l) means test name failed on elements of l.
val print_instance : 'a cell -> 'a -> stringval print_c_ex : 'a cell -> 'a TestResult.counter_ex -> stringval print_fail : 'a cell -> string -> 'a TestResult.counter_ex list -> stringval print_error :
?st:string ->
'a cell ->
string ->
('a TestResult.counter_ex * exn) ->
stringval print_stat : ('a stat * ( int, int ) Stdlib.Hashtbl.t) -> stringPrint statistics.
val check_result : 'a cell -> 'a TestResult.t -> unitcheck_result cell res checks that res is Ok _, and returns unit. Otherwise, it raises some exception.
Handler executed after each event during testing of an instance.
Callback executed after each instance of a test has been run. The callback is given the instance tested, and the current results of the test.
type 'a callback = string -> 'a cell -> 'a TestResult.t -> unitCallback executed after each test has been run. f name cell res means test cell, named name, gave res.
val check_cell :
?long:bool ->
?call:'a callback ->
?step:'a step ->
?handler:'a handler ->
?rand:Stdlib.Random.State.t ->
'a cell ->
'a TestResult.tcheck_cell ~long ~rand test generates up to count random values of type 'a using Gen.t and the random state st. The predicate law is called on them and if it returns false or raises an exception then we have a counter-example for the law.
val check_cell_exn :
?long:bool ->
?call:'a callback ->
?step:'a step ->
?rand:Stdlib.Random.State.t ->
'a cell ->
unitSame as check_cell but calls check_result on the result.
val check_exn : ?long:bool -> ?rand:Stdlib.Random.State.t -> t -> unitChecks the property against some test cases, and calls check_result, which might raise an exception in case of failure.