Module
poke/corpus
src/poke/corpus.pookaA bug that has been found should not need another lucky seed. Save the smallest failing value using an explicit text codec. Old examples run before fresh draws. Nothing evaluates Erlang terms or casts untyped data back into a test: the codec must validate every saved value on the way in.
class IntegerText with corpus.Codec(Int) {
encode(value: Int) -> String { int.to_string(value) }
decode(text: String) -> Result(Int, String) {
match int.parse(text) {
Ok(value) -> Ok(value)
Error(_) -> Error("expected an integer")
}
}
}
API reference
interface Codec(a)
Change the property name when its encoding or accepted domain changes.
encode(value: a) -> String
decode(text: String) -> Result(a, String)
class Failure(
message: String,
value: Option(a),
generated: Option(property.Failure(a))
)
Storage errors have no value; observed failures retain their counterexample.
message: String
Stringvalue: Option(a)
Option(a)generated: Option(property.Failure(a))
Option(poke/property.Failure(a))
fn(String, Option(a), Option(poke/property.Failure(a))) -> poke/corpus.Failure(a)class Store(directory: String)
Each property owns a directory of content-addressed .case files. Commit these small files with the tests. Concurrent saves of one value deduplicate.
directory: String
String
fn(String) -> poke/corpus.Storeexamples(name: String, codec: Codec(a)) -> Result(List(a), String)
fn(String, poke/corpus.Codec(a)) -> Result(List(a), String)Decode the complete corpus. A corrupt file is an error, never a skipped test.
check(
name: String,
source: Generator(a),
codec: Codec(a),
predicate: fn(a) -> Bool,
config: property.Config
) -> Result(property.Report, Failure(a))
fn(String, poke/generator.Generator(a), poke/corpus.Codec(a), fn(a) -> Bool, poke/property.Config) -> Result(poke/property.Report, poke/corpus.Failure(a))Replay stored examples first, then generate and shrink new cases. A newly discovered failure is saved before being returned to the caller.
for_all(
name: String,
source: Generator(a),
codec: Codec(a),
assertion: fn(a) -> Nil,
config: property.Config
) -> Nil
fn(String, poke/generator.Generator(a), poke/corpus.Codec(a), fn(a) -> Nil, poke/property.Config) -> NilAssertion-style properties use the same corpus and native failure channel.
defaults() -> Store
fn() -> poke/corpus.StoreKeep regression inputs beside the tests rather than in the build cache.
let saved = corpus.defaults()
// saved.for_all("integer-roundtrip-v1", source, codec, assertion, property.defaults())