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

Testing error messages from procedural macros #199

Closed
sphynx opened this issue Jun 9, 2019 · 1 comment · Fixed by #205
Closed

Testing error messages from procedural macros #199

sphynx opened this issue Jun 9, 2019 · 1 comment · Fixed by #205
Labels
enhancement We would love to have this feature! Feel free to supply a PR

Comments

@sphynx
Copy link
Contributor

sphynx commented Jun 9, 2019

As noted here, it would be nice to add tests for checking error messages got from procedural macros during compilation time. Since they are visible to users, it's important to keep them readable, predictable and stable between versions.

An example of an error message from a macro in compile time:

error: proc-macro derive panicked
  --> src/main.rs:11:10
   |
11 | #[derive(StructOpt, Debug)]
   |          ^^^^^^^^^
   |
   = help: message: cannot parse structopt attributes: ( parse ( 2 + 2 ) ): Error("expected identifier")

error: aborting due to previous error

There is no easy way to run tests in compile time using conventional [test] attributes. However, I've found a nice package called trybuild from @dtolnay, author of syn and quote. The package tries to compile test programs and matches the output against predefined .stderr files, which looks like exactly what is needed here.

I can take a closer look on that package and then incorporate it in structopt testing infrastructure.

@TeXitoi
Copy link
Owner

TeXitoi commented Jun 10, 2019

trybuild seems the way to go, I'll accept such a PR.

@TeXitoi TeXitoi added the enhancement We would love to have this feature! Feel free to supply a PR label Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement We would love to have this feature! Feel free to supply a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants