Skip to content

Commit

Permalink
Fix a bug where Pester fails to produce report if an error message co…
Browse files Browse the repository at this point in the history
…ntains VT sequences
  • Loading branch information
ocalvo committed Dec 3, 2024
1 parent 7e5d35c commit 71c5b03
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/functions/TestResults.NUnit3.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ function Write-NUnit3TestCaseAttributes {
$XmlWriter.WriteAttributeString('asserts', '1') # required attr, so hardcoding 1:1 per testcase
}

function Write-NUnit3OutputElement ($Output, [System.Xml.XmlWriter] $XmlWriter) {
function Format-CDataString ($Output) {

# The characters in the range 0x01 to 0x20 are invalid for CData
# (with the exception of the characters 0x09, 0x0A and 0x0D)
# We convert each of these using the unicode printable version,
Expand Down Expand Up @@ -572,8 +573,13 @@ function Write-NUnit3OutputElement ($Output, [System.Xml.XmlWriter] $XmlWriter)
}

$outputString = $o -join [Environment]::NewLine
return $outputString
}


function Write-NUnit3OutputElement ($Output, [System.Xml.XmlWriter] $XmlWriter) {
$XmlWriter.WriteStartElement('output')
$XmlWriter.WriteCData($outputString)
$XmlWriter.WriteCData((Format-CDataString $output))
$XmlWriter.WriteEndElement()
}

Expand All @@ -585,12 +591,12 @@ function Write-NUnit3FailureElement ($TestResult, [System.Xml.XmlWriter] $XmlWri
$XmlWriter.WriteStartElement('failure')

$XmlWriter.WriteStartElement('message')
$XmlWriter.WriteCData($result.FailureMessage)
$XmlWriter.WriteCData((Format-CDataString $result.FailureMessage))
$XmlWriter.WriteEndElement() # Close message

if ($result.StackTrace) {
$XmlWriter.WriteStartElement('stack-trace')
$XmlWriter.WriteCData($result.StackTrace)
$XmlWriter.WriteCData((Format-CDataString $result.StackTrace))
$XmlWriter.WriteEndElement() # Close stack-trace
}

Expand All @@ -604,7 +610,7 @@ function Write-NUnitReasonElement ($TestResult, [System.Xml.XmlWriter] $XmlWrite
if ($result.FailureMessage) {
$XmlWriter.WriteStartElement('reason')
$XmlWriter.WriteStartElement('message')
$XmlWriter.WriteCData($result.FailureMessage)
$XmlWriter.WriteCData((Format-CDataString $result.FailureMessage))
$XmlWriter.WriteEndElement() # Close message
$XmlWriter.WriteEndElement() # Close reason
}
Expand Down

0 comments on commit 71c5b03

Please sign in to comment.