-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat(update): add update by environment variable #1
base: trunk
Are you sure you want to change the base?
Conversation
Added the second option to update a snapshot test with an environment variable very inspired by the original snapshot testing library from TigerBeetle. This option was, tested but a unit test is kind of useless in this case. The test included the update of the `CustomStruct` structure like shown in the code snippet below (first snippet before update, second after update): ```zig test "update env var" { const oh = OhSnap{}; const foobar = CustomStruct{ .foo = 42, .bar = 23 }; try oh.snap( @src(), \\ , ).expectEqual(foobar); } ``` ```bash # fail on test "update env var" zig build test # command to update SNAP_UPDATE=1 zig build test # "update env var" test passes zig build test ``` ```zig test "update env var" { const oh = OhSnap{}; const foobar = CustomStruct{ .foo = 42, .bar = 23 }; try oh.snap( @src(), \\ohsnap.CustomStruct \\ .foo: u64 = 42 \\ .bar: u66 = 23 , ).expectEqual(foobar); } ```
@mnemnion any thoughts on this one? It seems like it would be a nice improvement to the workflow. |
Thanks for the PR! I'll take a look at it and give it a spin. Philosophically, I'm somewhat resistant to a bulk-update option. However, I've been hoist on my own petard at least once. Especially as combined with So given the interest, I'm inclined to set my dogma to the side. Discussion: is an environment variable the best way to do it? My first inclination is to make it a command line option using Also, speaking from total ignorance here: is an environment variable Windows-friendly? If not that tilts toward a build option. |
This also reminded me that @src() regressed on Zig master and We're expecting a release by the end of the year, so I need to follow through on that. Hopefully that affordance will be restored in some form, if not I'll need to figure out a way to keep the library functional. I have a copy of |
FWIW, for my part, if this is doable (and I believe it is), I would definitely prefer it to an environment variable. Here's how we do it in Zig itself:
To thread an option through, I believe you just pass it to |
As long as I can keep setup beginner friendly (meaning a copy-pasteable block in the README), which it's starting to look like I can, then I'm definitely leaning in the direction of a config option. Any project which has more of those will be in a position to customize that code to their needs, I figure. Thanks for the feedback, I'll look into this soon. |
Added the second option to update a snapshot test with an environment variable very inspired by the original snapshot testing library from TigerBeetle (see tigerbeetle/tigerbeetle/blob/main/src/testing/snaptest.zig#L109-L112).
This option was, tested but a unit test is kind of useless in this case. The test included the update of the
CustomStruct
structure like shown in the code snippet below (first snippet before update, second commands, third after update):PS: I know the code is a little bit repetitive if you have an idea how make it look nicer I'm open for changes.
PPS: I know this is out of the blue. I looked at snapshot testing, then the blog entry from TigerBeetle, then thought I could outsource the snap lib from, them then saw your project and missed this feature while using it hope you like it. Like the idea of this project very much ❤️!