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 does not work for inline doc assert #272

Open
indietyp opened this issue Aug 15, 2022 · 3 comments
Open

cargo insta test does not work for inline doc assert #272

indietyp opened this issue Aug 15, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@indietyp
Copy link

What happened?

When trying to update snapshots located in doc comments, insta recognizes that the snapshot is incorrect, but fails to prompt for review and creates a .pending file.

Reproduction steps

Snippet:

/// ```rust
/// use insta::assert_debug_snapshot;
///
/// assert_debug_snapshot!("abc", @r###""###);
/// ```
#[derive(Debug)]
pub struct A;
  1. cargo insta test -- --doc OR cargo test --doc
  2. When cargo test --doc was run in src/ a new file was created: .lib.rs.pending-snap with the following contents:
{"run_id":"1660578077-420954000","line":5,"new":{"module_name":"rust_out","snapshot_name":"_doctest_main_src_lib_rs_2_0","metadata":{"source":"src/lib.rs","assertion_line":5,"expression":"\"abc\""},"snapshot":"\"abc\""},"old":{"module_name":"rust_out","metadata":{},"snapshot":""}}
  1. cargo insta review

results in: done: no snapshots to review

Insta Version

insta v1.18.2

rustc Version

rustc 1.65.0-nightly (801821d15 2022-08-14)

What did you expect?

That insta would update the snapshot and prompt for review, or at least show a warning or note that such an operation isn't supported.

Is this behavior intended? What should I do instead? Thanks for creating such a valuable and great tool! I have used it in a few projects, and it's been great so far!

@indietyp indietyp added the bug Something isn't working label Aug 15, 2022
@mitsuhiko
Copy link
Owner

Unfortunately rust does not have correct line information within doctests (rust-lang/rust#79417) which makes it impossible to reliably reproduce the original location. In theory the offset to the doctest can be calculated from the function name as it encodes currently the offset to the doctest there, however the internally added preamble is not known and not consistent.

I will add a warning and avoid emitting the pending snapshot though, that can be detected.

@konstin
Copy link

konstin commented Sep 22, 2023

This warning is also incorrectly triggered when using cargo test instead of cargo insta test on tests that can actually be updated.

@max-sixty
Copy link
Sponsor Contributor

@konstin what's an example of that?

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

No branches or pull requests

4 participants