Skip to content

fix(insta): record the caller's expression in assert_screen_snapshot! - #878

Merged
vyncint merged 2 commits into
vyncint:mainfrom
alvaroalonsoparrondo-a11y:fix/snapshot-macro-expression
Nov 27, 2026
Merged

vyncint merged 2 commits into
vyncint:mainfrom
alvaroalonsoparrondo-a11y:fix/snapshot-macro-expression

Conversation

@alvaroalonsoparrondo-a11y

Copy link
Copy Markdown
Contributor

Fixes #851

assert_screen_snapshot! handed insta its own binding, so insta's stringify! recorded __screen.with_styles() or __screen as every snapshot's expression, and a failure summary showed the same name.

  • crates/termlens/src/lib.rs: each arm passes stringify!($source) as insta's debug expression. The file forms use assert_snapshot!(None::<String>, value, stringify!($source)), as the issue suggests, which keeps the auto-generated file name; the inline form uses assert_snapshot!(value, stringify!($source), @$inline). So assert_screen_snapshot!(t, after = …) records expression: t and assert_screen_snapshot!(t.screen(), styles = false) records expression: t.screen().
  • Snapshots: the six .snap files the macro writes in this repo (snapshot_macro and readme_example) get their new expression: line. Only that header line changes; the contents are the same.
  • Tests: insta compares contents, not the header, so the existing tests pass either way. To check the header I ran CI=1 INSTA_REQUIRE_FULL_MATCH=1 cargo test -p termlens --all-features --test snapshot_macro --test readme_example: it passes with this change and fails with main's macro against the updated files. I also checked that the inline form (assert_screen_snapshot!(t, @"")) compiles and runs. If you want CI to pin the header, require_full_match could be turned on for those two tests; I left that to you, since it changes insta's behaviour for the whole repo.
  • CHANGELOG: entry under Unreleased → Fixed. Snapshots users already committed keep passing; cargo insta test --force-update-snapshots rewrites their header.

Checked on macOS: cargo fmt --all --check, cargo clippy -p termlens --all-targets --all-features -- -D warnings, the two test files above, check-dco.sh and check-no-ai-attribution.sh.

Álvaro Alonso
242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com

Fixes vyncint#851

Signed-off-by: Álvaro Alonso <242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com>
vyncint
vyncint previously approved these changes Nov 27, 2026

@vyncint vyncint left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed against the issue; CI is green. Thank you.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
@vyncint
vyncint merged commit cc976e4 into vyncint:main Nov 27, 2026
17 checks passed
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.

assert_screen_snapshot! records its own binding, __screen.with_styles(), as every snapshot's expression

2 participants