Every .ts file under this directory is a real, compilable program that is
verified by cargo run -p perry-doc-tests on every PR. Documentation pages in
docs/src/ pull these files in via mdBook's {{#include}} directive, so the
code you see on the rendered docs site is the same code CI is checking.
- Create a
.tsfile under the appropriate subfolder (runtime/,ui/, etc.). - Start the file with a three-line banner:
// demonstrates: <one-line description>
// docs: docs/src/<page.md> (optional — where the example is referenced)
// platforms: macos, linux, windowsRuntime examples (non-UI) should list all three platforms. UI examples list whichever platforms their widgets support. The harness skips an example whose banner doesn't include the current host platform.
- Reference it from markdown:
\`\`\`typescript
{{#include ../../examples/ui/counter.ts}}
\`\`\`- (Optional) For runtime examples with deterministic stdout, create a
matching expected-output file at
_expected/<same/relative/path>.stdout. The harness will byte-compare actual stdout against it after trimming trailing whitespace.
| Folder | Content |
|---|---|
runtime/ |
Language and stdlib examples (non-UI). |
ui/ |
UI examples that open a window. Run with PERRY_UI_TEST_MODE=1. |
_expected/ |
Golden stdout files for runtime examples. |
_baselines/ |
Per-platform screenshot baselines (added in the gallery PR). |
_harness/ |
Shared bootstrap/helper files, not discovered as tests. |
# All examples
./scripts/run_doc_tests.sh # macOS / Linux
pwsh ./scripts/run_doc_tests.ps1 # Windows
# Just one
cargo run -p perry-doc-tests --release -- --filter ui/counter.ts --verbose
# Screenshot baseline: write/overwrite for the current host OS
cargo run -p perry-doc-tests --release -- --filter ui/gallery.ts --blessBinaries are built into target/perry-doc-tests/. A JSON summary can be
written with --json path/to/report.json.
Linux and Windows baselines can't be captured from a macOS dev box. Flow for bootstrapping them:
- Open a PR; the
doc-testsmatrix job runs on all three OSes. Gallery is advisory on any OS whose baseline isn't in_baselines/<os>/gallery.pngyet — the run will surfaceSCREENSHOT_DIFF: no baseline at .... - Download the
gallery-screenshots-<os>artifact from the CI run. It contains the freshly capturedgallery_<os>.png. - Rename to
gallery.pngand commit it atdocs/examples/_baselines/<os>/gallery.png. - Re-run the job; the advisory gate will now produce a real SSIM score. Once
two consecutive runs fall well under the threshold, flip
gallery_advisory: true → falsefor that OS in.github/workflows/test.yml.