Skip to content

Commit

Permalink
Merge pull request nunit#4773 from stevenaw/4584-selection-issue
Browse files Browse the repository at this point in the history
Test selection issue with normalized newlines
  • Loading branch information
stevenaw authored Aug 4, 2024
2 parents db3b267 + 7ffb366 commit 285bfa5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/NUnitFramework/framework/Interfaces/TNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public string OuterXml
public static TNode FromXml(string xmlText)
{
using var stringReader = new StringReader(xmlText);
using var reader = XmlReader.Create(stringReader);
using var reader = new XmlTextReader(stringReader)
{
Normalization = false
};

// go to starting point
reader.MoveToContent();
Expand Down
23 changes: 23 additions & 0 deletions src/NUnitFramework/testdata/TestCaseSourceAttributeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,28 @@ from spec in TestDataSpec.Specs
.SetProperty("ExpectedTestName", spec.GetTestCaseName(nameof(TestCaseNameTestDataMethod)));

#endregion

#region Multiline selection failure
[TestFixture(Description = "https://github.com/nunit/nunit/issues/4584")]
public class SelectionFail
{
[TestCaseSource(nameof(Data))]
public static void Test(int actual, int expected)
{
Assert.That(actual, Is.EqualTo(expected));
}

public static IEnumerable<TestCaseData> Data
{
get
{
yield return new TestCaseData(42, 42);
yield return new TestCaseData(42, 42).SetName("42 == 42");
yield return new TestCaseData(42, 42).SetName("42\r\n42");
yield return new TestCaseData(42, 42).SetArgDisplayNames("42\n", "42\r\n");
}
}
}
#endregion
}
}
34 changes: 34 additions & 0 deletions src/NUnitFramework/tests/Issue4584.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Execution;
using NUnit.Framework.Tests.TestUtilities;
using NUnit.TestData.TestCaseSourceAttributeFixture;

namespace NUnit.Framework.Tests
{
[TestFixture]
public class Issue4584
{
[Test]
public void DiscoverAndExecution()
{
var fixtureType = typeof(TestCaseSourceAttributeFixture.SelectionFail);
var methodName = nameof(TestCaseSourceAttributeFixture.SelectionFail.Test);
var fixture = TestBuilder.MakeTestFromMethod(fixtureType, methodName);

foreach (var test in fixture.Tests)
{
var filter = TestFilter.FromXml(
$"<filter><name>{test.Name}</name></filter>");
WorkItem? workItem = WorkItemBuilder.CreateWorkItem(fixture, filter, recursive: true);

Assert.That(workItem, Is.Not.Null);
Assert.That(workItem, Is.InstanceOf<CompositeWorkItem>());

var compositeWorkItem = (CompositeWorkItem)workItem;
Assert.That(compositeWorkItem.Children, Has.Count.EqualTo(1));
}
}
}
}

0 comments on commit 285bfa5

Please sign in to comment.