diff --git a/package.json b/package.json index d8817af..564b7ca 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "private": true, "license": "PMPL-1.0-or-later", "dependencies": { + "fast-check": "^4.0.0", "@rescript/runtime": "^12.0.0", "rescript": "^12.0.0" } diff --git a/tests/echidna/echidna-harness.mjs b/tests/echidna/echidna-harness.mjs index dc564d2..22e8e92 100644 --- a/tests/echidna/echidna-harness.mjs +++ b/tests/echidna/echidna-harness.mjs @@ -15,6 +15,7 @@ // Run: node tests/echidna/echidna-harness.mjs [--iterations N] [--echidna URL] import { parseModule } from "../../src/parser/Parser.mjs"; +import fc from "fast-check"; // ============================================================================ // Random Program Generator @@ -299,6 +300,27 @@ for (let i = 0; i < Math.min(iterations, 50); i++) { } } +console.log("\nProperty 5: fast-check fuzz oracle"); +fc.assert( + fc.property(fc.integer({ min: 0, max: 1000000 }), (seed) => { + const rng1 = new RNG(seed); + const rng2 = new RNG(seed); + const prog1 = genProgram(rng1); + const prog2 = genProgram(rng2); + + if (prog1 !== prog2) { + throw new Error(`Program generator diverged for seed ${seed}`); + } + + const r1 = parseModule(prog1); + const r2 = parseModule(prog2); + if (r1.TAG !== r2.TAG) { + throw new Error(`Parser result diverged for seed ${seed}`); + } + }), + { numRuns: Math.min(iterations, 100) }, +); + // ============================================================================ // ECHIDNA Submission (when running) // ============================================================================