haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
663 stars 96 forks source link

JUnit XML can contain invalid escape sequences #324

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hello,

I just got through adding a test project for all of my projects in a GitLab repo. I added the JUnit test result adapter, and ran a build with a test that would be sure to fail, to ensure that I'd done everything right.

I see a message that says Test summary failed loading results, on GitLab, and upon further inspection it seems that the XML is invalid.

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
  <testsuite name="Nemo.Processors.RP65816.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
    <testcase name="addressing/absolute address x, long/always fails" time="0.065">
      <failure message="&#xA;.&#xA;&#x1B;[32mexpected&#x1B;[36m: &#x1B;[32m2&#x1B;[36m&#xA;&#x1B;[31m  actual&#x1B;[36m: &#x1B;[31m1&#x1B;[36m&#xA;   at Nemo.Processors.RP65816.Tests.ModeTests.modes@137-6.Invoke(Unit unitVar) in /home/adam/Repos/nemo/Nemo.Processors.RP65816.Tests/src/ModeTests.fs:line 137&#xA;   at Expecto.Impl.execTestAsync@935-1.Invoke(Unit unitVar) in C:\Users\Anthony Lloyd\src\expecto\Expecto\Expecto.fs:line 939&#xA;   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2)&#xA;   at &lt;StartupCode$FSharp-Core&gt;.$Async.StartChild@1641-5.Invoke(AsyncActivation`1 ctxt)&#xA;   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction)" />
    </testcase>
</testsuites>

As you can see, the failure element contains the character &#x1B; to encode the beginning of an ANSI escape sequence, representing color. GitLab (And other XML tools) don't recognize this as valid, it's also not part of the XML 1.0 Rev 5 spec.

There are a few solutions to this, like being able to disable colors on the console output, or stripping out such sequences before dumping to XML.

ghost commented 5 years ago

I've just found the --colours flag, waiting on confirmation that this fixes the issue.

That did the trick!