From 56271657cf0bc19c1a4382a73e833d8d73ffafa0 Mon Sep 17 00:00:00 2001 From: kiwigitops Date: Wed, 20 May 2026 15:04:13 -0400 Subject: [PATCH] Handle empty test failure stack traces --- Actions/AnalyzeTests/TestResultAnalyzer.ps1 | 5 ++- Tests/AnalyzeTests.Test.ps1 | 45 ++++++++++++++++----- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Actions/AnalyzeTests/TestResultAnalyzer.ps1 b/Actions/AnalyzeTests/TestResultAnalyzer.ps1 index 1beae6e4fa..d06f13673a 100644 --- a/Actions/AnalyzeTests/TestResultAnalyzer.ps1 +++ b/Actions/AnalyzeTests/TestResultAnalyzer.ps1 @@ -192,10 +192,11 @@ function GetTestResultSummaryMD { foreach($failure in $testcase.ChildNodes) { Write-Host " - Error: $($failure.message)" Write-Host " Stacktrace:" - Write-Host " $($failure."#text".Trim().Replace("`n","`n "))" + $stackTrace = $failure.InnerText.Trim() + Write-Host " $($stackTrace.Replace("`n","`n "))" $testFailureNode = [FailureNode]::new($true) $testFailureNode.errorMessage = $failure.message - $testFailureNode.errorStackTrace = $($failure."#text".Trim().Replace("`n","
      ")) + $testFailureNode.errorStackTrace = $($stackTrace.Replace("`n","
      ")) $testCaseFailureNode.childSummaries.Add($testFailureNode) | Out-Null } $suiteFailureNode.childSummaries.Add($testCaseFailureNode) | Out-Null diff --git a/Tests/AnalyzeTests.Test.ps1 b/Tests/AnalyzeTests.Test.ps1 index b911958e9a..b41ba80b1d 100644 --- a/Tests/AnalyzeTests.Test.ps1 +++ b/Tests/AnalyzeTests.Test.ps1 @@ -135,15 +135,42 @@ Describe "AnalyzeTests Action Tests" { $script:warningCount | Should -be 0 } - It 'Test GetPageScriptingTestResultSummaryMD returns a hashtable' { - . (Join-Path $scriptRoot 'TestResultAnalyzer.ps1') - $output = GetPageScriptingTestResultSummaryMD -testResultsFile (Join-Path $PSScriptRoot 'TestArtifacts/PageScriptingTestResults.xml') -project 'TestProject' - $output | Should -BeOfType 'hashtable' - } - - AfterAll { - Remove-Item -Path $bcptFilename -Force -ErrorAction SilentlyContinue - Remove-Item -Path $bcptBaseLine1 -Force -ErrorAction SilentlyContinue + It 'Test GetPageScriptingTestResultSummaryMD returns a hashtable' { + . (Join-Path $scriptRoot 'TestResultAnalyzer.ps1') + $output = GetPageScriptingTestResultSummaryMD -testResultsFile (Join-Path $PSScriptRoot 'TestArtifacts/PageScriptingTestResults.xml') -project 'TestProject' + $output | Should -BeOfType 'hashtable' + } + + It 'Test GetTestResultSummaryMD handles empty failure stack traces' { + . (Join-Path $scriptRoot '../AL-Go-Helper.ps1') + . (Join-Path $scriptRoot 'TestResultAnalyzer.ps1') + + $testResultsFile = Join-Path ([System.IO.Path]::GetTempPath()) "$([GUID]::NewGuid().ToString()).xml" + try { + @' + + + + + + + + + + + +'@ | Set-Content -Path $testResultsFile -Encoding UTF8 + + { GetTestResultSummaryMD -testResultsFile $testResultsFile } | Should -Not -Throw + } + finally { + Remove-Item -Path $testResultsFile -Force -ErrorAction SilentlyContinue + } + } + + AfterAll { + Remove-Item -Path $bcptFilename -Force -ErrorAction SilentlyContinue + Remove-Item -Path $bcptBaseLine1 -Force -ErrorAction SilentlyContinue Remove-Item -Path $bcptBaseLine2 -Force -ErrorAction SilentlyContinue } }