Skip to main content

Crate lightweight_pdf_testing

Crate lightweight_pdf_testing 

Source
Expand description

Pixel-diff snapshot testing for rendered PDFs (issue #21): render → rasterize (pdftoppm, part of poppler-utils — already a required tool for this workspace’s own text-extraction tests, so this adds no new system dependency) → compare each page against a checked-in reference PNG, with a small per-pixel tolerance for renderer noise.

Deliberately independent of lightweight-pdf-test-support (that crate is this workspace’s own internal dev-dependency, never published) — this crate stands on its own, usable to pin any PDF (not just ones built with lightweight-pdf) against visual regressions.

Reference images are low-DPI grayscale PNG (DEFAULT_DPI) on purpose — this is a regression trip-wire, not a print-quality visual proof, and keeping them small keeps the repository’s history small.

let dir = std::path::Path::new("test-fixtures/snapshots");
lightweight_pdf_testing::assert_snapshot(dir, "invoice", &render());

Set UPDATE_SNAPSHOTS=1 to (re)write the reference images instead of comparing against them.

Enums§

SnapshotError

Constants§

DEFAULT_DPI
Low on purpose (see module doc) — this is a regression trip-wire, not a print-quality visual proof.
DEFAULT_TOLERANCE
Maximum per-pixel grayscale value difference (0-255) still counted as “the same” — absorbs the small amount of renderer anti-aliasing noise between otherwise-identical runs.

Functions§

assert_snapshot
check_snapshot with DEFAULT_DPI/DEFAULT_TOLERANCE, panicking with a descriptive message on any failure — the usual entry point from a #[test] function.
check_snapshot
Rasterizes pdf_bytes at dpi and compares every page against <snapshot_dir>/<name>-<page>.png. With UPDATE_SNAPSHOTS set (any value), (re)writes the reference images instead of comparing.