module Test:This module provides the functions for creating and running tests.sig
..end
Kaputt features four kinds of tests:
type
result =
| |
Passed |
(* | Indicates that the assertion-based test passed. | *) |
| |
Failed of |
(* | Indicates that the assertion-based test failed. | *) |
| |
Uncaught of |
(* | Indicates that the assertion-based test raised a exception (parameters are exception, and associated backtrace). | *) |
| |
Report of |
(* | Indicates how the generator- or enumerator-based execution performed
Parameters are:
| *) |
| |
Exit_code of |
(* | Indicates how the shell-based execution performed (parameter being the exit code of the executed command). | *) |
type'a
classifier ='a -> string
type
t
type
output_mode =
| |
Text_output of |
(* | Classical output, parameter being destination. | *) |
| |
Html_output of |
(* | HTML output, parameter being destination. | *) |
| |
Xml_output of |
(* | XML output, parameter being destination. | *) |
| |
Xml_junit_output of |
(* | XML output (in JUnit-compatible format - http://www.junit.org), parameter being destination. | *) |
| |
Csv_output of |
(* | CSV output, parameters being destination and separator. | *) |
val return : 'a -> unit -> 'a
return x
returns the function always returning x
.val make_assert_test : ?title:string -> (unit -> 'a) -> ('a -> 'b) -> ('b -> unit) -> t
make_assert_test ~title:t set_up f tear_down
constructs a test running
the function f
. The function is feed by the result of a call to set_up
,
and the value returned by the function is passed to tear_down
.
The function is intended to use functions from the Assertion
module to
check if computed values are equal to waited ones.val make_simple_test : ?title:string -> (unit -> unit) -> t
make_simple_test ~title:t f
constructs a test running the function f
.
It is equivalent to make_assert_test ~title:t (return ()) f ignore
.
The function is intended to use functions from the Assertion
module to
check if computed values are equal to waited ones.val add_assert_test : ?title:string -> (unit -> 'a) -> ('a -> 'b) -> ('b -> unit) -> unit
make_assert_test
, except that the built test is added to the ones to be run by launch_tests
.val add_simple_test : ?title:string -> (unit -> unit) -> unit
make_simple_test
, except that the built test is added to the ones to be run by launch_tests
.val default_classifier : 'a classifier
""
.val default_reducer : 'a Reducer.t
[]
.val make_random_test : ?title:string ->
?nb_runs:int ->
?nb_tries:int ->
?classifier:'a classifier ->
?reducer:'a Reducer.t ->
?reduce_depth:int ->
?reduce_smaller:('a -> 'a -> bool) ->
?random_src:Generator.random ->
'a Generator.t -> ('a -> 'b) -> ('a, 'b) Specification.t list -> t
make_random_test ~title:t ~nb_runs:nb ~nb_tries:nt ~classifier:c ~reducer:red ~random_src:rnd gen f spec
constructs a random test. f
is the function to be tested; when run,
the framework will generate nb
input values for f
satisfying
spec
using gen
(an input value satisfies spec
if it makes one
of the preconditions evaluate to true
). As it is possible to find
no such input value, nt
defines the maximum number of tries when
generating a value.
The function f
is then feed with those values, and the output is
passed to the associated postcondition to check it evaluates to true
(otherwise, a counterexample has been found). The reducer is used
to try to producer a smaller counterexample (. The classifier c
is
used to group generated elements into categories in order to have a
better understanding of what the random elements actually tested.
The default values are:
"untitled no X"
string
("X" being the value of a counter) for title
;100
for nb_runs
;10 * nb_runs
for nb_tries
;default_classifier
for classifier
;default_reducer
for reducer
;Generator.make_random ()
for random_src
.Invalid_arg
if either nb
or nt
is not strictly positive.val add_random_test : ?title:string ->
?nb_runs:int ->
?nb_tries:int ->
?classifier:'a classifier ->
?reducer:'a Reducer.t ->
?reduce_depth:int ->
?reduce_smaller:('a -> 'a -> bool) ->
?random_src:Generator.random ->
'a Generator.t -> ('a -> 'b) -> ('a, 'b) Specification.t list -> unit
make_random_test
, except that the built test is added to the ones to be run by launch_tests
.val make_partial_random_test : ?title:string ->
?nb_runs:int ->
?nb_tries:int ->
?classifier:'a classifier ->
?reducer:'a Reducer.t ->
?reduce_depth:int ->
?reduce_smaller:('a -> 'a -> bool) ->
?random_src:Generator.random ->
'a Generator.t ->
('a -> 'b) -> ('a, 'b Specification.outcome) Specification.t list -> t
make_random_test
for partial functions.val add_partial_random_test : ?title:string ->
?nb_runs:int ->
?nb_tries:int ->
?classifier:'a classifier ->
?reducer:'a Reducer.t ->
?reduce_depth:int ->
?reduce_smaller:('a -> 'a -> bool) ->
?random_src:Generator.random ->
'a Generator.t ->
('a -> 'b) -> ('a, 'b Specification.outcome) Specification.t list -> unit
make_partial_random_test
, except that the built test is added to the ones to be run by launch_tests
.val make_enum_test : ?title:string ->
'a Enumerator.t -> ('a -> 'b) -> ('a, 'b) Specification.t list -> t
make_enum_test ~title:t e f spec
constructs an enumerator-based test
f
is the function to be tested against the values enumerated by e
,
ensuring that the specification spec
is satisfied
(cf. Test.make_random_test
).val add_enum_test : ?title:string ->
'a Enumerator.t -> ('a -> 'b) -> ('a, 'b) Specification.t list -> unit
make_enum_test
, except that the built test is added to the ones to be run by launch_tests
.val make_partial_enum_test : ?title:string ->
'a Enumerator.t ->
('a -> 'b) -> ('a, 'b Specification.outcome) Specification.t list -> t
make_enum_test
for partial functions.val add_partial_enum_test : ?title:string ->
'a Enumerator.t ->
('a -> 'b) -> ('a, 'b Specification.outcome) Specification.t list -> unit
make_partial_enum_test
, except that the built test is added to the ones to be run by launch_tests
.val make_shell_test : ?title:string ->
([< `Input | `No_input ], [< `No_output | `Output ], [< `Error | `No_error ])
Shell.command list -> t
make_shell_test ~title:t l
constructs a test running the commands from
l
using Shell.run_list
.val add_shell_test : ?title:string ->
([< `Input | `No_input ], [< `No_output | `Output ], [< `Error | `No_error ])
Shell.command list -> unit
make_shell_test
, except that the built test is added to the ones to be run by launch_tests
.val exec_test : t -> result
val exec_tests : t list -> result list
exec_tests l
is equivalent to List.map exec_test l
.val run_test : ?output:output_mode -> t -> unit
The output channel if closed only iff it is neither stdout
, nor stderr
.
val run_tests : ?output:output_mode -> t list -> unit
The output channel if closed only iff it is neither stdout
, nor stderr
.
val launch_tests : ?output:output_mode -> ?clear:bool -> unit -> unit
run_tests
, except that the list of tests to be run is
composed of all the tests build by the add_xyz
functions of this module.
The clear
parameter indicates whether the list of tests should be
emptied, and defaults to true
.val get_tests : unit -> t list
launch_tests
.val check : ?title:string ->
?nb_runs:int ->
?nb_tries:int ->
?classifier:'a classifier ->
?random_src:Generator.random ->
'a Generator.t -> ('a -> 'b) -> ('a, 'b) Specification.t list -> unit
check ...
is equivalent to run_test (make_random_test ...)
.val check_partial : ?title:string ->
?nb_runs:int ->
?nb_tries:int ->
?classifier:'a classifier ->
?random_src:Generator.random ->
'a Generator.t ->
('a -> 'b) -> ('a, 'b Specification.outcome) Specification.t list -> unit
check
for partial functions.