spawn test compare
Usage
spawn test compare <name> Runs tests and compares their output against saved expected results, reporting any differences.
Arguments
Section titled “Arguments”<name>— Specific test to compare.
Behavior
Section titled “Behavior”For each test:
- Runs the test and captures its output
- Compares that output to the
expectedfile in the test directory - Reports differences (if any)
Use spawn test expect to update the expected output.
Notices and errors
Section titled “Notices and errors”If a test produces NOTICE, WARNING or error messages, they are recorded at the end of the expected file, below a --- diagnostics --- line:
ok---- 1(1 row)
--- diagnostics ---NOTICE: table "audit_log" does not exist, skippingA test that produces no messages has no such line — its expected file is just query output.
An error does not automatically fail a test. It is recorded like anything else and compared, so a test can deliberately expect one; it fails only if the message changes. By default PostgreSQL stops at the first error, so later statements do not run — put \set ON_ERROR_STOP off at the top of the test to keep going.
Messages are grouped at the end rather than shown beside the statement that produced them, because PostgreSQL does not emit them in a reproducible order. If it matters where one occurred, print a marker with \echo and the marker will appear in the query output.
Secrets
Section titled “Secrets”test compare always masks secret() values so real secrets cannot appear in test output or diffs. See the Secrets guide for details.
Example
Section titled “Example”spawn test compare user-creationOptions
| Option | Description |
|---|---|
-e, --environment <name> | Override the environment for the target config. |
--target <name> | Select which target from spawn.toml to use. |
--config-file <path> | Path to config file. Defaults to spawn.toml. |
-d, --debug | Turn on debug output. |