nunit-console icon indicating copy to clipboard operation
nunit-console copied to clipboard

\u001a test case fails on dotnet6

Open indy-singh opened this issue 1 year ago • 8 comments

[TestCase("\u001a")]
public void Then(string foo) => Assert.Pass();

The above testcase works fine on net472 + NUnit Console 3.16.3 (Release).

But it fails on dotnet6.0 + NUnit Console 3.16.3 (Release):-

With this exception:-

--XmlException
'', hexadecimal value 0x1A, is an invalid character. Line 1, position 1571.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ThrowInvalidChar(Char[] data, Int32 length, Int32 invCharPos)
   at System.Xml.XmlTextReaderImpl.ParseCDataOrComment(XmlNodeType type, Int32& outStartPos, Int32& outEndPos)
   at System.Xml.XmlTextReaderImpl.ParseCDataOrComment(XmlNodeType type)
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.LoadXml(String xml)
   at NUnit.XmlHelper.CreateXmlNode(String xml)
   at NUnit.Engine.Runners.WorkItemTracker.NUnit.Engine.ITestEventListener.OnTestEvent(String report)
   at NUnit.Engine.Runners.TestEventDispatcher.OnTestEvent(String report)
   at NUnit.Engine.Runners.MasterTestRunner.RunTests(ITestEventListener listener, TestFilter filter)
   at NUnit.Engine.Runners.MasterTestRunner.Run(ITestEventListener listener, TestFilter filter)
   at NUnit.ConsoleRunner.ConsoleRunner.RunTests(TestPackage package, TestFilter filter)
   at NUnit.ConsoleRunner.Program.Main(String[] args)

Cheers, Indy

indy-singh avatar Jun 27 '23 16:06 indy-singh

Setup a minimal repo https://github.com/indy-singh/nunit_console_runner_issue_1349

indy-singh avatar Jun 27 '23 18:06 indy-singh

This is more likely a breaking change by Microsoft between Framework 4.7.2 and NET 6.

In my opinion this is not a bug in NUnit. The argument is a dotnet string and should be valid. Consider changing the argument type.

ueli-werner avatar Aug 24 '23 15:08 ueli-werner

The string is a valid .NET string, just not valid inside XML CDATA where characters are limited to: image

This excludes 0x1A.

Having said that, dotnet test has no problem with this However even though tests are shown in Visual Studio Test Explorer. image

They don't seem to run. I see error message: NUnit3TestExecutor discovered 0 of 0 NUnit test cases using Current Discovery mode, Explicit run

I don't know if the XML is NUnit specific or dictated by the test specification. If arguments are stored there, they must be stored in such a way that they result in valid XML. Maybe they need encoding.

manfred-brands avatar Aug 25 '23 01:08 manfred-brands

Presumably there is a suitable escape mechanism we can use when creating the XML in the first place?

andrewimcclement avatar Feb 02 '24 18:02 andrewimcclement

I think the XML is NUnit specific and the framework have special code to handle this - see e.g. https://github.com/nunit/nunit/blob/68d994772d10de54ac960ea8379ee966a3293083/src/NUnitFramework/framework/XmlExtensions.cs#L76 - but apparent we also need some escaping in the engine.

mikkelbu avatar Feb 02 '24 20:02 mikkelbu