Module

poke/corpus

src/poke/corpus.pooka

A 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.

Pooka
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

src/poke/corpus.pooka:28
interface Codec(a)

Change the property name when its encoding or accepted domain changes.

method

encode

src/poke/corpus.pooka:29
encode(value: a) -> String
method

decode

src/poke/corpus.pooka:31
decode(text: String) -> Result(a, String)
class

Failure

src/poke/corpus.pooka:35
class Failure(
  message: String,
  value: Option(a),
  generated: Option(property.Failure(a))
)

Storage errors have no value; observed failures retain their counterexample.

field

message

src/poke/corpus.pooka:36
message: String
INFERREDString
field

value

src/poke/corpus.pooka:37
value: Option(a)
INFERREDOption(a)
field

generated

src/poke/corpus.pooka:38
generated: Option(property.Failure(a))
INFERREDOption(poke/property.Failure(a))
constructor

new

src/poke/corpus.pooka:36
INFERREDfn(String, Option(a), Option(poke/property.Failure(a))) -> poke/corpus.Failure(a)
class

Store

src/poke/corpus.pooka:49
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.

field

directory

src/poke/corpus.pooka:49
directory: String
INFERREDString
constructor

new

src/poke/corpus.pooka:49
INFERREDfn(String) -> poke/corpus.Store
method

examples

src/poke/corpus.pooka:51
examples(name: String, codec: Codec(a)) -> Result(List(a), String)
INFERREDfn(String, poke/corpus.Codec(a)) -> Result(List(a), String)

Decode the complete corpus. A corrupt file is an error, never a skipped test.

method

check

src/poke/corpus.pooka:58
check(
    name: String,
    source: Generator(a),
    codec: Codec(a),
    predicate: fn(a) -> Bool,
    config: property.Config
  ) -> Result(property.Report, Failure(a))

Replay stored examples first, then generate and shrink new cases. A newly discovered failure is saved before being returned to the caller.

method

for_all

src/poke/corpus.pooka:89
for_all(
    name: String,
    source: Generator(a),
    codec: Codec(a),
    assertion: fn(a) -> Nil,
    config: property.Config
  ) -> Nil
INFERREDfn(String, poke/generator.Generator(a), poke/corpus.Codec(a), fn(a) -> Nil, poke/property.Config) -> Nil

Assertion-style properties use the same corpus and native failure channel.

function

defaults

src/poke/corpus.pooka:138
defaults() -> Store
INFERREDfn() -> poke/corpus.Store

Keep regression inputs beside the tests rather than in the build cache.

Pooka
let saved = corpus.defaults()
// saved.for_all("integer-roundtrip-v1", source, codec, assertion, property.defaults())