Skip to content
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

cargo insta test crash #340

Closed
samueltardieu opened this issue Feb 1, 2023 · 0 comments · Fixed by #341
Closed

cargo insta test crash #340

samueltardieu opened this issue Feb 1, 2023 · 0 comments · Fixed by #341
Labels
bug Something isn't working

Comments

@samueltardieu
Copy link

samueltardieu commented Feb 1, 2023

What happened?

After I put a insta::assert_snapshot!() in a function called by several tests, I got the expected

thread 'main' panicked at 'assertion failed: self.inline_snapshots.last().map_or(true, |x| x.end.0 <= line)', /home/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-insta-1.26.0/src/inline.rs:60:17

introduced after #307.

However, after removing the insta::assert_snapshot!() from there, using cargo insta test still crashes:

$ RUST_BACKTRACE=1 cargo insta test --release
thread 'main' panicked at 'assertion failed: self.inline_snapshots.last().map_or(true, |x| x.end.0 <= line)', /home/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-insta-1.26.0/src/inline.rs:60:17
stack backtrace:
   0: rust_begin_unwind
             at /rustc/1e4f90061cc4bc566f99ab21b1f101182b10cf0c/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/1e4f90061cc4bc566f99ab21b1f101182b10cf0c/library/core/src/panicking.rs:64:14
   2: core::panicking::panic
             at /rustc/1e4f90061cc4bc566f99ab21b1f101182b10cf0c/library/core/src/panicking.rs:114:5
   3: cargo_insta::inline::FilePatcher::add_snapshot_macro
   4: cargo_insta::container::SnapshotContainer::load
   5: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
   6: <core::iter::adapters::filter_map::FilterMap<I,F> as core::iter::traits::iterator::Iterator>::try_fold
   7: cargo_insta::cli::load_snapshot_containers
   8: cargo_insta::cli::process_snapshots
   9: cargo_insta::cli::run
  10: cargo_insta::main

Reproduction steps

  1. Put a insta::snapshot!() in a loop or a shared function.
  2. Run cargo insta test and get an assertion error.
  3. Remove the problematic insta::snapshot!().
  4. Run cargo insta test and get another assertion error. At this stage you cannot use cargo insta anymore (unless you remove the pending snap file by hand)

Insta Version

1.26.0

rustc Version

rustc 1.69.0-nightly (e972bc808 2023-01-29)

What did you expect?

cargo insta test should work again when the problematic insta::assert_snapshot!() is removed from source.

@samueltardieu samueltardieu added the bug Something isn't working label Feb 1, 2023
IgorLaborieWefox added a commit to IgorLaborieWefox/insta that referenced this issue Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant