init argv parses command-line arguments from argv. Called once by the generated test runner. Recognized flags: -source-tree-root, -diff-cmd, -partition, -list-partitions. Unrecognized flags are silently ignored. Subsequent calls are silently ignored.
exit () runs all registered tests, writes pending corrections, and terminates the process. Exits with code 0 on success or when corrections are written (to allow dune's diff action to run), and code 1 on test failures without corrections. If not running as the test runner, exits immediately with code 0.
am_test_runner () returns true if running as the inline test runner (i.e., init received the inline-test-runner argument).
Sourceval should_record_corrections : unit -> bool
should_record_corrections () returns true if correction recording is enabled. This is the case either when running as the inline test runner (am_test_runner) or when INSIDE_DUNE is set (enabling the dune promote workflow for executable-based expect tests).
Sourceval expect : loc:location->expected:string option-> unit
expect ~loc ~expected checks captured output against expected using normalized comparison (trailing whitespace and blank lines are trimmed). Pass None for expected to assert that no output was produced. When correction recording is enabled (should_record_corrections), records a correction for dune promote; otherwise just raises on mismatch.
raisesFailure.Check_failure
if output does not match.
Sourceval expect_exact : loc:location->expected:string option-> unit
expect_exact ~loc ~expected checks captured output against expected using exact byte-for-byte comparison. Otherwise behaves like expect (including correction recording when enabled).
output () returns and consumes raw captured output since the last expect, expect_exact, or output call. Returns "" if no output was captured.
Sourceval run_expect_test :
must_reach_count:int ->trailing_loc:location->(unit -> unit)->
unit
run_expect_test ~must_reach_count ~trailing_loc fn executes fn with must-reach and trailing-output checks. In inline mode, unmatched trailing output is recorded as an inserted [%expect] correction at trailing_loc.
Module-based Test Syntax
These functions support the module%test and let%test syntax for building test trees using a stack-based group nesting model.
Sourceval add_test :
?file:string ->?tags:string list->string ->(unit -> unit)->
unit
add_test ?file ?tags name fn adds a test case to the current group, or to the top-level if no group is open. tags are attached as label tags. file is used for inline-test partitioning.
Sourceval enter_group : ?file:string ->?tags:string list->string -> unit
enter_group ?file ?tags name starts a new test group. file is used for file-level scoping of test names.
run_tests name runs all registered tests under the suite name.
This call is optional in executable mode — if omitted, tests auto-execute when the program exits via an at_exit handler with the default suite name "Tests". Use [%%run_tests "Name"] to set a custom suite name.
In inline test mode, defers execution to exit which handles test running and correction file generation.