ITADN

Snapshot not fixed by accepting it

#865Closedilyagr 创建于 2026-01-31
bug
I
ilyagrcommented
### What happened? If I run `cargo insta test` with this example, it suggests updating the snapshot. However, the suggestion is identical to the snapshot, so this can be done forever. Aside: I encountered this in https://github.com/jj-vcs/jj/pull/8752, while trying to fix "Snapshot test passes but the existing value is in a legacy format. Please run `cargo insta test --force-update-snapshots` to update to a newer format" warning. ### Reproduction steps 1. Start with this example: ```rust #[cfg(test)] mod tests { #[test] fn test_trim_end() { insta::assert_snapshot!(" \n \r foo bar", @" foo bar "); } } ``` 2. Run `cargo insta test --accept` a few times and/or `cargo insta test` followed by `cargo insta review`. 3. Run `cargo test`, note that it fails. The failure I get looks as follows: ``` ---- tests::test_trim_end stdout ---- ━━━━━━━━━━━━━━━ Snapshot Summary ━━━━━━━━━━━━━━━ Snapshot: trim_end Source: src/lib.rs:5 ──────────────────────────────────────────────── Expression: " \n \r foo bar" ──────────────────────────────────────────────── -old snapshot +new results ────────────┬─────────────────────────────────── 1 1 │ ␊ 2 │-foo bar 3 │+ foo bar ────────────┴─────────────────────────────────── To update snapshots run `cargo insta review` Stopped on the first failure. Run `cargo insta test` to run all snapshots. ``` <img width="508" height="338" alt="Screenshot of terminal with that output and underlines" src="https://github.com/user-attachments/assets/705c6052-bdc6-42ea-be40-f344c177df23" /> And the snapshot file (after moving things around a bit, I lost the original, so the line numbers are different): ```json { "run_id": "1769831166-734466000", "line": 3, "new": { "module_name": "crazy_start_whitespace", "snapshot_name": "crazy_start_whitespace", "metadata": { "source": "tests/crazy_start_whitespace.rs", "assertion_line": 3, "expression": "\" \\n \\r foo bar\"" }, "snapshot": "\n\r foo bar" }, "old": { "module_name": "crazy_start_whitespace", "metadata": {}, "snapshot": "\nfoo bar" } } ``` ### rustc Version rustc 1.95.0-nightly (a293cc4af 2026-01-30) binary: rustc commit-hash: a293cc4af8b26701c42738381c0c6f9d2ba881e0 commit-date: 2026-01-30 host: aarch64-apple-darwin release: 1.95.0-nightly LLVM version: 22.1.0 ### insta Version 1.46.1 ### cargo insta --version output 1.46.1 ### What did you expect? After running `cargo insta test --accept`, `cargo test` should succeed.
关闭于 2026-02-02 10 条评论