Proc macro attribute fails a tests in IDE

Im trying to find out why I keep getting "Test framework quit unexpectedly" error in Intellij for few hours now without any luck. :tired_face:

I have dumbed down the problem Im having in the screenshot below

  • Right side of screenshot is the proc lib.
  • Left side is the one using the proc macro attribute.

According to my understanding, my_test basically wont do anything. It simply returns the method.
But I know my understanding is flawed.

Any help would be appreciated.

Will the error go away if you add some real test (without removing current code)? It's possible that this "unexpected quit" is simply due to the fact that Cargo didn't find any tests to run at all.

Adding a regular test with #[test] does work. It finds only one test.
Why cant it run with just #[my_test]?
Or rather what do I need to tell #[my_test] to mimic a #[test]?

Ohhhhh. I think I need to reply with something like..

<my function>

Is that it?

Yes, if you want your macro to produce a test, you need to emit the #[test] annotation.

So, I think I know why the IDE is producing such a confusing error message when you don't emit #[test]:

  1. The IDE is assuming that it_works is a #[test] function, maybe because it has an attribute that contains the test pattern?

    • :x: First bug :x: (IDE should expand macros at some point to make sure the function was #[test]-annotated).
  2. I guess you then click on that gutter button which will cause your IDE to try and run that test by doing something like cargo test -- --exact tests::it_works, probably with an added --format=json flag (guessed from this PR).

  3. The IDE then looks for something like { "type": "test", "name": "tests::it_works", "event": "<ok|failed>" … } among the emitted json events, which of course is missing because tests::it_works is not a test.

  4. Confused, the IDE interprets that lack of json entry as a Test … quit unexpectedly

    • :x: Second bug :x: (it should look into that json output to see which tests actually started, so as to emit a message related to there not being a { "type": "test", "event": "started", "name": "tests::it_works" } event and thus reporting a failure to start that test).

You all are right in one way or another. The solution just somehow hit me when I started posting here.

Thanks all.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.