package popper

  1. Overview
  2. Docs

Popper is an OCaml testing library that can be used for writing simple unit-tests as well as property-based ones. Its underlying design is inspired by the Python library Hypothesis.

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

exception Test_failure

Constructing tests

val test : ?config:Config.t -> (unit -> Proposition.t Sample.t) -> Test.t

test ?config f creates a test that when run evaluates f that produces a Proposition.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). If config is given it takes all the specified overrides into account.

val suite : (string * Test.t) list -> Test.t

suite ts packs the list of name and test pairs, ts, into a single test suite.

Propositions

pass is a sample that always returns the value pass.

val fail : ?loc:string -> string -> Proposition.t Sample.t

fail ?loc msg is a sample that returns the value fail with location loc if given and error message msg.

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 is pass only if x and y are equal using the given comparator cmp. If loc 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 is pass only if x is less than y, using the given comparator cmp. If loc 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 is pass only if x is greater than y, using the given comparator cmp. If loc 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
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 is pass only if x is less than or equal to y, using the given comparator cmp. If loc 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 is pass only if b is true. If loc 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 is pass only if b is false. If loc is passed, it reports the location string in case of failure.

all ps combines a list of proposition samples into a sample that only returns pass in case all returned propositions pass.

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 the config settings if given. In case the test fails, an exception of type Test_failure is raised.

val run : ?config:Config.t -> Test.t -> unit

test ?config t runs the given test t using the config settings if given. In case the test fails, an exception of type Test_failure is raised.