Skip to content

Commit

Permalink
Merge pull request #908 from nunit/Issue516
Browse files Browse the repository at this point in the history
Fix for issue #516
  • Loading branch information
OsirisTerje committed Nov 5, 2021
2 parents 42a8779 + af10a0f commit 1964278
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/NUnitTestAdapter/Internal/Extensions.cs
Expand Up @@ -10,9 +10,6 @@ public static class TypeExtensions
#endif
public static class StringExtensions
{
public static bool IsNullOrWhiteSpace(this string value)
{
return value == null || value.Trim().Length == 0;
}
public static bool IsNullOrWhiteSpace(this string value) => string.IsNullOrEmpty(value) || value.Trim().Length == 0;
}
}
5 changes: 3 additions & 2 deletions src/NUnitTestAdapter/NUnitEventListener.cs
Expand Up @@ -30,6 +30,7 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NUnit.Engine;
using NUnit.VisualStudio.TestAdapter;
using NUnit.VisualStudio.TestAdapter.Dump;
using NUnit.VisualStudio.TestAdapter.Internal;
using NUnit.VisualStudio.TestAdapter.NUnitEngine;
Expand Down Expand Up @@ -159,14 +160,14 @@ public void TestFinished(INUnitTestEventTestCase resultNode)
var result = testConverter.GetVsTestResults(resultNode, outputNodes ?? EmptyNodes);
if (settings.ConsoleOut == 1)
{
if (!string.IsNullOrEmpty(result.ConsoleOutput) && result.ConsoleOutput != NL)
if (!result.ConsoleOutput.IsNullOrWhiteSpace() && result.ConsoleOutput != NL)
{
string msg = result.ConsoleOutput;
if (settings.UseTestNameInConsoleOutput)
msg = $"{resultNode.Name}: {msg}";
recorder.SendMessage(TestMessageLevel.Informational, msg);
}
if (!string.IsNullOrEmpty(resultNode.ReasonMessage))
if (!resultNode.ReasonMessage.IsNullOrWhiteSpace())
{
recorder.SendMessage(TestMessageLevel.Informational, $"{resultNode.Name}: {resultNode.ReasonMessage}");
}
Expand Down
23 changes: 23 additions & 0 deletions src/NUnitTestAdapterTests/NUnitEventListenerTests.cs
Expand Up @@ -106,6 +106,29 @@ public void TestFinished_CallsRecordEndCorrectly()
Assert.That(testLog.Events[0].TestOutcome, Is.EqualTo(TestOutcome.Passed));
}

/// <summary>
/// Issue516
/// </summary>
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
[TestCase("\t")]
[TestCase("\r")]
[TestCase("\n")]
[TestCase("\r\n")]
public void TestFinished_DoNotSendWhiteSpaceToMessages(string data)
{
var testcase = Substitute.For<INUnitTestEventTestCase>();
testcase.Name.Returns($"Test1({data})");
testcase.FullName.Returns($"Issue516.Tests.Test1({data})");
testcase.Output.Returns($"{data}");
settings.ConsoleOut.Returns(1);
listener.TestFinished(testcase);
Assert.That(testLog.Events.Count, Is.EqualTo(0));
}



[Test]
public void TestFinished_CallsRecordResultCorrectly()
{
Expand Down

0 comments on commit 1964278

Please sign in to comment.