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

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

Open
nyurik opened this issue Aug 17, 2023 · 1 comment
Open

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

nyurik opened this issue Aug 17, 2023 · 1 comment

Comments

@nyurik
Copy link

nyurik commented Aug 17, 2023

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:

  • if the glob! is used with two parameters AND the filter begins with a / or a .., warn or even fail to compile -- because I suspect it is never correct(?), and explain that a 3 param glob! should be used. (i wonder if its possible to make it work in a more intelligent way?)
  • when printing an error, report where the base was and how it was searched to simplify debugging

Once again, thanks for an awesome tool!

@mitsuhiko
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants