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

Roslyn warning for missing Skip.If() #26

Closed
thomaseyde opened this issue Sep 2, 2022 · 5 comments
Closed

Roslyn warning for missing Skip.If() #26

thomaseyde opened this issue Sep 2, 2022 · 5 comments
Labels

Comments

@thomaseyde
Copy link

Would it be possible to create a Roslyn warning for missing calls to Skip.If(...)?

@AArnott
Copy link
Owner

AArnott commented Sep 4, 2022

Would the warning be on a [SkippableFact] method specifically, that lacks a Skip.If call?

I think that would generate a lot of false positives, because Skip.If just throws a specific exception type, which triggers the test to be recognized as skipped. Any code may throw this, whether in the test method or in a test helper that the test method calls. It's therefore quite common for such a test method to not directly make this call.

@thomaseyde
Copy link
Author

thomaseyde commented Sep 4, 2022 via email

@AArnott
Copy link
Owner

AArnott commented Sep 4, 2022

SkippableFact and Skip.If() belongs together. Calling one without the other should be an error.

I disagree. This is a perfectly valid test:

[SkippableFact]
public void SomeTest()
{
   if (!good) throw new SkipException();
   // more test;
}

But more commonly, this is also perfectly valid:

[SkippableFact]
public void SomeTest()
{
   SetUpEnvironment();
   // more test;
}

void SetUpEnvironment()
{
   Skip.IfNot(OS.IsWindows);
}

See how in that later example, the Skip method call is not in the test method, but is nevertheless called from the test indirectly? We need the attribute to support the test helper method's ability to skip the test.

I raise this issue because a fellow developer have introduced tests that runs fine in CI, but fails on my machine. I suffer too much task switching fixing irrelevant code.

How does that relate to this issue? I can't imagine how a failure on your machine that passes in CI has to do with using the attribute without a Skip.If method call.
Now maybe I can imagine use of Skip.If in a [Fact] method being problematic. Adding a roslyn analyzer that would flag such a method as needing an attribute change may be worthwhile. But the attribute without a visible method call within the test method itself is not an error.

@thomaseyde
Copy link
Author

thomaseyde commented Sep 5, 2022 via email

@AArnott AArnott closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2022
@AArnott AArnott added the wontfix label Sep 5, 2022
@AArnott
Copy link
Owner

AArnott commented Sep 5, 2022

If you were interested in sending a PR that added an analyzer that does this, I don't mind taking it, provided the default behavior is off. And we'd need to of course accept Skip.IfNot as well.

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

No branches or pull requests

2 participants