Module Popper
Popper is an OCaml testing library that can be used for writing simple unit-tests as well as property-based ones.
Modules
module Comparator : sig ... end
module Consumed : sig ... end
module Sample : sig ... end
module Proposition : sig ... end
module Test : sig ... end
module Config : sig ... end
Types and exceptions
Constructing tests
val test : ?config:Config.t -> (unit -> Proposition.t Sample.t) -> Test.t
test ?config f
creates a test that when run evaluatesf
that produces aProposition.t Sample.t
value. If the the sample consumes any input, it is run a number of times until it either finds some input value that causes the sample to yield a failing proposition, or until it passes specified number of runs (default is 300). Ifconfig
is given it takes all the specified overrides into account.
Propositions
val pass : Proposition.t Sample.t
pass
is a sample that always returns the valuepass
.
val fail : ?loc:string -> string -> Proposition.t Sample.t
fail ?loc msg
is a sample that returns the valuefail
with locationloc
if given and error messagemsg
.
val equal : ?loc:string -> 'a Comparator.t -> 'a -> 'a -> Proposition.t Sample.t
equal ?loc cmp x y
is a sample that returns a proposition that ispass
only ifx
andy
are equal using the given comparatorcmp
. Ifloc
is passed, it reports the location string in case of failure.
val less_than : ?loc:string -> 'a Comparator.t -> 'a -> 'a -> Proposition.t Sample.t
less_than ?loc cmp x y
is a sample that returns a proposition that ispass
only ifx
is less thany
, using the given comparatorcmp
. Ifloc
is passed, it reports the location string in case of failure.
val greater_than : ?loc:string -> 'a Comparator.t -> 'a -> 'a -> Proposition.t Sample.t
greater_than ?loc cmp x y
is a sample that returns a proposition that ispass
only ifx
is greater thany
, using the given comparatorcmp
. Ifloc
is passed, it reports the location string in case of failure.
val greater_equal_than : ?loc:string -> 'a Comparator.t -> 'a -> 'a -> Proposition.t Sample.t
greater_equal_than ?loc cmp x y
is a sample that returns a proposition that ispass
only ifx
is greater than or equal toy
, using the given comparatorcmp
. Ifloc
is passed, it reports the location string in case of failure.
val less_equal_than : ?loc:string -> 'a Comparator.t -> 'a -> 'a -> Proposition.t Sample.t
less_than_equal ?loc cmp x y
is a sample that returns a proposition that ispass
only ifx
is less than or equal toy
, using the given comparatorcmp
. Ifloc
is passed, it reports the location string in case of failure.
val is_true : ?loc:string -> bool -> Proposition.t Sample.t
is_true ?loc b
is a sample that returns a proposition that ispass
only ifb
is true. Ifloc
is passed, it reports the location string in case of failure.
val is_false : ?loc:string -> bool -> Proposition.t Sample.t
is_false ?loc b
is a sample that returns a proposition that ispass
only ifb
is false. Ifloc
is passed, it reports the location string in case of failure.
val all : Proposition.t Sample.t list -> Proposition.t Sample.t
all ps
combines a list of proposition samples into a sample that only returns pass in case all returned propositions pass.
val any : Proposition.t Sample.t list -> Proposition.t Sample.t
any ps
combines a list of proposition samples into a single sample that returns pass in case any of the returned propositions pass.
Running tests
val check : ?config:Config.t -> (unit -> Proposition.t Sample.t) -> unit
check ?config f
runs a single anonymous test using theconfig
settings if given. In case the test fails, an exception of typeTest_failure
is raised.