package qcheck-core
Install
Dune Dependency
Authors
Maintainers
Sources
md5=e1e928bf792c27de5c072f9123eeaec9
sha512=a0b5791cea09f98f1f17221e6289b87a7a1c16ae1c9af0c2e5bd6a170f2cf8727dba0759a7fd932d5d617e8c242562d69187c7e74eefd5262bc5fd75a322699e
doc/qcheck-core/QCheck2/Test/index.html
Module QCheck2.Test
Source
A test is a pair of a generator and a property that all generated values must satisfy.
The main features of this module are:
make
to create a testmake_neg
to create a negative test that is expected not to satisfy the tested propertycheck_exn
to run a single test with a simple runner.
A test fails if the property does not hold for a given input. The simple form or the rich form) offer more elaborate forms to fail a test.
Note 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 framework
A 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 ->
?negative:bool ->
?max_gen:int ->
?max_fail:int ->
?retries:int ->
?name:string ->
?print:'a Print.t ->
?collect:('a -> string) ->
?stats:'a stat list ->
'a Gen.t ->
('a -> bool) ->
'a cell
make_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 ->
?negative:bool ->
?max_gen:int ->
?max_fail:int ->
?retries:int ->
?name:string ->
gen:(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. ⚠️
Get the expected mode of a cell: positive indicates expected to satisfy the tested property, negative indicates expected not to satisfy the tested property.
val make :
?if_assumptions_fail:([ `Fatal | `Warning ] * float) ->
?count:int ->
?long_factor:int ->
?max_gen:int ->
?max_fail:int ->
?retries:int ->
?name:string ->
?print:'a Print.t ->
?collect:('a -> string) ->
?stats:'a stat list ->
'a Gen.t ->
('a -> bool) ->
t
make 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 make_neg :
?if_assumptions_fail:([ `Fatal | `Warning ] * float) ->
?count:int ->
?long_factor:int ->
?max_gen:int ->
?max_fail:int ->
?retries:int ->
?name:string ->
?print:'a Print.t ->
?collect:('a -> string) ->
?stats:'a stat list ->
'a Gen.t ->
('a -> bool) ->
t
make_neg gen prop
builds a test that checks property prop
on instances of the generator gen
. The test is considered negative, meaning that it is expected not to satisfy the tested property. This information is recorded in an underlying test cell
entry and interpreted suitably by test runners. See make_cell
for a description of the parameters.
Fail the test with some additional message that will be reported.
Format version of fail_report
.
Example:
Test.fail_reportf
"Value N = %i should be greater than M = %i for Foo = %a" n m pp_foo foo
Running the test
include module type of Test_exceptions
Exception raised when a test failed, with the list of counter-examples. Test_fail (name, l)
means test name
failed on elements of l
.
Exception raised when a test raised an exception e
, with the sample that triggered the exception. Test_error (name, i, e, st)
means name
failed on i
with exception e
, and st
is the stacktrace (if enabled) or an empty string.
Exception raised when a negative test failed. Test_unexpected_success name
means test name
failed to find an expected counter example.
val print_error :
?st:string ->
'a cell ->
string ->
('a TestResult.counter_ex * exn) ->
string
For a positive test check_result cell res
checks that res
is Ok _
, and returns unit. For a negative test check_result cell res
checks that res
is Failed _
, 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.
Callback 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:Random.State.t ->
'a cell ->
'a TestResult.t
check_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
.
Note: check_cell
ignores a test's polarity, acting as described above regardless of whether the tested cell is a positive or negative test.
val check_cell_exn :
?long:bool ->
?call:'a callback ->
?step:'a step ->
?handler:'a handler ->
?rand:Random.State.t ->
'a cell ->
unit
Same as check_cell
but calls check_result
on the result. check_cell test
honors test polarity and thus expects positive tests to succeed without finding a counterexample and expects negative tests to fail by finding one.
Checks the property against some test cases, and calls check_result
, which might raise an exception in case of failure. check_exn test
honors test polarity and thus expects positive tests to succeed without finding a counterexample and expects negative tests to fail by finding one.