Skip to content

Commit fd4c421

Browse files
committed
FIx for issue #516
1 parent 42a8779 commit fd4c421

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

src/NUnitTestAdapter/Internal/Extensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ public static class TypeExtensions
1010
#endif
1111
public static class StringExtensions
1212
{
13-
public static bool IsNullOrWhiteSpace(this string value)
14-
{
15-
return value == null || value.Trim().Length == 0;
16-
}
13+
public static bool IsNullOrWhiteSpace(this string value) => string.IsNullOrEmpty(value) || value.Trim().Length == 0;
1714
}
1815
}

src/NUnitTestAdapter/NUnitEventListener.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
3131
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
3232
using NUnit.Engine;
33+
using NUnit.VisualStudio.TestAdapter;
3334
using NUnit.VisualStudio.TestAdapter.Dump;
3435
using NUnit.VisualStudio.TestAdapter.Internal;
3536
using NUnit.VisualStudio.TestAdapter.NUnitEngine;
@@ -159,14 +160,14 @@ public void TestFinished(INUnitTestEventTestCase resultNode)
159160
var result = testConverter.GetVsTestResults(resultNode, outputNodes ?? EmptyNodes);
160161
if (settings.ConsoleOut == 1)
161162
{
162-
if (!string.IsNullOrEmpty(result.ConsoleOutput) && result.ConsoleOutput != NL)
163+
if (!result.ConsoleOutput.IsNullOrWhiteSpace() && result.ConsoleOutput != NL)
163164
{
164165
string msg = result.ConsoleOutput;
165166
if (settings.UseTestNameInConsoleOutput)
166167
msg = $"{resultNode.Name}: {msg}";
167168
recorder.SendMessage(TestMessageLevel.Informational, msg);
168169
}
169-
if (!string.IsNullOrEmpty(resultNode.ReasonMessage))
170+
if (!resultNode.ReasonMessage.IsNullOrWhiteSpace())
170171
{
171172
recorder.SendMessage(TestMessageLevel.Informational, $"{resultNode.Name}: {resultNode.ReasonMessage}");
172173
}

src/NUnitTestAdapterTests/NUnitEventListenerTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,32 @@ public void TestFinished_CallsRecordEndCorrectly()
106106
Assert.That(testLog.Events[0].TestOutcome, Is.EqualTo(TestOutcome.Passed));
107107
}
108108

109+
/// <summary>
110+
/// Issue516
111+
/// </summary>
112+
[TestCase(null)]
113+
[TestCase("")]
114+
[TestCase(" ")]
115+
[TestCase("\t")]
116+
[TestCase("\r")]
117+
[TestCase("\n")]
118+
[TestCase("\r\n")]
119+
public void TestFinished_DoNotSendWhiteSpaceToMessages(string data)
120+
{
121+
var testcase = Substitute.For<INUnitTestEventTestCase>();
122+
testcase.Name.Returns($"Test1({data})");
123+
testcase.FullName.Returns($"Issue516.Tests.Test1({data})");
124+
testcase.Output.Returns($"{data}");
125+
settings.ConsoleOut.Returns(1);
126+
listener.TestFinished(testcase);
127+
Assert.That(testLog.Events.Count, Is.EqualTo(0));
128+
129+
130+
131+
}
132+
133+
134+
109135
[Test]
110136
public void TestFinished_CallsRecordResultCorrectly()
111137
{

0 commit comments

Comments
 (0)