← docs1 min read

5. Tests

A test step checks the things a cook step produced. It declares no outputs; its exit code is the verdict. A test inherits the preceding cook step's outputs as…

manual

A test step checks the things a cook step produced. It declares no outputs; its exit code is the verdict. A test inherits the preceding cook step’s outputs as its inputs (or the recipe’s gather if no cook ran):

recipe check
gather "src/*.c"
cook "build/$<in.stem>" { gcc $<in> -o $<out> }
test { ./$<in> --selftest }

A failure in one test unit doesn’t cancel the others: cook collects every failure and reports them together. There are no test modifiers; to write a check that’s expected to fail, invert the command with !:

recipe lint
gather "src/*.c"
test { ! grep -q TODO $<in> }

cook test runs every test in the workspace and aggregates a pass/fail summary. Because test results are content-keyed to the outputs they consume, unchanged code doesn’t re-run its tests.

Terminal window
cook test # everything
cook test apps.web # scope to a namespace
cook test --fail-fast # stop on first failure
cook test --rerun-failed # re-run only what failed last time
cook test --report-junit results.xml