Target

:= [Target({ name : Str, run! : List(U8) => U8, show : List(U8) -> Str, example_count : () -> U64, example : U64 -> { name : Str, revision : Str, bytes : List(U8) }, goals : () -> List(Str) }), Targets(List(Target))]

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.

with_goals : Target, List(Str) -> Target

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.

goals : Target -> List(Str)

The goals this target declares, in declaration order.

new_suite : List(Target) -> Target

Assemble a flat inventory for the native runner. Prefer Fuzz.suite.

count : Target -> U64

Number of independently selectable properties.

get : Target, U64 -> Try(Target, [OutOfBounds])

Select a member without decoding or changing its corpus bytes.

name : Target -> Str

Return the human-readable target name reported by the executable.

run! : Target, List(U8) => U8

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.

show : Target, List(U8) -> Str

Decode one raw input into a human-readable typed value.

example_count : Target -> U64

Number of source-declared examples, independent of corpus retention.

example : Target, U64 -> { name : Str, revision : Str, bytes : List(U8) }

Prepare one source example as corpus bytes. The native host copies the returned fields and releases all temporary Roc values before execution.