Advanced, type-erased bridge between a typed Roc property and the native
runner.
Applications normally construct this value with Fuzz.target or
Fuzz.target_with and expose it as target. The methods here define the
small byte-oriented ABI consumed by the embedded runner.
new : { name : Str, run! : List(U8) => U8, show : List(U8) -> Str, example_count : () -> U64, example : U64 -> { name : Str, revision : Str, bytes : List(U8) } } -> Target
Construct a target from low-level runner callbacks.
run! returns zero for a kept input and a non-zero status for a rejected
input. Failures should use crash or expect rather than status codes.
Declare goals: named events that some kept input of a campaign must
reach. An input reaches a goal by recording an event of that name with
Fuzz.mark! or by completing a measured region of that
name. A campaign is the declared examples, the saved corpus and
exploration together.
target = Fuzz.target_with!({
name: "parse",
examples: [],
generator: Fuzz.bytes,
test!: |input| {
match parse(input) {
Ok(_) => Fuzz.mark!("parsed a document")
Err(_) => Fuzz.mark!("refused a document")
}
Fuzz.keep
},
show: Str.inspect,
}).with_goals(["parsed a document", "refused a document"])
Every other trace rule is judged on each input. A goal is judged once,
over the campaign: the report lists the goals reached, each with the
first input that reached it, and the goals never reached. A goal no
input reached makes the campaign inconclusive. Reaching one is never
a finding.
The inventory is part of the target, so the runner knows every goal
before any input runs. It refuses an inventory whose names are not
unique, nonempty and at most 128 bytes each, or that has more than 1024.
Calling this again adds to the goals already declared.
Decode and test one raw input, returning the runner status code.
This is effectful so a target may read the platform's allocation
counters (see Fuzz.alloc_count!). A target whose property needs no
effects can still be written as a plain pure function
a pure body
satisfies this signature unchanged.