Skip to content

Conversation

@talf301
Copy link
Collaborator

@talf301 talf301 commented Feb 10, 2026

Summary

  • Adds SnapshotTestSuite abstract type and run_snapshot_tests driver for eliminating snapshot test boilerplate
  • Packages define a marker type and overload snapshot_tests, snapshot_expected_dir, snapshot_produce (and optionally snapshot_test_extras, snapshot_allow_additions)
  • run_snapshot_tests handles iteration, @testset wrapping, filter (string/function), and skip lists
  • Existing test_snapshot API is completely untouched — this is purely additive
  • 8 new tests covering: basic suite, string filter, predicate filter, skip list, empty suite, no-match warning, extras callback, and allow_additions=false

Usage

struct MySnapshots <: SnapshotTestSuite end
SnapshotTesting.snapshot_tests(::MySnapshots) = [("test1" => "path/to/test1"), ...]
SnapshotTesting.snapshot_expected_dir(::MySnapshots) = joinpath(@__DIR__, "expected")
function SnapshotTesting.snapshot_produce(::MySnapshots, name, path, dir)
    write(joinpath(dir, "out.txt"), run_my_code(path))
end

run_snapshot_tests(MySnapshots())
run_snapshot_tests(MySnapshots(); filter="test1")  # debug single test

Test plan

  • All 49 tests pass (8 existing snapshots + 18 update modes + 23 new suite tests)

🤖 Generated with Claude Code

Add an abstract type `SnapshotTestSuite` with a `run_snapshot_tests` driver
that handles test iteration, filtering, and skipping. Packages define a
marker type, overload a few functions (snapshot_tests, snapshot_expected_dir,
snapshot_produce), and get automatic plumbing. Supports filtering by exact
name or predicate function, skip lists, and optional pre-snapshot assertions
via snapshot_test_extras. The existing test_snapshot API is untouched.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment on lines +80 to +84
function run_snapshot_tests(suite::SnapshotTestSuite; filter=nothing, skip=String[])
cases = snapshot_tests(suite)
expected = snapshot_expected_dir(suite)
allow = snapshot_allow_additions(suite)
pred = _make_filter(filter)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we maybe also just have a run_snapshot_test syntactic sugar function that runs a single snapshot test

Claude and others added 2 commits February 11, 2026 03:38
…test

- Change SnapshotTestSuite from abstract type to parameterized struct
  SnapshotTestSuite{X}, following the Salsa Keyspace{X} pattern. Users
  dispatch on SnapshotTestSuite{:my_symbol} instead of defining/exporting
  concrete subtypes.
- Add run_snapshot_test(suite, name) convenience function for running a
  single snapshot test by name.
- Update tests to use parameterized types with unique symbols per testset.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Julia requires global method definitions to be at the top level, not
inside local scopes like `mktempdir() do ... end` blocks. Use Ref
variables at module level to pass test-specific data (cases, expected
dirs) into the parameterized type method implementations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant