Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/nuget/Microsoft.VSSDK.BuildTool…
Browse files Browse the repository at this point in the history
…s-16.11.35
  • Loading branch information
OsirisTerje authored Nov 5, 2021
2 parents 6f7c5d3 + 1964278 commit cc7592c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
5 changes: 1 addition & 4 deletions src/NUnitTestAdapter/Internal/Extensions.cs
Original file line number Diff line number Diff line change
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;
}
}
13 changes: 10 additions & 3 deletions src/NUnitTestAdapter/NUnitEngine/NUnitEngineAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,15 @@ public void CloseRunner()
if (Runner.IsTestRunning)
Runner.StopRun(true);

Runner.Unload();
Runner.Dispose();
try
{
Runner.Unload();
Runner.Dispose();
}
catch (NUnitEngineUnloadException ex)
{
logger.Warning($"Engine encountered NUnitEngineUnloadException : {ex.Message}");
}
Runner = null;
}

Expand Down Expand Up @@ -159,7 +166,7 @@ public string GetXmlFilePath(string folder, string defaultFileName, string exten
int i = 1;
while (true)
{
string path = Path.Combine(folder, $"{defaultFileName}.{i++}.{extension}");
string path = Path.Combine(folder, $"{defaultFileName}.{i++}.{extension}");
if (!File.Exists(path))
return path;
}
Expand Down
5 changes: 3 additions & 2 deletions src/NUnitTestAdapter/NUnitEventListener.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 cc7592c

Please sign in to comment.