Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 25 additions & 5 deletions crates/termlens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 $(,)?) => {
Expand All @@ -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)
);
}
}};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/termlens/tests/readme_example.rs
expression: __screen.with_styles()
expression: t
---
size: 80x24 cursor: hidden
╭──────────────────────────────╮
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/termlens/tests/snapshot_macro.rs
expression: __screen
expression: t.screen()
---
size: 30x3 cursor: 0,5
fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/termlens/tests/snapshot_macro.rs
expression: __screen.with_styles()
expression: screen
---
size: 30x3 cursor: 0,5
fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/termlens/tests/snapshot_macro.rs
expression: __screen
expression: t
---
size: 30x3 cursor: 0,11
Ready later
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/termlens/tests/snapshot_macro.rs
expression: __screen.with_styles()
expression: t
---
size: 30x3 cursor: 0,11
Ready later
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/termlens/tests/snapshot_macro.rs
expression: __screen.with_styles()
expression: t
---
size: 30x3 cursor: 0,11
Ready later
Expand Down
Loading