Skip to content

0.3.0

Choose a tag to compare

@tmattio tmattio released this 30 Oct 20:26
· 27 commits to main since this release

CHANGES:

Windtrap 0.3.0 changes how property tests shrink and where tests run,
with few changes to the interface.

Generators now read a sequence of random choices, and shrinking reduces
that sequence and runs the generator again, as Hypothesis does
(MacIver and Donaldson, ECOOP 2020).
0.2.0 shrank each value through a tree of smaller candidates, which
cannot shrink across Gen.bind or change a value's shape. On benchmarks
that need such a change, 0.3.0 reaches the smallest counterexample on
every seed, where 0.2.0 reached it on 15% (a calculator's expressions)
and 47% (nested lists).

Outside Windows, each test now runs in a worker process, so a test that
crashes, calls exit or hangs fails by name and the run goes on. A
worker starts the test executable again, so module initialisation runs
once per worker start. On raven's suites a run took about 3% longer than
under 0.2.0, except where a suite opens a GPU at initialisation and pays
for it in each new worker.

Highlights

A crash or a hang fails one test, not the run. In 0.2.0 a test that
segfaulted or ran out of memory ended the run with no summary, and a
test that never returned kept the build waiting forever. Outside
Windows, tests now run in worker processes, so such a test fails by
name and the run goes on, and every test stops after ten minutes unless
~timeout or --timeout sets another limit. -j N runs the tests in
N workers at once.

A failure inside a catch-all is no longer lost. In 0.2.0 an equal
that failed inside try … with _ -> (), or inside a library that
ignores what its callbacks raise, passed the test. A failing verb now
records its failure before it raises, and the block says
failed, then caught. To retry a claim until it holds, use
eventually ~within f.

A verdict says what it checked. In 0.2.0 a property with
~count:0 and no examples passed, and a passing test never said how
much it had run. Now a test that checks nothing fails as VACUOUS, with
a line that says why, as do a property whose every case was discarded,
an unmet cover, a stateful command never called and a table with no
row. Under -v a passing test says what it ran, as
(100 cases, 2 examples, 14 discards) or holds on all 3 rows, and a
float comparison reports the largest error it saw against its
tolerance; --json writes all of it.

Property tests find bugs sooner and shrink them further. Shrinking
now works on the choices a generator made, so it can shrink through
Gen.bind and rewrite a value's structure. On benchmarks that need such
a rewrite it reaches the smallest counterexample on every seed, where
0.2.0 reached it on 15% (a calculator's expressions) and 47% (nested
lists). Generators draw edge cases and repeated values more often, and
the whole integer types draw small values first, so on planted bugs in
search trees and a lambda calculus a failure comes after 22 cases on
average, against 68. A failure prints a keep it: ~examples:[ … ] line
to paste into the test.

Stateful tests on several domains check linearizability. In 0.2.0
the judge accepted any order of the parallel calls that kept each
domain's program order, so a structure that was only sequentially
consistent passed. Now a call that returned before another began must
come first.

Mutation testing and coverage can judge one change. Given the output
of git diff -U0, --mutate --diff FILE tests only the mutants on the
changed lines, and windtrap coverage --diff FILE reports only their
points. Mutant verdicts no longer change from run to run, and a mutant
that no run could judge is reported as unknown, never as a survivor.

Declaring tests

  • (breaking) cases name ~id rows fn is one test that runs every row
    and reports each refuted one, as row 2 of 5: b, where 0.2.0's
    cases ~name base inputs fn declared one test per row; -f, -v,
    ~timeout, ~retries and the summary see one test
    (doc/manual/resources-and-structure.md#checking-a-table-of-inputs).
  • A row is identified by ~id row, and two rows with one id fail the
    table before any row runs; ?label shows a text beside a row and
    identifies nothing.
  • A skip in a row skips that row alone, and a table skips only when
    every row skipped; -v says holds on 2 of 3 rows, 1 skipped: no GPU.
  • A row keeps or withholds its baseline corrections, and refuses
    collect, classify and cover, as a test of its own did in 0.2.0.
  • (breaking) slow : test -> test and tag : string -> test -> test
    mark any test or group, as focus and xfail do, and ?tags is
    removed from every constructor; slow name fn is
    slow @@ test name fn.

Assertions

  • (breaking) starts_with ~prefix, ends_with ~suffix and the ?sub
    of Exn.invalid_arg, Exn.failure and Exn.sys_error replace
    ~affix and ?substring, as in String.starts_with,
    String.ends_with and contains.
  • (breaking) A failing verb records its failure in the test before it
    raises, so a catch-all around it, in the test or on a domain the test
    spawned, no longer passes the test; the block says
    failed, then caught.
  • eventually ~within f calls f until a call returns, for at most
    within seconds, and fails with the last call's failure
    (doc/manual/assertions.md#checking-inside-a-callback-or-until-a-claim-holds).
  • slist t cmp compares two lists as multisets under t's equality and
    uses cmp only to sort, where 0.2.0 found equal multisets unequal
    under a coarser cmp; a failure says
    multisets differ: 2 missing, 1 extra in place of a diff.
  • equal under float eps or float_rel records the largest error it
    saw, which a failing block, -v and --json state, as
    tolerance at test/t.ml:12: largest error 3e-12 of 1e-06 allowed, over 40 comparisons.
  • output () on a domain the test spawned reads what that domain
    printed through Format.
  • uchar is the witness for Uchar.t, printed as U+00E9.
  • float_exact, float eps, float_rel and the float generators
    print infinity, neg_infinity and nan, where 0.2.0 printed
    inf, -inf and, under some C libraries, -nan.

Property testing

  • (breaking) A test that refuted nothing and checked less than it
    claims is vacuous, a failing verdict tagged VACUOUS and counted
    apart in the summary: a property whose every case was discarded, an
    unmet cover, a stateful command never called, a table with no row,
    and ~count:0 with no example, which passed in 0.2.0.
  • (breaking) cover ~share:p label cond demands that a share p of the
    cases carry label, judged as QuickCheck's checkCoverage judges it,
    and states the bound it established, as
    cover "accepted" ~share:0.2: 27.9% of 800 cases, at least 19.3%;
    cover's type is ?share:float -> string -> bool -> unit
    (doc/manual/property-testing.md#discarding-and-labelling-cases).
  • (breaking) An expect, expect_exact or expect_file in the law of
    a property or a stateful test fails its case as any verb does, so the
    case shrinks and no correction is written, where 0.2.0 recorded every
    case's mismatch and passed the case.
  • (breaking) The whole integer types, Gen.int, Gen.int32,
    Gen.int64, Gen.nativeint and a range over a type's min_int to
    max_int, draw small values and the edges of powers of two first,
    and a draw repeats an earlier value of its generator one time in
    eight; on ETNA-style workloads a planted bug fails after 22 cases on
    average, against 68, and a case costs up to 1.9 times as much to draw.
  • Gen.float and Gen.float_range draw a corner case one time in ten,
    such as -0., the least subnormal, the greatest finite float or a range's
    bounds; a property that passed under 0.2.0 can fail on one.
  • Gen.char and Gen.char_range draw a corner one time in ten, as the
    integer ranges do, so a default Gen.string holds a NUL in 7.7% of
    the cases, against 1.8%
    (doc/manual/property-testing.md#generating-strings-and-alphabets).
  • A list, array, string or bytes drawn without ~size can be up to 255
    long, where 0.2.0 stopped at 63; one in 133 is 64 or longer.
  • A seed or a replay: line that 0.2.0 printed draws other cases; a
    replay token holds the case's choices and still replays its case.
  • Shrinking works on the choices a generator read, so it shrinks
    through Gen.bind and can merge two inner lists or replace a node by
    its subterm, which 0.2.0's trees could not
    (doc/manual/property-testing.md#reading-a-counterexample).
  • Gen.result, Gen.either and Gen.frequency shrink toward Ok,
    Left and the first generator of positive weight, and -0. shrinks
    to 0..
  • A failing property prints the line that keeps its counterexample,
    keep it: ~examples:[ … ] when its generators print OCaml and
    replay it: -f PATH --replay TOKEN otherwise
    (doc/manual/property-testing.md#keeping-a-counterexample-as-a-regression).
  • A property whose generator has no more values than its count runs its
    law once on each, and -v says holds on all N values; a failure
    reports every value refuted, none shrunk.
  • After the search the law runs once more on the counterexample, and
    when it passes the block says
    the test did not fail again on this counterexample; it is not deterministic.
  • A failing block shows the output captured on the counterexample, and
    prints the counterexample as it was drawn, where 0.2.0 showed the
    search's last output and the value as the law left it.
  • ~max_discard defaults to ten discards per case, where 0.2.0 allowed
    two, so a law that keeps an eighth of its cases no longer gives up by
    chance.
  • A generator that overflows the stack still fails its case, and the
    report names the likely cause
    (doc/manual/property-testing.md#generating-a-recursive-type).
  • On a terminal the live line says when a test is shrinking, as
    [3/10] lists › rev: shrinking, 12 steps….
  • Gen.uchar draws a Unicode scalar value, each UTF-8 length equally
    likely, and Gen.any_float draws nan, infinity and neg_infinity
    beside the finite floats.
  • Gen.int32_range, Gen.int64_range and Gen.nativeint_range
    generate in a range of their type, as Gen.int_range does.
  • Gen.permutation ~pp values shuffles values and shrinks toward
    their order, and Gen.subsequence ~pp values keeps some of them in
    order and shrinks toward [].

Stateful testing

  • (breaking) judges w replaces chooses w, and its reference rules on
    the system's outcome instead of returning the one it accepts; an
    exception other than a verb's failure or the system's own is reported
    as a bug of the reference
    (doc/manual/stateful-testing.md#judging-calls-against-a-rule).
  • (breaking) On several domains the judge accepts only the orders that
    keep real time, so the test checks linearizability, where 0.2.0
    checked program order alone.
  • among w t candidates is the type of the elements that a value of t
    lists, such as an array's indices, and a call that takes one reads it
    from that value when it runs
    (doc/manual/stateful-testing.md#taking-an-argument-from-what-a-value-lists).
  • A case draws each command with probability 3/4, where 0.2.0 drew it
    with 1/2, so a planted recency bug in an LRU cache is found on 142 of
    200 seeds instead of 82; stateful suites run about 10% slower.
  • A program shrinks as a property's value does, and a failing program
    prints a replay it: line; the guide's set shrinks to its minimum on
    88% of seeds, against 66%.
  • A command list with no more programs than the count has each program
    checked once, as a finite domain is.
  • A counterexample's table of calls escapes control bytes, keeps its
    columns straight and ends no row in blanks.
  • On several domains the labels of the parallel calls count along the
    order the judge accepted in each run, where 0.2.0 counted the first
    run's.

Baselines and expect tests

  • (breaking) expect_file ~file:"golden/x.txt" text labels the file,
    whose two positional strings compiled swapped in 0.2.0; a report
    names the baseline as the call writes it.
  • (breaking) expect_file compares the final newline, which 0.2.0 gave
    both sides, and -u and --corrected write the text byte for byte;
    the block says
    values differ only by a trailing newline (on the expected side).
  • Under CI a baseline mismatch fails the run in every mode; a
    --corrected run still writes the correction and says on standard
    error why it exits 1.
  • The manual's dune stanza wraps its diff? actions in
    (concurrent …) (lang dune 3.8), so one dune promote takes every
    stale file of a run, where 0.2.0's progn stopped at the first
    (doc/manual/baselines.md#running-expectations-under-dune).

Running tests

  • Tests run in worker processes, never in the process that calls run,
    so a test that calls exit, segfaults, raises Out_of_memory or
    loops in C past its limit fails, saying which, and the run goes on;
    in 0.2.0 some of these passed a test, ended a failed run with 0 or
    ended it with no summary
    (doc/manual/running-tests.md#running-tests-in-worker-processes).
  • A worker starts the test executable again, so module initialisation
    runs once per worker start and what a declaration opens is the
    worker's own; make expensive declarations lazy or a fixture.
  • (breaking) A suite declares the same tests at each start of the
    program; a worker that declares others fails the tests it was to run,
    saying so.
  • (breaking) Every attempt has a limit, ten minutes unless ~timeout or
    --timeout sets one, where 0.2.0 let a test run forever; the runner
    owns SIGALRM during every test outside --in-process, and Windows
    enforces no limit.
  • A test still running three limits after it started is killed with its
    worker and times out.
  • -j N (WINDTRAP_JOBS) runs the tests in N workers at once; the
    default is one, and the report, the exit code and the corrections do
    not depend on it.
  • --in-process runs one selected test in the calling process, with no
    limit, for a debugger.
  • A worker retires after a test that spawned a domain, and an at_exit
    handler that a test registers runs as its worker ends; one that
    raises fails the run and names the test.
  • --replay TOKEN (WINDTRAP_REPLAY) checks the selected property or
    stateful test on the case a failure printed, judging no vacuity; a
    token its generator now parses differently fails as stale.
  • --case PATH checks the property or stateful test that -f selects
    on the case that the bytes of PATH decode to, and every file decodes
    to a case.
  • --failed reruns the cases that failed, a table's rows and each
    recorded counterexample, drawing nothing; a test whose failure
    belongs to no case reruns whole.
  • (breaking) The record that --failed reads is kept per executable and
    suite, so two executables with one suite name no longer erase each
    other's; the first --failed after upgrading finds no record.
  • --failed with nothing to rerun says why: the last run passed, no run
    recorded failures, the record cannot be read, or it names no test of
    the suite.
  • --json PATH (WINDTRAP_JSON) writes the results as one versioned
    JSON document, a test per line with its verdict, failures and scope;
    a PATH not ending in .json is a directory, as for --junit.
  • Under -v a passing property says what it ran, as
    PASS sorts 1.2ms (100 cases, 2 examples, 14 discards), and a
    failing one's block says what passed before it failed, as
    scope: 37 cases passed, 3 discards.
  • Under dune no block prints accept:, and the report ends on one
    accept: dune promote FILES, printed only when the run exits 0; when
    dune withholds the corrections, the warning names the -u command
    that accepts them (doc/manual/baselines.md#accepting-a-change).
  • A selection that keeps no test prints its list: line above the
    summary, so the summary is the last line of every report.
  • (breaking) --prop-count N (WINDTRAP_PROP_COUNT) raises the count of
    every property below N, a declared ~count included, and lowers
    none.
  • A project built inside another's _build, as dune-release distrib
    builds one, finds its own build directory below DUNE_SOURCEROOT;
    0.2.0 took the outer _build, so its inline tests wrote no correction
    and its paths kept _build/default.

Coverage

  • invalid_arg and exit join raise and failwith as calls with no
    point for their return, direct or through @@ or |>, and such a
    call as the right operand of || has no point for being true; code
    such as n > 0 || failwith "negative" no longer reads uncovered when
    a test ran it.
  • windtrap coverage --lines FILE:A-B,... and --diff FILE, the output
    of git diff -U0, report the points on those lines alone
    (doc/manual/coverage.md#measuring-a-changes-coverage).
  • A report with no point says coverage: no point to measure (0/0 points),
    where it said 100.0%, and a --min over no point is met.

Mutation testing

  • --mutate and windtrap mutants take --lines FILE:A-B,... and
    --diff FILE (WINDTRAP_LINES, WINDTRAP_DIFF) and judge the
    mutants on those lines alone; lines with no mutation site run the
    suite unmutated and say so
    (doc/manual/mutation.md#testing-a-changes-mutants).
  • (breaking) A mutant that no run could judge is unknown, with its
    reason, where 0.2.0 read it as a survivor, or as killed when its
    child crashed; a refused suite's verdict file says so, and
    windtrap mutants names it under not mutation-tested and exits 1.
  • Under --mutate and --arm the root seed is fixed unless --seed
    gives one, so a verdict no longer changes from run to run.
  • Each mutant runs in a fresh worker, up to -j at once, so its verdict
    does not depend on what earlier tests cached, and a suite that spawns
    a domain is mutation-tested, where 0.2.0 refused it.
  • A surviving or unknown mutant's block opens on its location in the
    compiler's format, which editors jump to; the verdict file is
    windtrap-mutants-v5, and an earlier one is refused.
  • Three rewrites join the catalogue: del drops e1 from e1; e2,
    int nudges an integer literal and bool flips a boolean outside a
    condition, each skipping code where a survivor asks for no test worth
    writing
    (doc/manual/mutation.md#what-is-mutated).