Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate assert_display_snapshot, refactor macros #385

Merged
merged 9 commits into from Mar 3, 2024

Conversation

max-sixty
Copy link
Sponsor Contributor

@max-sixty max-sixty commented Jun 18, 2023

This PR:

  • Deprecates assert_display_snapshot in favor of assert_snapshot, as discussed in assert_display_snapshot vs. assert_snapshot #379
  • Makes a sizable change in how macros are constructed:
    • It makes macros consistent — previously debug & display had different forms than the others, not taking a debug_expr.
    • The non-redaction macros are a simple wrapper of _assert_snapshot_base, which takes a closure transform of how to transform the input to a string.
    • The redaction macros are a simple wrapper of _assert_serialized_snapshot, which takes an arg format (similar to before), and uses that to construct a transform.
    • As a result, the boilerplate for each macros is removed.

It's not quite complete, but wanted to post before spending more time on it. Now complete

Previous todos:

  • We get a couple of test failures; I need to look into this; we seem to be generating an additional --- in some yaml snapshots. (possibly something is being converted to string twice?)
  • Update docs; previously the debug_expr wasn't well documented, and now that the source is more opaque this is more important

This PR:
- Deprecates `assert_display_snapshot` in favor of `assert_snapshot`, as discussed in mitsuhiko#379
- Makes a sizable change in how macros are constructed:
  - It makes macros consistent — previously `debug` & `display` had different forms than the others, not taking a `debug_expr`.
  - The non-redaction macros are a simple wrapper of `_assert_snapshot_base`, which takes a closure `transform` of how to transform the input to a string.
  - The redaction macros are a simple wrapper of `_assert_serialized_snapshot`, which takes an arg `format` (similar to before), and uses that to construct a transform.
  - As a result, the boilerplate for each macros is removed.

It's not quite complete, but wanted to post before spending more time on it.

Still todo:
- We get a couple of test failures; I need to look into this; we seem to be generating an additional `---` in some yaml snapshots. (possibly something is being converted to string twice?)
- Update docs; previously the debug_expr wasn't documented, and now that the source is more opaque this is more important
@max-sixty
Copy link
Sponsor Contributor Author

This is updated, with all the tests passing, and better comments around the macros.

One thing that would make the code even simpler — serializing values the same for File and Inline. I think the only difference is that YAML snapshots lose the leading --- in files — is that right? Any reason not to remove for both files & inline?

max-sixty added a commit to max-sixty/insta-website that referenced this pull request Sep 24, 2023
Relies on mitsuhiko/insta#385; otherwise not all snapshot macros implement all of these
max-sixty added a commit to max-sixty/insta-website that referenced this pull request Sep 24, 2023
Relies on mitsuhiko/insta#385; otherwise not all snapshot macros implement all of these
@max-sixty
Copy link
Sponsor Contributor Author

Updated the docs at mitsuhiko/insta-website#17

@mitsuhiko
Copy link
Owner

I will try to get this reviewed this week.

src/macros.rs Outdated Show resolved Hide resolved
mitsuhiko pushed a commit to mitsuhiko/insta-website that referenced this pull request Nov 19, 2023
* Enumerate all the snapshot types

Relies on mitsuhiko/insta#385; otherwise not all snapshot macros implement all of these

* Add debug expr to docs
@max-sixty
Copy link
Sponsor Contributor Author

@mitsuhiko the gentlest of pings! Also will take feedback if you think it's not so great :)

@mitsuhiko
Copy link
Owner

I am in favor of this. I will try to get it merged and released ahead of backwards incompatible changes.

@max-sixty
Copy link
Sponsor Contributor Author

I am in favor of this. I will try to get it merged and released ahead of backwards incompatible changes.

Thanks!

@mitsuhiko mitsuhiko merged commit 8221931 into mitsuhiko:master Mar 3, 2024
6 checks passed
@max-sixty max-sixty deleted the macros branch March 3, 2024 18:47
@kennethloeffler
Copy link

Just a heads up, @mitsuhiko + @max-sixty - I have good reason to believe that these changes broke one of our tests. It seems like this version of the assert_yaml_snapshot macro takes ownership of the value, while previous versions only borrowed it. I can reproduce the test failures observed in rojo-rbx/rbx-dom#398 on insta 1.36.0 (the version in which the changes in this PR shipped), but not on insta 1.35.1.

@max-sixty
Copy link
Sponsor Contributor Author

I'll take a look, thanks @kennethloeffler !

@max-sixty max-sixty mentioned this pull request Mar 3, 2024
@max-sixty
Copy link
Sponsor Contributor Author

This is fixed in #453, apologies for the temporary break

@kennethloeffler
Copy link

It's perfectly okay - it's easy to see how this flew under the radar 😅

@mitsuhiko
Copy link
Owner

Sorry for that. I pushed out a fix!

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.

None yet

3 participants