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
Add support for allow_duplicates! #346
Conversation
5e9bce6
to
70c9401
Compare
70c9401
to
9569708
Compare
What are the limitations of this, aside from the snapshot having to take the same value every time? Can I just wrap all of my tests in allow_duplicates!? Could I repeatedly call a function that has an assert_snapshot! in it. I guess one problem with that is that rustfmt and rust-analyzer might have some trouble if all of the coffee is in a macro. I'm hoping that understanding this better might clarify what names are good for the feature. |
The limitations are that the results have to match per invocation. They uniqueness key for inline snapshots is the location in the file and for named snapshots is the name of the snapshot provided. |
Sorry, I edited the question above just as you answered. TLDR: Any limitations apart from that? |
Not really. |
In the spirit of trying to clarify pesky details, which of these will work? (Some or all of these might be worth adding as tests): 1fn assert_even(x:i64) {
let is_even = x % 2 == 0;
insta::assert_debug_snapshot!(is_even, @"true");
}
fn test(){
insta::allow_duplicates! {
assert_even(0);
assert_even(2);
}
} 2fn assert_even(x:i64) {
let is_even = x % 2 == 0;
insta::assert_debug_snapshot!(is_even, @"true");
}
fn test(){
insta::allow_duplicates! {
assert_even(0);
};
insta::allow_duplicates! {
assert_even(2);
};
} 3fn assert_even(x:i64) {
let is_even = x % 2 == 0;
insta::allow_duplicates! {
insta::assert_debug_snapshot!(is_even, @"true");
};
}
fn test(){
assert_even(0);
assert_even(2);
} |
They will all "work" but only the first will do what you want on assertion failures. |
Going to be sticking with |
This adds a new macro called
allow_duplicates!
. When a block of code is wrapped with it, every snapshot assertion can be visited more than once. In that case all of the snapshot assertions in a loop etc. have to match with each other and if not, an assertion error is raised.Motivational example:
Fixes #313