mitsuhiko / insta

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

Feature request: custom headers in a snap file #433

Open quantori-pokidovea opened 9 months ago

quantori-pokidovea commented 9 months ago

That would be nice to have an extra context inside the snap file. For example

---
source: src/secondary_structure/bulge.rs
expression: bulge
---
sense: TCCCCTAGCTTTTAGCTATGGGGA
anti_sense: AGGGGTATCGATTTTCGATCCCCT
forward_init_x: 6
---
Bulge {
    description: "/bulge(-T)",
    entropy: Entropy(
        -35.510002,
    ),
    enthalpy: Enthalpy(
        -7.8,
    ),
    interim_oligo: Some(
        Sequence(T),
    ),
    wc_stack: Some(
        WCStack(CT/GA),
    ),
}

So, we can see some circumstances which led to the snapshot's body.

max-sixty commented 9 months ago

Possibly description or debug_expr could be serialized using the same serializer — and then we could add fields without an additional field?

(it would be a small breaking change though, unless we did something like attempt both the serialized and unserialized versions)

pokidovea commented 9 months ago

It could be the same section as for the regular headers. It doesn't matter. The main idea is to be able to populate headers with custom ones.

mitsuhiko commented 8 months ago

Would you expect the review tool to show these headers?

tyao1 commented 6 months ago

Would love this feature as well. I would like to ignore the headers section, because we use buck internally and cargo externally, and they have different root directories for source and output files, I couldn't get snapshot to stay the same between two build systems.