insta
insta copied to clipboard
Add `read_snapshot!` and `read_binary_snapshot!` macros (experimental)
for https://github.com/mitsuhiko/insta/issues/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 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_suffixprepend_module_to_snapshot => false- Nested modules
- Combined settings
- Error cases for reading text as binary and vice-versa.