Modules/businessdev.ALbuild.Apps/Private/Resolve-BcCoverageData.ps1
|
function Resolve-BcCoverageData { <# .SYNOPSIS Loads ALbuild coverage data (Summary + Objects) from either an existing coverage-summary.json or raw coverage .dat files, so the summary/threshold/delta cmdlets share one input contract. .PARAMETER SummaryPath Path to a coverage-summary.json (or a folder containing one) produced by Convert-BcCodeCoverage. .PARAMETER CoveragePath Folder of raw *.dat files (or a single .dat) -- converted in-memory (no files written). .PARAMETER WorkspaceRoot AL source root, enabling the honest source-based denominator when converting raw .dat. .PARAMETER DenominatorMode Passed through to Convert-BcCodeCoverage when converting raw .dat. .PARAMETER IncludeNonDebuggable Passed through to Convert-BcCodeCoverage when converting raw .dat; omitted, albuild.json decides. .OUTPUTS PSCustomObject: Summary, Objects, Unmeasured, Excluded. #> [CmdletBinding(DefaultParameterSetName = 'Summary')] [OutputType([PSCustomObject])] param( [Parameter(Mandatory, ParameterSetName = 'Summary')] [string] $SummaryPath, [Parameter(Mandatory, ParameterSetName = 'Raw')] [string] $CoveragePath, [Parameter(ParameterSetName = 'Raw')] [string] $WorkspaceRoot, [Parameter(ParameterSetName = 'Raw')] [ValidateSet('Auto', 'Source', 'CoveredOnly')] [string] $DenominatorMode = 'Auto', [Parameter(ParameterSetName = 'Raw')] [switch] $IncludeNonDebuggable ) if ($PSCmdlet.ParameterSetName -eq 'Summary') { $file = $SummaryPath if (Test-Path -LiteralPath $file -PathType Container) { $file = Join-Path $file 'coverage-summary.json' } if (-not (Test-Path -LiteralPath $file)) { throw "No coverage-summary.json found at '$SummaryPath'." } $doc = Get-Content -LiteralPath $file -Raw | ConvertFrom-Json $read = { param($n) if ($doc.PSObject.Properties.Name -contains $n) { @($doc.$n) } else { @() } } return [PSCustomObject]@{ Summary = $doc.summary; Objects = @($doc.objects); Unmeasured = (& $read 'unmeasured'); Excluded = (& $read 'excluded') } } # Convert raw .dat in-memory to a temp folder (cleaned up), returning the live objects. $tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("albuild-covtmp-" + [guid]::NewGuid()) try { $convertArgs = @{ CoveragePath = $CoveragePath; Format = @('ALbuildJson'); OutputFolder = $tmp; DenominatorMode = $DenominatorMode } if ($WorkspaceRoot) { $convertArgs['WorkspaceRoot'] = $WorkspaceRoot } if ($PSBoundParameters.ContainsKey('IncludeNonDebuggable')) { $convertArgs['IncludeNonDebuggable'] = [bool]$IncludeNonDebuggable } $r = Convert-BcCodeCoverage @convertArgs return [PSCustomObject]@{ Summary = $r.Summary; Objects = @($r.Objects); Unmeasured = @($r.Unmeasured); Excluded = @($r.Excluded) } } finally { if (Test-Path $tmp) { Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue } } } |