Add read_snapshot! and read_binary_snapshot! macros (experimental)#841
Open
max-sixty wants to merge 2 commits intomitsuhiko:masterfrom
Open
Add read_snapshot! and read_binary_snapshot! macros (experimental)#841max-sixty wants to merge 2 commits intomitsuhiko:masterfrom
read_snapshot! and read_binary_snapshot! macros (experimental)#841max-sixty wants to merge 2 commits intomitsuhiko:masterfrom
Conversation
These new experimental macros allow programmatic reading of snapshot contents, returning `String` for text snapshots and `Vec<u8>` for binary snapshots. The macros resolve snapshot paths using the same logic as `assert_snapshot!` and `assert_binary_snapshot!`, respecting settings like `snapshot_path`, `snapshot_suffix`, and `prepend_module_to_snapshot`. Includes comprehensive functional tests covering various scenarios such as: - Reading YAML, JSON, and plain text snapshots - Handling nonexistent snapshots - Auto-generated snapshot names - Custom `snapshot_path` - Binary snapshots with `read_binary_snapshot!` - `snapshot_suffix` - `prepend_module_to_snapshot => false` - Nested modules - Combined settings - Error cases for reading text as binary and vice-versa.
# Conflicts: # cargo-insta/tests/functional/main.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
for #353
I think it's somewhat useful. It doesn't allow reading from a different function. As a downside: it adds to the API surface...
From Claude (which also helped with the code):
These new experimental macros allow programmatic reading of snapshot contents, returning
Stringfor text snapshots andVec<u8>for binary snapshots.The macros resolve snapshot paths using the same logic as
assert_snapshot!andassert_binary_snapshot!, respecting settings likesnapshot_path,snapshot_suffix, andprepend_module_to_snapshot.Includes comprehensive functional tests covering various scenarios such as:
snapshot_pathread_binary_snapshot!snapshot_suffixprepend_module_to_snapshot => false