package popper

  1. Overview
  2. Docs

Module PopperSource

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

Sourcemodule Comparator : sig ... end
Sourcemodule Consumed : sig ... end
Sourcemodule Sample : sig ... end
Sourcemodule Proposition : sig ... end
Sourcemodule Test : sig ... end
Sourcemodule Config : sig ... end

Types and exceptions

Sourceexception Test_failure

Constructing tests

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval greater_equal_than : ?loc:string -> 'a Comparator.t -> 'a -> 'a -> Proposition.t Sample.t
Sourceval 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.

Sourceval 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.

Sourceval 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

Sourceval 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.

Sourceval 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.

OCaml

Innovation. Community. Security.