(options: FuzzRunOptions, body: FuzzBody)
| 134 | } |
| 135 | |
| 136 | export async function runFuzz(options: FuzzRunOptions, body: FuzzBody): Promise<FuzzRunSummary> { |
| 137 | const label = options.label ?? "fuzz"; |
| 138 | assertUInt32("seed", options.seed); |
| 139 | assertPositiveInteger("iterations", options.iterations); |
| 140 | |
| 141 | for (let iteration = 0; iteration < options.iterations; iteration++) { |
| 142 | const caseSeed = deriveFuzzCaseSeed(options.seed, iteration); |
| 143 | const notes: string[] = []; |
| 144 | const ctx: FuzzIterationContext = Object.freeze({ |
| 145 | label, |
| 146 | seed: options.seed >>> 0, |
| 147 | iteration, |
| 148 | caseSeed, |
| 149 | rng: createRng(caseSeed), |
| 150 | note(message: string): void { |
| 151 | notes.push(message); |
| 152 | }, |
| 153 | fail(message: string, cause?: unknown): never { |
| 154 | throw new FuzzFailureError( |
| 155 | { label, seed: options.seed >>> 0, iteration, caseSeed }, |
| 156 | cause === undefined ? new Error(message) : new Error(message, { cause }), |
| 157 | notes, |
| 158 | ); |
| 159 | }, |
| 160 | }); |
| 161 | |
| 162 | try { |
| 163 | await body(ctx); |
| 164 | } catch (cause: unknown) { |
| 165 | if (cause instanceof FuzzFailureError) throw cause; |
| 166 | throw new FuzzFailureError(ctx, cause, notes); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | return Object.freeze({ |
| 171 | label, |
| 172 | seed: options.seed >>> 0, |
| 173 | iterations: options.iterations, |
| 174 | }); |
| 175 | } |
| 176 | |
| 177 | export function fuzzTest(name: string, options: FuzzRunOptions, body: FuzzBody): void { |
| 178 | const label = options.label ?? name; |
no test coverage detected