Repository navigation
0.3.0
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 fnis one test that runs every row
and reports each refuted one, asrow 2 of 5: b, where 0.2.0's
cases ~name base inputs fndeclared one test per row;-f,-v,
~timeout,~retriesand 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;?labelshows a text beside a row and
identifies nothing. - A
skipin a row skips that row alone, and a table skips only when
every row skipped;-vsaysholds on 2 of 3 rows, 1 skipped: no GPU. - A row keeps or withholds its baseline corrections, and refuses
collect,classifyandcover, as a test of its own did in 0.2.0. - (breaking)
slow : test -> testandtag : string -> test -> test
mark any test or group, asfocusandxfaildo, and?tagsis
removed from every constructor;slow name fnis
slow @@ test name fn.
Assertions
- (breaking)
starts_with ~prefix,ends_with ~suffixand the?sub
ofExn.invalid_arg,Exn.failureandExn.sys_errorreplace
~affixand?substring, as inString.starts_with,
String.ends_withandcontains. - (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 fcallsfuntil a call returns, for at most
withinseconds, and fails with the last call's failure
(doc/manual/assertions.md#checking-inside-a-callback-or-until-a-claim-holds).slist t cmpcompares two lists as multisets undert's equality and
usescmponly to sort, where 0.2.0 found equal multisets unequal
under a coarsercmp; a failure says
multisets differ: 2 missing, 1 extrain place of a diff.equalunderfloat epsorfloat_relrecords the largest error it
saw, which a failing block,-vand--jsonstate, 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 throughFormat.ucharis the witness forUchar.t, printed asU+00E9.float_exact,float eps,float_reland the float generators
printinfinity,neg_infinityandnan, where 0.2.0 printed
inf,-infand, under some C libraries,-nan.
Property testing
- (breaking) A test that refuted nothing and checked less than it
claims is vacuous, a failing verdict taggedVACUOUSand counted
apart in the summary: a property whose every case was discarded, an
unmetcover, a stateful command never called, a table with no row,
and~count:0with no example, which passed in 0.2.0. - (breaking)
cover ~share:p label conddemands that a sharepof the
cases carrylabel, judged as QuickCheck'scheckCoveragejudges 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_exactorexpect_filein 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.nativeintand a range over a type'smin_intto
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.floatandGen.float_rangedraw 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.charandGen.char_rangedraw a corner one time in ten, as the
integer ranges do, so a defaultGen.stringholds 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
~sizecan 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
throughGen.bindand 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.eitherandGen.frequencyshrink towardOk,
Leftand the first generator of positive weight, and-0.shrinks
to0..- A failing property prints the line that keeps its counterexample,
keep it: ~examples:[ … ]when its generators print OCaml and
replay it: -f PATH --replay TOKENotherwise
(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-vsaysholds 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_discarddefaults 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.uchardraws a Unicode scalar value, each UTF-8 length equally
likely, andGen.any_floatdrawsnan,infinityandneg_infinity
beside the finite floats.Gen.int32_range,Gen.int64_rangeandGen.nativeint_range
generate in a range of their type, asGen.int_rangedoes.Gen.permutation ~pp valuesshufflesvaluesand shrinks toward
their order, andGen.subsequence ~pp valueskeeps some of them in
order and shrinks toward[].
Stateful testing
- (breaking)
judges wreplaceschooses 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 candidatesis the type of the elements that a value oft
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 areplay 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" textlabels the file,
whose two positional strings compiled swapped in 0.2.0; a report
names the baseline as the call writes it. - (breaking)
expect_filecompares the final newline, which 0.2.0 gave
both sides, and-uand--correctedwrite the text byte for byte;
the block says
values differ only by a trailing newline (on the expected side). - Under
CIa baseline mismatch fails the run in every mode; a
--correctedrun 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 onedune promotetakes every
stale file of a run, where 0.2.0'sprognstopped 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 callsexit, segfaults, raisesOut_of_memoryor
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 declarationslazyor afixture. - (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
~timeoutor
--timeoutsets one, where 0.2.0 let a test run forever; the runner
ownsSIGALRMduring 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 inNworkers at once; the
default is one, and the report, the exit code and the corrections do
not depend on it.--in-processruns 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 PATHchecks the property or stateful test that-fselects
on the case that the bytes ofPATHdecode to, and every file decodes
to a case.--failedreruns 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
--failedreads is kept per executable and
suite, so two executables with one suite name no longer erase each
other's; the first--failedafter upgrading finds no record. --failedwith 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;
aPATHnot ending in.jsonis a directory, as for--junit.- Under
-va 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-ucommand
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 belowN, a declared~countincluded, and lowers
none. - A project built inside another's
_build, asdune-release distrib
builds one, finds its own build directory belowDUNE_SOURCEROOT;
0.2.0 took the outer_build, so its inline tests wrote no correction
and its paths kept_build/default.
Coverage
invalid_argandexitjoinraiseandfailwithas 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 asn > 0 || failwith "negative"no longer reads uncovered when
a test ran it.windtrap coverage --lines FILE:A-B,...and--diff FILE, the output
ofgit 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 said100.0%, and a--minover no point is met.
Mutation testing
--mutateandwindtrap mutantstake--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 mutantsnames it undernot mutation-testedand exits 1. - Under
--mutateand--armthe 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
-jat 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:
deldropse1frome1; e2,
intnudges an integer literal andboolflips a boolean outside a
condition, each skipping code where a survivor asks for no test worth
writing
(doc/manual/mutation.md#what-is-mutated).