Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Actions/AnalyzeTests/TestResultAnalyzer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,14 @@ function GetBcptSummaryMD {
)

$bcpt = ReadBcptFile -bcptTestResultsFile $bcptTestResultsFile
if (-not $bcpt) {
if ($null -eq $bcpt) {
return ''
}
if ($bcpt.Count -eq 0) {
# File exists but contained no log entries - test run produced no output
OutputWarning "BCPT tests were run but produced no results. The BCPT test suite may have failed to start or the test codeunits exited without recording any measurements."
return "No BCPT results were recorded. The BCPT test suite may have failed to start or the test codeunits exited without recording any measurements.`n`n> Verify that the BCPT suite definition matches the published test codeunit IDs and that the test codeunits are reachable from the test runner."
}
$baseLine = ReadBcptFile -bcptTestResultsFile $baseLinePath
if ($baseLine) {
if ($null -eq $bcptThresholds) {
Expand Down
32 changes: 32 additions & 0 deletions Tests/AnalyzeTests.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,38 @@ Describe "AnalyzeTests Action Tests" {
$bcpt."SUITE1"."1".operations."operation2".measurements.Count | should -Be 4
}

It 'Test ReadBcptFile returns null when file does not exist' {
. (Join-Path $scriptRoot '../AL-Go-Helper.ps1')
. (Join-Path $scriptRoot 'TestResultAnalyzer.ps1')
$bcpt = ReadBcptFile -bcptTestResultsFile 'non-existent-file.json'
$bcpt | Should -Be $null
}

It 'Test GetBcptSummaryMD returns empty string when file does not exist' {
. (Join-Path $scriptRoot '../AL-Go-Helper.ps1')
. (Join-Path $scriptRoot 'TestResultAnalyzer.ps1')
$md = GetBcptSummaryMD -bcptTestResultsFile 'non-existent-file.json'
$md | Should -Be ''
}

It 'Test GetBcptSummaryMD returns warning message when file exists but contains no entries' {
. (Join-Path $scriptRoot '../AL-Go-Helper.ps1')
. (Join-Path $scriptRoot 'TestResultAnalyzer.ps1')
$emptyResultsFile = Join-Path ([System.IO.Path]::GetTempPath()) "$([GUID]::NewGuid().ToString()).json"
$script:warningCount = 0
Mock OutputWarning { Param([string] $message) Write-Host "WARNING: $message"; $script:warningCount++ }
try {
Set-Content -Path $emptyResultsFile -Value '[]' -Encoding UTF8
$md = GetBcptSummaryMD -bcptTestResultsFile $emptyResultsFile
$md | Should -Not -BeNullOrEmpty
$md | Should -Match 'No BCPT results were recorded'
$script:warningCount | Should -Be 1
}
Comment on lines +95 to +107
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “file exists but contains no entries” test writes JSON null to disk. BCPT result files appear to be JSON arrays (your helper uses @(...) | ConvertTo-Json), so an empty-results file would more realistically be [] (empty array). Using an empty array here would better match the real-world format and protect against differences in how ConvertFrom-Json handles null vs [].

Copilot uses AI. Check for mistakes.
finally {
Remove-Item -Path $emptyResultsFile -Force -ErrorAction SilentlyContinue
}
}

It 'Test GetBcptSummaryMD (no baseline)' {
. (Join-Path $scriptRoot '../AL-Go-Helper.ps1')
. (Join-Path $scriptRoot 'TestResultAnalyzer.ps1')
Expand Down