Module QCheck_runner

module QCheck_runner: sig .. end

Runners for Tests

Once you built some tests using QCheck.Test.make, you need to run the tests. This module contains several runners, which are designed to run every test and report the result.

By default, you can use QCheck_runner.run_tests in a test program as follows:

      let testsuite = [
        Test.make ...;
        Test.make ...;
      ]

      let () =
        let errcode = QCheck_runners.run_tests ~verbose:true testsuite in
        exit errcode
    
which will run the tests, and exit the program. The error code will be 0 if all tests pass, 1 otherwise.

QCheck_runner.run_tests_main can be used as a shortcut for that, also featuring command-line parsing (using Arg) to activate verbose mode and others.



State


val random_state : unit -> Random.State.t
Access the current random state
val verbose : unit -> bool
Is the default mode verbose or quiet?
val long_tests : unit -> bool
Is the default mode to run long tests or nor?
val set_seed : int -> unit
Change the QCheck_runner.random_state by creating a new one, initialized with the given seed.
val set_verbose : bool -> unit
Change the value of verbose ()
val set_long_tests : bool -> unit
Change the value of long_tests ()

Conversion of tests to OUnit Tests


val to_ounit_test : ?verbose:bool ->
?long:bool -> ?rand:Random.State.t -> QCheck.Test.t -> OUnit.test
to_ounit_test ~rand t wraps t into a OUnit test
verbose : used to print information on stdout (default: verbose())
rand : the random generator to use (default: random_state ())
val to_ounit_test_cell : ?verbose:bool ->
?long:bool -> ?rand:Random.State.t -> 'a QCheck.Test.cell -> OUnit.test
Same as QCheck_runner.to_ounit_test but with a polymorphic test cell
val (>:::) : string -> QCheck.Test.t list -> OUnit.test
Same as OUnit.>::: but with a list of QCheck tests
val to_ounit2_test : ?rand:Random.State.t -> QCheck.Test.t -> OUnit2.test
to_ounit2_test ?rand t wraps t into a OUnit2 test
rand : the random generator to use (default: a static seed for reproducibility), can be overridden with "-seed" on the command-line
val to_ounit2_test_list : ?rand:Random.State.t -> QCheck.Test.t list -> OUnit2.test list
to_ounit2_test_list ?rand t like to_ounit2_test but for a list of tests

OUnit runners


val run : ?argv:string array -> OUnit.test -> int
run test runs the test, and returns an error code that is 0 if all tests passed, 1 otherwise. This is the default runner used by the comment-to-test generator.
Raises
argv : the command line arguments to parse parameters from (default Sys.argv)
val run_tap : OUnit.test -> OUnit.test_results
TAP-compatible test runner, in case we want to use a test harness. It prints one line per test.

Run a Suite of Tests and Get Results


val run_tests : ?verbose:bool ->
?long:bool ->
?out:Pervasives.out_channel ->
?rand:Random.State.t -> QCheck.Test.t list -> int
Run a suite of tests, and print its results. This is an heritage from the "qcheck" library.
Returns an error code, 0 if all tests passed, 1 otherwise.
verbose : if true, prints more information about test cases
val run_tests_main : ?argv:string array -> QCheck.Test.t list -> 'a
Can be used as the main function of a test file. Exits with a non-0 code if the tests fail. It refers to QCheck_runner.run_tests for actually running tests after CLI options have been parsed.

The available options are:

Below is an example of the output of the run_tests and run_tests_main function:
random seed: 174620056
generated  error;  fail; pass / total       time -- test name
[✓] (1000)    0 ;    0 ; 1000 / 1000 --     0.5s -- list_rev_is_involutive
[✗] (   1)    0 ;    1 ;    0 /   10 --     0.0s -- fail_sort_id
[✗] (   1)    1 ;    0 ;    0 /   10 --     0.0s -- error_raise_exn

--- Failure --------------------------------------------------------------------

Test fail_sort_id failed (112 shrink steps):

[1; 0]

=== Error ======================================================================

Test error_raise_exn errored on (56 shrink steps):

0

exception QCheck_test.Error
Raised at file "example/QCheck_test.ml", line 19, characters 20-25
Called from file "src/QCheck.ml", line 846, characters 13-33

================================================================================
failure (1 tests failed, 1 tests errored, ran 3 tests)