Skip to content

Commit 712986b

Browse files
authored
Fix StackOverflowException in StringAssert.DoesNotMatch (#806)
1 parent c1cd55d commit 712986b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/TestFramework/MSTest.Core/Assertions/StringAssert.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ public static void DoesNotMatch(string value, Regex pattern)
655655
/// </exception>
656656
public static void DoesNotMatch(string value, Regex pattern, string message)
657657
{
658-
DoesNotMatch(value, pattern, message);
658+
DoesNotMatch(value, pattern, message, null);
659659
}
660660

661661
/// <summary>

test/UnitTests/MSTest.Core.Unit.Tests/Assertions/StringAssertTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.Assertions
77
extern alias FrameworkV2;
88

99
using System;
10+
using System.Text.RegularExpressions;
1011

1112
using MSTestAdapter.TestUtilities;
1213
using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
@@ -60,6 +61,16 @@ public void StringAssertEndsWith()
6061
TestFrameworkV1.StringAssert.Contains(ex.Message, "StringAssert.EndsWith failed");
6162
}
6263

64+
[TestMethod]
65+
public void StringAssertDoesNotMatch()
66+
{
67+
string actual = "The quick brown fox jumps over the lazy dog.";
68+
Regex doesMatch = new Regex("quick brown fox");
69+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.StringAssert.DoesNotMatch(actual, doesMatch));
70+
Assert.IsNotNull(ex);
71+
TestFrameworkV1.StringAssert.Contains(ex.Message, "StringAssert.DoesNotMatch failed");
72+
}
73+
6374
[TestMethod]
6475
public void StringAssertContainsIgnoreCase()
6576
{

0 commit comments

Comments
 (0)