-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Hiya, I keep running into a papercut. I think I can solve it pretty well, but before I make it, would you be interested in a fix?
The problem
What I keep running into is regularly I want to assert the same snapshot multiple times. Simplified example:
#[test]
fn test_expect() {
let expect = expect!["hello beautiful world, i love you so much"];
expect.assert_eq("hi");
expect.assert_eq("hi");
}Of course, in both cases the value under test (2x "hi") should be equal. Here they are, and I would like to update my snapshot.
But when I update my snapshot, the source gets corrupted:
let expect = expect!["hi"ect.assert_eq("hi");The Rust file is now corrupted and actually some source code was deleted.
Proposed solution
-
Add
AtomicU8tostruct Expect, which is morally an enum:- 0: snapshot has not been asserted
- 1: snapshot has been asserted and was valid
- 2: snapshot has been asserted and was updated
-
Add
Mutex<String>tostruct Expect, which starts empty and in case (2) is set to a copy of the updated value.
In the example above, the second assert_eq would look at the enum, see that we already update the value, and succeed silently.
And if you have
let expect = expect!["hi"];
expect.assert_eq("hi");
expect.assert_eq("hi, world");the enum is first set to 1, so then the second assert_eq knows there's no use updating the value. Current behavior is that the snapshots flip/flop back and forth.