Skip to content

Commit

Permalink
Fix possible NRE in NUnit3 export (#2444)
Browse files Browse the repository at this point in the history
* Fix possible NRE in NUnit3 export

* Fix tests on Windows
  • Loading branch information
fflaten authored May 13, 2024
1 parent 6d77316 commit 93c6610
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/functions/TestResults.NUnit3.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,13 @@ function Write-NUnit3TestCaseAttributes {
}

function Write-NUnit3OutputElement ($Output, [System.Xml.XmlWriter] $XmlWriter) {
$outputString = @(foreach ($o in $Output) { $o.ToString() }) -join [System.Environment]::NewLine
$outputString = @(foreach ($o in $Output) {
if ($null -eq $o) {
[string]::Empty
} else {
$o.ToString()
}
}) -join [System.Environment]::NewLine

$XmlWriter.WriteStartElement('output')
$XmlWriter.WriteCData($outputString)
Expand Down
7 changes: 6 additions & 1 deletion tst/Pester.RSpec.TestResults.NUnit3.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ i -PassThru:$PassThru {
}
It 'Test' {
'test output'
$null # Should not throw but leave blank line
123
$true | Should -Be $true
}
}
Expand All @@ -423,7 +425,10 @@ i -PassThru:$PassThru {

$xmlTest = $xmlDescribe.'test-case'
$xmlTest.name | Verify-Equal 'Describe.Test'
$xmlTest.output.'#cdata-section' | Verify-Equal 'test output'
$message = $xmlTest.output.'#cdata-section' -split "`n"
$message[0] | Verify-Equal 'test output'
$message[1] | Verify-Equal ''
$message[2] | Verify-Equal '123'
}

t 'should add site-attribute to identity failure location' {
Expand Down

0 comments on commit 93c6610

Please sign in to comment.