-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Multiple assert_snapshot
within a allow_duplicates
doesn't work well
#712
Comments
Thanks, this seems important.
OK, I looked at the PR — I think the problem i that we're deciding how many hashes to use depending on whether there are linebreaks, but failing to consider a bare |
I just started investigating, I think there are at least two problems (as seen by the two error messages). Running I randomly tried running I tried a commit from earlier today, and got the same error. I might try bisecting to find when the commit that |
(I edited my message above a minute after sending) No need to bisect — I know why it's doing this. We previously always used |
Fixes at least some of mitsuhiko#712 (not confident it fixes all of it, but wanted to get it out quickly)
#713 goes some way to fixing it; possibly not all of it. If you have an idle moment, give it a try; otherwise I can look later |
I don't think #713 is complete fyi, will come back to this later (or welcome any contribution if you have an idea, but no obligation) |
No, #713 does not resolve either problem. I didn't look into why yet. |
I did narrow down the error to the following files in the
So, you can run the following, slightly faster command, to observe a few different errors.
|
I think there are at least two problems:
|
OK, I think the new version of #713 fixes the first; will be offline for a bit but can look more later |
Fixes at least some of #712 (not confident it fixes all of it, but wanted to get it out quickly)
Yes, I think that new version of #713 helped. 🎉 For the second problem, @martinvonz pointed out that it's probably related to jj-vcs/jj#5314 and having more than one |
OK great! I'll change the title if that's OK! |
cargo insta test --test-runner nextest --accept --force-update-snapshots
messes up codeassert_snapshot
within a allow_duplicates
doesn't work well
Fun crazy illustrations for mitsuhiko#712
Fun crazy illustrations for mitsuhiko#712
Fun crazy illustrations for mitsuhiko#712 Note that the result of running ``` cargo insta test --workspace --test-runner nextest --accept -- allow_duplicates ``` is not currently determenistic, usually only some of the tests get any diffs shown and others (incorrectly) show empty diffs.
Fun crazy illustrations for mitsuhiko#712 Note that the result of running ``` cargo insta test --workspace --accept -- allow_duplicates ``` is not currently determenistic, usually only some of the tests get any diffs shown and others (incorrectly) show empty diffs.
Fun crazy illustrations for mitsuhiko#712 Note that the result of running ``` cargo insta test --workspace --accept -- allow_duplicates ``` is not currently determenistic, usually only some of the tests get any diffs shown and others (incorrectly) show empty diffs.
There are two problems:
#[test]
fn test_dup() {
for _ in 0..2 {
insta::allow_duplicates! {
insta::assert_snapshot!("foo", @"");
}
}
} #[test]
fn test_bad_location() {
for _ in 0..2 {
insta::allow_duplicates! {
insta::assert_snapshot!("1", @"
1a
1b
");
insta::assert_snapshot!("2", @"
2a
2b
");
}
}
} I'll send fixes shortly. |
Thanks, I guess I'll leave it to you then. I have some tests in the commit linked from this issue above, if they are helpful. Though, I think some fixes to functional testing infra might be needed to make the result of running |
This is a follow up for 7b5a7f8 "Fix a patcher panic (mitsuhiko#341)." Since snapshots are identified by line number, multiple snapshots located at the same line should be omitted.
Before, the last assertion within the allow_duplicates! { .. } block was always chosen. This patch makes visitor parse block-like macro as a plain code block and visit the inner statements recursively. Maybe scan_nested_macros() could be removed or cleaned up, but it's still called from visit_attribute(). I have no idea what's supposed to be done here. Fixes mitsuhiko#712
This is a follow up for 7b5a7f8 "Fix a patcher panic (mitsuhiko#341)." Since snapshots are identified by line number, multiple snapshots located at the same line should be omitted.
Before, the last assertion within the allow_duplicates! { .. } block was always chosen. This patch makes visitor parse block-like macro as a plain code block and visit the inner statements recursively. Maybe scan_nested_macros() could be removed or cleaned up, but it's still called from visit_attribute(). I have no idea what's supposed to be done here. Fixes mitsuhiko#712
#712 There are two problems: 1. single-line snapshot isn't deduplicated 2. the last assertion in the `allow_duplicates!` block is always chosen ```rust #[test] fn test_dup() { for _ in 0..2 { insta::allow_duplicates! { // shouldn't be updated twice insta::assert_snapshot!("foo", @""); } } } ``` ```rust #[test] fn test_bad_location() { for _ in 0..2 { insta::allow_duplicates! { // each snapshot should be updated accordingly insta::assert_snapshot!("1", @" 1a 1b "); insta::assert_snapshot!("2", @" 2a 2b "); } } } ```
What happened?
I think there might be several problems here
Reproduction steps
cargo nextest run
passescargo insta test --workspace --test-runner nextest --force-update-snapshots
cargo nextest run
againExpected results:
tests pass
Actual result:
Compilation fails
Furthermore, these
\r
-s are not the only problem. If that one diff is reverted (\r
replaced with␍
again) in jj-vcs/jj#5441, there are more compilation errors, see https://github.com/jj-vcs/jj/actions/runs/12934546007/job/36075816189?pr=5441 . For example,Insta Version
1.42.0, same behavior with 1.41.1
rustc Version
rustc 1.86.0-nightly (48a426eca 2025-01-12)
What did you expect?
Tests to pass.
The text was updated successfully, but these errors were encountered: