package ppx_windtrap

All checked builds pass
  1. Overview
  2. Docs
PPX and instrumentation backend for windtrap

Install

dune-project
 Dependency

Authors

Maintainers

Sources

windtrap-0.3.1.tbz
sha256=9a8c7926c77b1c258010e027eb219164e46a036bfe2df32b34b8781884c8d11c
sha512=10d53181d709e713e8437774aecf8465153c7ce2cda5f42ede02c92cb6ada38a6dcd091566807d3c75b6c8017ca1ca012989ad4aa50788c6ab1fd6c4a1e927de

Description

Inline test syntax for windtrap (let%test, module%test, let%expect_test, [%expect], [%expect_exact], [%expect.output]) with corrections accepted via dune promote, plus two instrumentation backends enabled with dune's --instrument-with: ppx_windtrap.coverage for expression coverage and ppx_windtrap.mutate for mutation testing.

Tags

testing ppx expect-test coverage mutation-testing

Added 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.pop

Expect 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 -- coverage

Mutation 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 -- --mutate

Installation

    opam install windtrap
opam install ppx_windtrap   # expect tests, coverage, mutation testing

Documentation

The manual, doc/manual/, has one page per need:

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.

Dependencies (4)

  1. ppxlib >= "0.37.0"
  2. windtrap = version
  3. ocaml >= "5.0"
  4. dune >= "3.21"

Dev Dependencies (1)

  1. odoc with-doc

Optional Dependencies

None

Used by (3)

  1. matrix >= "0.2.0"
  2. mosaic
  3. toffee < "0.2.0"

Conflicts

None

Build status

Results of building ppx_windtrap with each compiler on check.ci.ocaml.org, run of against opam-repository 6e2873f. 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