Next: , Previous: , Up: API  


1.12 (veritas snapshot)

Snapshot testing: compare a value with the one recorded the first time the check ran. A missing snapshot is written and the check passes, so a new test does not fail merely for being new. A mismatch fails and shows both sides, and VERITAS_UPDATE_SNAPSHOTS=true rewrites every snapshot the run reaches, which is how an intended change is accepted.

A snapshot is Scheme data, read back with ‘read’: lists, vectors, strings, numbers, symbols and alists travel exactly. Procedures, records and ports do not, so snapshot the string they print instead.

1.12.1 Procedures

Procedure: assert-snapshot KEY: #:got #:name #:dir

Assert that got matches the snapshot recorded under name.

name labels the assertion and names the file, so it is required; the file lives under VERITAS_SNAPSHOT_DIR (default test/snapshots) or under dir. The first run writes the snapshot and passes. Later runs compare with equal?, and a mismatch fails with both values. A snapshot that cannot be read is a failure too, never a silent rewrite.

A got that is a procedure is called with no arguments when the assertion runs, so state that only exists at test time can be snapshotted.

(assert-snapshot #:name "the rendered cart"
                 #:got (lambda () (render (make-cart))))
Procedure: snapshot-path name KEY: #:dir

Return the file holding the snapshot called name.

dir overrides VERITAS_SNAPSHOT_DIR, which itself defaults to test/snapshots.

Procedure: snapshot-update?

Return #t when snapshots are to be rewritten instead of compared.

Set VERITAS_UPDATE_SNAPSHOTS to true to accept the current value of every snapshot a run reaches.


Next: (veritas table), Previous: (veritas shuffle), Up: API