mitsuhiko / insta

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

Variables with the same name in the same test function will only be snapshotted once #671

Closed ahaoboy closed 1 month ago

ahaoboy commented 1 month ago

What happened?

In a test function, I use assert_debug_snapshot to take snapshots of variables with the same name, but only the first value is saved, which ignores subsequent variables with the same name. In this case, maybe warn should be used to prompt the user, or is it a bug in insta?

Reproduction steps

#[cfg(test)]
mod test {
    use insta::assert_debug_snapshot;

    #[test]
    fn test() {
        let r = 1;
        assert_debug_snapshot!(r);

        let r = 2;
        assert_debug_snapshot!(r);
    }
}
---
source: src/lib.rs
expression: r
---
1

Insta Version

latest

rustc Version

rustc 1.84.0-nightly (798fb83f7 2024-10-16)

What did you expect?

Variables with the same name should be snapshotted twice

max-sixty commented 1 month ago

This would be very surprising. Could you confirm once more? Your're sure it's not just failing on the first and not hitting the second? Changing the name of the second makes a difference?

ahaoboy commented 1 month ago

Sorry, I mistakenly thought that all assertions in each test function were in the same file, insta is fine, thanks for your help