-
Notifications
You must be signed in to change notification settings - Fork 269
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
Implement analyzer to warn for use of Assert methods in async void #4640
Implement analyzer to warn for use of Assert methods in async void #4640
Conversation
11d6a73
to
c09eca4
Compare
c09eca4
to
8646dec
Compare
Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
{ | ||
if (containingSymbol is IMethodSymbol { IsAsync: true, ReturnsVoid: true }) | ||
{ | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReturnsVoid seems to be true also for async Task
methods...
(getting the new warning now in .net framework 4.8 project for async Task TestMethod()
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@UliKu-philips Could you please open an issue for that, with a repro? I'm not able to reproduce the behavior you describe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I think I am wrong... in the example here, triggering MSTEST0040 is caused by the async lambda. The Subscribe
method takes an Action<T>
which is void:
[TestMethod]
public async Task TestMethodAsync()
{
using (var waitEvent = new ManualResetEventSlim())
{
using (Observable.Timer(dueTime: TimeSpan.FromSeconds(0), period: TimeSpan.FromSeconds(1)).Subscribe(
async t =>
{
await Task.Delay(1);
Assert.IsTrue(t > 0);
waitEvent.Set();
}))
{
waitEvent.Wait(TimeSpan.FromSeconds(2));
await Task.Delay(1);
}
}
}
https://github.com/UliKu-philips/UnitTestAsyncTaskWarning/blob/main/UnitTestProject1/UnitTest1.cs
Thanks for the great work!
Fixes #4613