mix corpus.generate (predicator v7.0.0)

Copy Markdown View Source

Regenerates conformance/corpus/tier-*.json and conformance/manifest.json from the authored cases in conformance/cases/*.json (px-35i.4).

Each authored case is run through the real compiler and evaluator by Predicator.Conformance.Generator.generate/1, which fills in instructions, expected_result/expected_error, tier, and features. This task is the thin I/O shell around that pure function: it reads the authored files, writes the completed corpus (one case per line, sorted by id, via Predicator.Conformance.JSON.encode_lines/1) and the manifest, and is otherwise deliberately free of logic - anything that needs a test belongs in Predicator.Conformance.*, not here.

Usage

mix corpus.generate          # regenerate and write conformance/corpus/ and manifest.json
mix corpus.generate --check  # regenerate in memory, diff against the checked-in files,
                              # write nothing, exit non-zero on drift (for CI)

A case that fails to generate - a compile error, an authored expected or tier mismatch, an unknown opcode, and so on - prints every failing case's id and problem (not just the first) and exits non-zero without writing anything.

Summary

Types

Relative path (from the project root) mapped to the exact bytes it should contain.

Functions

Reads conformance/cases/*.json, runs Predicator.Conformance.Generator.generate/1, and returns the exact file map mix corpus.generate would write: relative path (from the project root) mapped to the exact bytes that file should contain.

Types

file_map()

@type file_map() :: %{required(String.t()) => binary()}

Relative path (from the project root) mapped to the exact bytes it should contain.

Functions

build_files()

@spec build_files() ::
  {:ok, file_map()} | {:error, [Predicator.Conformance.Generator.case_error()]}

Reads conformance/cases/*.json, runs Predicator.Conformance.Generator.generate/1, and returns the exact file map mix corpus.generate would write: relative path (from the project root) mapped to the exact bytes that file should contain.

Public so test/predicator/conformance/corpus_freshness_test.exs can regenerate in memory and byte-compare against the checked-in files without duplicating the assembly logic (tier file naming, canonical encoding, the corpus_hash computation) - a second hand-maintained copy of that logic is exactly the kind of drift this whole bead exists to prevent.