diff --git a/CHANGELOG.md b/CHANGELOG.md index 2684eb69..1e010d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,12 @@ reads that marker. declines parameter by parameter counted once per parameter. It now remembers up to 256 shapes past the 32 by hash and counts each once; past those, a shape counts each time it is sent. (#828) +- A snapshot taken with `assert_screen_snapshot!` records the caller's + expression, `t` or `t.screen()`, as its `expression`. It recorded the + macro's own binding, `__screen.with_styles()` or `__screen`, so every + `.snap` file the macro wrote, and every failure summary, named a + variable the test never wrote. Snapshots already committed still match; + `cargo insta test --force-update-snapshots` rewrites their header. (#851) - Both published crates, `termlens` and `termlens-cli`, ship `LICENSE-MIT` and `LICENSE-APACHE`. They are `MIT OR Apache-2.0`, and both licences ask for their text in every copy, but the texts sat only at the repository diff --git a/crates/termlens/src/lib.rs b/crates/termlens/src/lib.rs index c6e53b98..27c6eea0 100644 --- a/crates/termlens/src/lib.rs +++ b/crates/termlens/src/lib.rs @@ -236,15 +236,25 @@ macro_rules! assert_screen_snapshot { ($source:expr, @$inline:literal $(,)?) => {{ use $crate::SnapshotSource as _; let __screen = ($source).screen_for_snapshot(::core::option::Option::None)?; - $crate::insta::assert_snapshot!(__screen.with_styles(), @$inline) + $crate::insta::assert_snapshot!(__screen.with_styles(), stringify!($source), @$inline) }}; ($source:expr, styles = $styles:expr $(,)?) => {{ use $crate::SnapshotSource as _; let __screen = ($source).screen_for_snapshot(::core::option::Option::None)?; + // The caller's expression, not this macro's binding, is what the + // snapshot records as its `expression` (#851). if $styles { - $crate::insta::assert_snapshot!(__screen.with_styles()); + $crate::insta::assert_snapshot!( + ::core::option::Option::None::<::std::string::String>, + __screen.with_styles(), + stringify!($source) + ); } else { - $crate::insta::assert_snapshot!(__screen); + $crate::insta::assert_snapshot!( + ::core::option::Option::None::<::std::string::String>, + __screen, + stringify!($source) + ); } }}; ($source:expr, after = $after:expr $(,)?) => { @@ -259,10 +269,20 @@ macro_rules! assert_screen_snapshot { } let mut __after = __predicate($after); let __screen = ($source).screen_for_snapshot(::core::option::Option::Some(&mut __after))?; + // The caller's expression, not this macro's binding, is what the + // snapshot records as its `expression` (#851). if $styles { - $crate::insta::assert_snapshot!(__screen.with_styles()); + $crate::insta::assert_snapshot!( + ::core::option::Option::None::<::std::string::String>, + __screen.with_styles(), + stringify!($source) + ); } else { - $crate::insta::assert_snapshot!(__screen); + $crate::insta::assert_snapshot!( + ::core::option::Option::None::<::std::string::String>, + __screen, + stringify!($source) + ); } }}; } diff --git a/crates/termlens/tests/snapshots/readme_example__readme_example_compiles_and_runs.snap b/crates/termlens/tests/snapshots/readme_example__readme_example_compiles_and_runs.snap index ea08df24..0b2c0750 100644 --- a/crates/termlens/tests/snapshots/readme_example__readme_example_compiles_and_runs.snap +++ b/crates/termlens/tests/snapshots/readme_example__readme_example_compiles_and_runs.snap @@ -1,6 +1,6 @@ --- source: crates/termlens/tests/readme_example.rs -expression: __screen.with_styles() +expression: t --- size: 80x24 cursor: hidden ╭──────────────────────────────╮ diff --git a/crates/termlens/tests/snapshots/snapshot_macro__a_screen_is_recorded_as_it_is_and_refuses_a_wait-2.snap b/crates/termlens/tests/snapshots/snapshot_macro__a_screen_is_recorded_as_it_is_and_refuses_a_wait-2.snap index 95b1e2a7..6f83a7bb 100644 --- a/crates/termlens/tests/snapshots/snapshot_macro__a_screen_is_recorded_as_it_is_and_refuses_a_wait-2.snap +++ b/crates/termlens/tests/snapshots/snapshot_macro__a_screen_is_recorded_as_it_is_and_refuses_a_wait-2.snap @@ -1,6 +1,6 @@ --- source: crates/termlens/tests/snapshot_macro.rs -expression: __screen +expression: t.screen() --- size: 30x3 cursor: 0,5 fixed diff --git a/crates/termlens/tests/snapshots/snapshot_macro__a_screen_is_recorded_as_it_is_and_refuses_a_wait.snap b/crates/termlens/tests/snapshots/snapshot_macro__a_screen_is_recorded_as_it_is_and_refuses_a_wait.snap index 8713f866..0b54ecfa 100644 --- a/crates/termlens/tests/snapshots/snapshot_macro__a_screen_is_recorded_as_it_is_and_refuses_a_wait.snap +++ b/crates/termlens/tests/snapshots/snapshot_macro__a_screen_is_recorded_as_it_is_and_refuses_a_wait.snap @@ -1,6 +1,6 @@ --- source: crates/termlens/tests/snapshot_macro.rs -expression: __screen.with_styles() +expression: screen --- size: 30x3 cursor: 0,5 fixed diff --git a/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles-2.snap b/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles-2.snap index 4678c095..9b7ad7d0 100644 --- a/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles-2.snap +++ b/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles-2.snap @@ -1,6 +1,6 @@ --- source: crates/termlens/tests/snapshot_macro.rs -expression: __screen +expression: t --- size: 30x3 cursor: 0,11 Ready later diff --git a/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles-3.snap b/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles-3.snap index 90a52c59..9d619657 100644 --- a/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles-3.snap +++ b/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles-3.snap @@ -1,6 +1,6 @@ --- source: crates/termlens/tests/snapshot_macro.rs -expression: __screen.with_styles() +expression: t --- size: 30x3 cursor: 0,11 Ready later diff --git a/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles.snap b/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles.snap index 90a52c59..9d619657 100644 --- a/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles.snap +++ b/crates/termlens/tests/snapshots/snapshot_macro__a_terminal_is_settled_and_snapshotted_with_styles.snap @@ -1,6 +1,6 @@ --- source: crates/termlens/tests/snapshot_macro.rs -expression: __screen.with_styles() +expression: t --- size: 30x3 cursor: 0,11 Ready later