This is an "experts only" module that exposes functions needed to run and
display tests. A typical user will use an existing runner library for Node or
the browser, which is implemented using this interface. A list of these runners
can be found in the README.
Test Runners which have had seeds distributed to them, and which are now either invalid or are ready to run. Seeded runners include some metadata:
Invalid runners had a problem (e.g. two sibling tests had the same description) making them un-runnable.Only runners can be run, but Test.only was used somewhere, so ultimately they will lead to a failed test run even if each test that gets run passes.Skipping runners can be run, but Test.skip was used somewhere, so ultimately they will lead to a failed test run even if each test that gets run passes.Plain runners are ready to run, and have none of these issues.Convert a Test into SeededRunners.
In order to run any fuzz tests that the Test may have, it requires a default run count as well
as an initial Random.Seed. 100 is a good run count. To obtain a good random seed, pass a
random 32-bit integer to Random.initialSeed. You can obtain such an integer by running
Math.floor(Math.random()*0xFFFFFFFF) in Node. It's typically fine to hard-code this value into
your Elm code; it's easy and makes your tests reproducible.
Return Nothing if the given Expectation is a pass.
If it is a fail, return a record containing the expectation
description, the Reason the test failed, and the given inputs if
it was a fuzz test. (If it was not a fuzz test, the record's given field
will be Nothing).
For example:
getFailureReason (Expect.equal 1 2)
-- Just { reason = Equal 1 2, description = "Expect.equal", given = Nothing }
getFailureReason (Expect.equal 1 1)
-- NothingDetermine if an expectation was created by a call to Test.todo. Runners
may treat these tests differently in their output.
A standard way to format descriptions and test labels, to keep things consistent across test runner implementations.
The HTML, Node, String, and Log runners all use this.
What it does:
Example:
[ "the actual test that failed"
, "nested description failure"
, "top-level description failure"
]
|> formatLabels ((++) "↓ ") ((++) "✗ ")
{-
[ "↓ top-level description failure"
, "↓ nested description failure"
, "✗ the actual test that failed"
]
-}These functions give you the ability to run fuzzers separate of running fuzz tests.
A Shrinkable a is an opaque type that allows you to obtain a value of type
a that is smaller than the one you've previously obtained.
Given a fuzzer, return a random generator to produce a value and a Shrinkable. The value is what a fuzz test would have received as input.
Given a Shrinkable, attempt to shrink the value further. Pass False to
indicate that the last value you've seen (from either fuzz or this function)
caused the test to fail. This will attempt to find a smaller value. Pass
True if the test passed. If you have already seen a failure, this will attempt
to shrink that failure in another way. In both cases, it may be impossible to
shrink the value, represented by Nothing.
A function which, when evaluated, produces a list of expectations. Also a list of labels which apply to this outcome.