Skip to content
Latchkey

dune "build @runtest ... FAILED" in CI

dune runs your tests through the @runtest alias. A failure means an expect/cram test produced output that differs from the recorded expectation, or a test raised an uncaught exception and exited non-zero.

What this error means

dune build @runtest or dune runtest fails, printing a diff between expected and actual output, or a "Fatal error: exception ..." from a failing test.

dune
File "test/test_calc.ml", line 1, characters 0-0:
Fatal error: exception Failure("expected 5, got 6")
FAILED test/test_calc.exe (exit 2)

Common causes

A real test assertion failed

The code under test produced a wrong result, so an assertion raised or an expect diff appeared.

A stale recorded expectation

The expected output in a cram/expect test drifted from intended behavior and needs promoting.

How to fix it

Read the diff or exception and fix the code

  1. Read the printed diff or "Fatal error: exception ..." line.
  2. Fix the code so the actual output matches the expectation.
  3. Re-run dune runtest to confirm it passes.
Terminal
dune runtest --force

Promote intended output changes

When the new output is correct, promote it so the recorded expectation matches, then commit the change.

Terminal
dune runtest
dune promote

How to prevent it

  • Run dune runtest locally before pushing.
  • Promote expect/cram changes deliberately, reviewing the diff.
  • Keep tests deterministic so CI matches local output.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →