Skip to content
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

Fix for issue #516 #908

Merged
merged 2 commits into from Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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