Skip to content

Commit 94d1cd6

Browse files
author
Corniel Nobel
committed
Extend test to cover Thread.Sleep() within lambda's.
1 parent 0682e00 commit 94d1cd6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TestsShouldNotUseThreadSleep.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using NUnit.Framework;
3+
using System;
34
using System.Threading;
45
using Xunit;
56
using Alias = System.Threading.Thread;
@@ -70,4 +71,10 @@ void Wait()
7071
Thread.Sleep(42); // Noncompliant
7172
}
7273
}
74+
75+
[Test]
76+
public void ThreadSleepInLambdaFunction()
77+
{
78+
Action sleep = () => Thread.Sleep(42); // Noncompliant
79+
}
7380
}

analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TestsShouldNotUseThreadSleep.vb

+4
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ Class NonCompliant
5151
Sleep(42) ' Noncompliant
5252
End Sub
5353

54+
<Test>
55+
Public Sub ThreadSleepInLambdaFunction()
56+
Dim sleep As Action = Sub() Thread.Sleep(42) ' Noncompliant
57+
End Sub
5458
End Class

0 commit comments

Comments
 (0)