Skip to content

Commit 93c6610

Browse files
authored
Fix possible NRE in NUnit3 export (#2444)
* Fix possible NRE in NUnit3 export * Fix tests on Windows
1 parent 6d77316 commit 93c6610

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Diff for: src/functions/TestResults.NUnit3.ps1

+7-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,13 @@ function Write-NUnit3TestCaseAttributes {
539539
}
540540

541541
function Write-NUnit3OutputElement ($Output, [System.Xml.XmlWriter] $XmlWriter) {
542-
$outputString = @(foreach ($o in $Output) { $o.ToString() }) -join [System.Environment]::NewLine
542+
$outputString = @(foreach ($o in $Output) {
543+
if ($null -eq $o) {
544+
[string]::Empty
545+
} else {
546+
$o.ToString()
547+
}
548+
}) -join [System.Environment]::NewLine
543549

544550
$XmlWriter.WriteStartElement('output')
545551
$XmlWriter.WriteCData($outputString)

Diff for: tst/Pester.RSpec.TestResults.NUnit3.ts.ps1

+6-1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ i -PassThru:$PassThru {
409409
}
410410
It 'Test' {
411411
'test output'
412+
$null # Should not throw but leave blank line
413+
123
412414
$true | Should -Be $true
413415
}
414416
}
@@ -423,7 +425,10 @@ i -PassThru:$PassThru {
423425

424426
$xmlTest = $xmlDescribe.'test-case'
425427
$xmlTest.name | Verify-Equal 'Describe.Test'
426-
$xmlTest.output.'#cdata-section' | Verify-Equal 'test output'
428+
$message = $xmlTest.output.'#cdata-section' -split "`n"
429+
$message[0] | Verify-Equal 'test output'
430+
$message[1] | Verify-Equal ''
431+
$message[2] | Verify-Equal '123'
427432
}
428433

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

0 commit comments

Comments
 (0)