-
Notifications
You must be signed in to change notification settings - Fork 256
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
Unit tests for linters sometimes seem to disregard PPDs #1161
Comments
😕 The term PPD is used several times here, but I don't see a definition for it |
It generally should not be necessary to manually test Lines 34 to 38 in 0a17426
For the second issue, have you verified that the final end-of-line matches? |
Sorry, PPD = preprocessor directive. For the second issue: I tried to verify that the final end-of-lines matched, found that they didn't, and corrected that. Now the test (as expected) catches my bug, and I feel very silly. For the first one, let me put together a MWE. |
Here's an analyzer that does not respect
Here's the first unit test I wrote when I wanted to fix the analyzer.
This test fails:
The fix for the analyzer was pretty simple: rather than six lines for a
Now it passed the test, so I decided to write another test, resulting in the weird behaviour of my first example in the original post. Because I know that we can write analyzers which pass our other unit tests but which don't respect |
What version of the test framework are you using? I'm curious if the newest releases would have caught this without writing a new test. |
Ah, I looked and the validation I was thinking of only applied to code fixes. If you do have a code fix for this diagnostic, it may have flagged it. |
|
I'm not sure which package you want the version of, so here are NuGet packages I'm currently including, with the latest version (if not what I'm already using) included in parentheses.
|
I've noticed two issues with unit tests I've attempted to write, both of which involve PPDs. I'm willing to believe I'm at fault, but I think there's a bug.
First:
I inherited a custom analyzer that checked if a line was longer than our column limit. This analyzer didn't respect
#pragma warning
directives, so it was impossible to disable the analyzer for intentionally-too-long lines. After fixing this, I wanted to add a unit test to this analyzer (and our other analyzers) to verify that they respect pragma directives. Here are the two tests I wrote:The first test passes, but the second fails. Here's the error message for the second one:
Interestingly, if I remove
, expected
from the final line of test, leaving the test code unchanged, I get a different error message:Somehow, expecting a diagnostic causes the actual diagnostic to change.
Second:
I'm trying to write an analyzer to enforce our indentation rules. There's a bug in my code involving PPDs near the ends of files. Here's a file that my analyzer flags as wrong:
My analyzer reports a diagnostic at the
EndOfFileToken
. I wanted to debug this issue, so I tossed this small example into a unit test:I expect this test to fail, because of the bug in my analyzer. However, it passes.
Conclusion:
I've encountered multiple issues when writing unit tests that arise when I'm trying to test how my analyzers behave around PPDs. I don't have a lot of reason to expect them to be related, except that they both involve PPDs.
The text was updated successfully, but these errors were encountered: