nunit-console
nunit-console copied to clipboard
\u001a test case fails on dotnet6
[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
Setup a minimal repo https://github.com/indy-singh/nunit_console_runner_issue_1349
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.
The string is a valid .NET string, just not valid inside XML CDATA where characters are limited to:
This excludes 0x1A.
Having said that, dotnet test
has no problem with this
However even though tests are shown in Visual Studio Test Explorer
.
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.
Presumably there is a suitable escape mechanism we can use when creating the XML in the first place?
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.