package windtrap
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9a8c7926c77b1c258010e027eb219164e46a036bfe2df32b34b8781884c8d11c
sha512=10d53181d709e713e8437774aecf8465153c7ce2cda5f42ede02c92cb6ada38a6dcd091566807d3c75b6c8017ca1ca012989ad4aa50788c6ab1fd6c4a1e927de
Description
Unit, property, stateful, and expect tests behind one flat API: every assertion failure prints the values and marks what changed, generators shrink integrally and replay from a printed seed, baselines are a literal in the test or a file it names and are accepted with dune promote, and the runner handles filtering, sharding, and JUnit output. Inline expect tests, code coverage, and mutation testing come from the companion ppx_windtrap package.
Tags
testing unit-test property-testing stateful-testing expect-test snapshot-testing coverage mutation-testingAdded to opam-repository:
README
Windtrap — One library for all your OCaml tests
Windtrap runs unit, property, stateful and expect tests from one flat interface, with coverage and mutation testing in the companion ppx. A suite is an ordinary executable that dune runtest builds and runs.
A first suite
open Windtrap
let basics =
group "basics"
[
test "evicts the oldest entry when full" (fun () ->
let c = Lru.create 2 in
List.iter (fun k -> Lru.add c k k) [ 1; 2; 3 ];
equal (option int) None (Lru.find c 1));
test "lists its keys, most recent first" (fun () ->
let c = Lru.create 3 in
List.iter (fun k -> Lru.add c k k) [ 1; 2; 3 ];
ignore (Lru.find c 1);
expect (Lru.to_string c) @@ __POS_OF__ {|1 3 2|});
]
let bounded =
prop "never holds more than its capacity" Gen.(list int) (fun keys ->
let c = Lru.create 3 in
List.iter (fun k -> Lru.add c k k) keys;
at_most int ~than:3 (Lru.size c))
let () = exit (run "lru" [ basics; bounded ])A run with nothing to report prints one line:
$ dune runtest
lru: 3 passed in 1.0ms (seed s1:b02192cebcec40d2).Features
Unit tests
test and group declare a suite, and run runs it. The assertions that compare values, such as equal, not_equal, less and mem, take a witness, for example int or list string, which prints and compares them; contains, raises and require_some take none. A failure prints the values it compared.
test "splits on commas" (fun () ->
equal (list string) [ "a"; "b" ] (String.split_on_char ',' "a,b"))Property tests
prop checks a law over values generated with Gen. A failing input is reduced to a smaller one that still fails. Law states textbook laws, such as an involution or a round trip, and a failure names each term.
prop "rev is an involution" Gen.(list int) (Law.involutive (list int) List.rev)Stateful tests
stateful runs generated programs of calls on a system and on a reference, such as a model of its state or another implementation, and compares what each call returns or raises. A failing program is reduced to a shorter one and printed as the calls that ran. With ~domains:2, the middle of each program runs on two domains at once, and the test fails when no order of the calls explains the results.
command "pop" (queue ^-> returns int) Model.pop Bounded_queue.popExpect tests
expect compares a string with a literal in the test's source, and expect_file with a file. ppx_windtrap provides let%expect_test and [%expect]. dune promote accepts a change.
expect (Printf.sprintf "%d items" (List.length cart)) @@ __POS_OF__ {|3 items|}Coverage
ppx_windtrap.coverage instruments a library, and windtrap coverage reports the expressions that the tests did not run.
dune runtest --instrument-with ppx_windtrap.coverage
dune exec windtrap -- coverageMutation testing
ppx_windtrap.mutate compiles mutants of a library, small changes such as >= into >, into its test executables. --mutate runs the tests on each mutant and reports the mutants that no test fails on.
dune exec --instrument-with ppx_windtrap.mutate test/test_calc.exe -- --mutateInstallation
opam install windtrap
opam install ppx_windtrap # expect tests, coverage, mutation testingDocumentation
The manual, doc/manual/, has one page per need:
- Tutorial: Getting started, the suite above and its first failure.
How-to:
- Assertions: values, bounds, strings, results and exceptions.
- Property testing: laws over generated values.
- Stateful testing: a system against a reference.
- Baselines and expect tests:
expect,expect_file,let%expect_test. - Resources and structure: a suite's layout and resources.
- Running tests: selection, reruns,
dune runtestand CI. - Coverage: the code no test runs.
- Mutation testing: the changes no test notices.
- Migrating from 0.2: each breaking change since 0.2 and what a suite writes now.
- Migrating from 0.1: each 0.1 spelling and its replacement.
- Explanation: Design notes, why windtrap is shaped as it is.
- Reference:
lib/windtrap.mli,lib/testable.mlifor the witness constructors ofWindtrap.Testable, andppx/ppx_windtrap.mlifor the inline test forms.
Questions are welcome on the OCaml forum.
Examples
examples/ holds the project of each manual page, run by dune runtest; its README lists them.
Acknowledgments
Windtrap builds on ideas and code from several OCaml projects:
- Alcotest by Thomas Gazagnaire: test structure and runner design.
- Craig Ferguson's Alcotest PRs (#294, #247): API design, subcomponent diffing.
- QCheck2 by Simon Cruanes et al.: generator design and integrated shrinking.
- Monolith by François Pottier, and qcheck-stm by Jan Midtgaard et al.: stateful testing against a reference, on one domain or several.
- ppx_expect and ppx_inline_test by Jane Street: expect test paradigm and dune integration, and ppx_expect's test corpus.
- Bisect_ppx by Anton Bachin et al.: coverage instrumentation and runtime.
- mutaml by Jan Midtgaard: mutation testing for OCaml as a PPX, with every mutant compiled into one build.
- mtime by Daniel Bünzli: the monotonic clock.
THIRD_PARTY_LICENSES.md holds the notices of the code derived from them.
Dev Dependencies (1)
-
odoc
with-doc
Optional Dependencies
None
Used by (5)
-
matrix
>= "0.2.0" -
mosaic
>= "0.2.0" -
ppx_windtrap
>= "0.3.1" - thumper
-
toffee
>= "0.2.0"
Conflicts
None
Build status
Results of building windtrap with each compiler on check.ci.ocaml.org, run of against opam-repository 8d8d144. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.3.1 (this version) | n/a | n/a | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure