mitsuhiko / insta

A snapshot testing library for rust
https://insta.rs
Apache License 2.0
2.07k stars 93 forks source link

Group multiple assertions into one file #493

Open tisonkun opened 1 month ago

tisonkun commented 1 month ago

Hi @mitsuhiko! Thanks for releasing this amazing crate for snapshot tests :D

I'm currently using insta to write SQL tests and assert the result set as snapshot. For demonstration, it looks like:

assert_snapshot!(execute("<sql-statements>"));

// result set
+------------+---------------+
| col_0::int | col_1::string |
+------------+---------------+
|         42 |       'tison' |
+------------+---------------+

This works well. But it generates one snapshot file per assertions, and I will have thousands of SQL statements to test and it creates too many files to store the snapshot.

Thus, I wonder if it's possible to group multiple assertions so that their snapshots are stored into one file.

Looking forward to your feedback.

tisonkun commented 1 month ago

Other solutions for SQL tests can be found like:

Despite the DSL and inputs part, you may notice it contains multiple statements and all the output in one file.

max-sixty commented 1 month ago

Do inline snapshots help here? Over at PRQL we use them a lot for small snapshots...

tisonkun commented 1 month ago

@max-sixty Yeah ... This sounds reasonable and it would take almost the same lines like sqllogictest/sqlness linked above.

So snapshot files are mainly for large outputs and inline snapshots are encouraged for other scenarios?

max-sixty commented 1 month ago

So snapshot files are mainly for large outputs and inline snapshots are encouraged for other scenarios?

Yes, that's how I generally think about them (though just my view, not necessarily the project's...)