mitsuhiko / insta

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

Help new users with glob! macro: base suggestions #398

Open nyurik opened 1 year ago

nyurik commented 1 year ago

As a novice insta user, I wrote this in my unit test:

glob!("../tests/fixtures/*.pbf", |file| { ... });

resulting in unhelpful the glob! macro did not match any files error. I tried a few different paths to no help because I was not even sure where the base is, until I simply modified my .cargo/registry/src/index.crates.io-.../insta-1.31.0/src/glob.rs (eek!) with a few extra debug statements:

eprintln!("manifest_dir={manifest_dir}");
eprintln!("base={}", base.display());
eprintln!("pattern={pattern}");
panic!("the glob! macro did not match any files.");

and realized that the base is what I expected it to be, and that I should be using 3 parameter glob! macro:

glob!("../tests/fixtures", "*.pbf", |file| { ... });

Sugestion

To make dev's life easier with this amazing (!!!!) tool, I recommend two things:

Once again, thanks for an awesome tool!

mitsuhiko commented 1 year ago

So I think that ../ can make sense in some cases. I agree that this error is not helpful at all. I think I can try a variation of the proposal to show where the base is and what was searched in the output.