rust-marker / marker

An experimental linting interface for Rust. Let's make custom lints a reality
https://rust-marker.github.io/marker/
Other
140 stars 12 forks source link

Document snapshot-testing in Marker's codebase #202

Open xFrednet opened 1 year ago

xFrednet commented 1 year ago

Marker has a few tests, that check the size of structs. @Veetaha suggested to potentially use snapshot-testing to allow automatic updates of these tests:

I recommend you to use a snapshot-testing library. I've been using expect-test, which is a suprisingly low-overhead crate for snapshot testing.

This way you can capture all the data about the types and their sizes in a string snapshot (inline our out-of-line in a separate file) and re-generate it if something changes with UPDATE_EXPECT=1 cargo test, which means maintaining tests becomes almost a zero-effort task, because they rewrite themselves, and you just review the diff.

This testing library was originally developed for use in rust-analyzer by @matklad and I've been using it in production successfuly so far. The one thing is that the library is barebones, and requires some small amount of batteries (like I added in my repo here) to make JSON snapshots and auto-format snapshots such that they don't exceed 80 lines in the editor

Source: https://github.com/rust-marker/marker/pull/196#discussion_r1273872898

xFrednet commented 1 year ago

Support has been implemented in https://github.com/rust-marker/marker/pull/233, now it only needs to be documented, or at least linked to in our docs, than we can close this issue :)