@@ -60,59 +60,65 @@ jobs:
6060 - name : Install PowerShell test dependency
6161 shell : pwsh
6262 run : Install-Module Pester -RequiredVersion 5.7.1 -Scope CurrentUser -Force
63- - name : Test Hidi NuGet helper with measured coverage
63+ - name : Test Hidi NuGet helpers with measured coverage
6464 shell : pwsh
6565 run : |
6666 $ErrorActionPreference = 'Stop'
6767 Import-Module Pester -RequiredVersion 5.7.1 -ErrorAction Stop
68- $helperPath = 'scripts/check-nuget-package-published.ps1'
69- $helper = ( Resolve-Path $helperPath ).Path
68+ $helperPaths = @( 'scripts/check-nuget-package-published.ps1', 'scripts/verify-hidi-package-assembly.ps1')
69+ $helpers = @($helperPaths | ForEach-Object { ( Resolve-Path $_ ).Path })
7070 $outputRoot = Join-Path $PWD 'artifacts\hidi\powershell-coverage'
7171 New-Item -ItemType Directory -Force -Path $outputRoot | Out-Null
7272 $configuration = New-PesterConfiguration
73- $configuration.Run.Path = 'test\Microsoft.OpenApi.Hidi.Tests\check-nuget-package-published.Tests.ps1'
73+ $configuration.Run.Path = @( 'test\Microsoft.OpenApi.Hidi.Tests\check-nuget-package-published.Tests.ps1', 'test\Microsoft.OpenApi.Hidi.Tests\verify-hidi-package-assembly.Tests.ps1')
7474 $configuration.Run.PassThru = $true
7575 $configuration.CodeCoverage.Enabled = $true
76- $configuration.CodeCoverage.Path = $helper
76+ $configuration.CodeCoverage.Path = $helpers
7777 $configuration.CodeCoverage.OutputFormat = 'JaCoCo'
7878 $configuration.CodeCoverage.OutputPath = Join-Path $outputRoot 'pester-coverage.xml'
7979 $configuration.CodeCoverage.CoveragePercentTarget = 80
8080 $result = Invoke-Pester -Configuration $configuration
81- if ($result.FailedCount -gt 0 -or $result.PassedCount -lt 24 ) {
82- throw "Hidi NuGet helper tests failed or did not execute all 24 cases."
81+ if ($result.FailedCount -gt 0 -or $result.PassedCount -lt 45 ) {
82+ throw "Hidi NuGet helper tests failed or did not execute all 45 cases."
8383 }
8484 $report = [xml](Get-Content $configuration.CodeCoverage.OutputPath.Value -Raw)
8585 $sourceFiles = @($report.SelectNodes('//sourcefile'))
86- if ($sourceFiles.Count -ne 1 -or $sourceFiles[0].name -ne [IO.Path]::GetFileName($helper)) {
87- throw 'Expected measured coverage of only the Hidi NuGet helper.'
88- }
89- $lines = @($sourceFiles[0].SelectNodes('line'))
90- $sourceLineCount = @(Get-Content $helper).Count
91- $lineNumbers = @($lines | ForEach-Object { [int]$_.nr })
92- if ($lines.Count -eq 0 -or @($lineNumbers | Select-Object -Unique).Count -ne $lines.Count -or
93- @($lines | Where-Object {
94- [int]$_.nr -le 0 -or [int]$_.nr -gt $sourceLineCount -or
95- -not $_.HasAttribute('ci') -or -not $_.HasAttribute('mi') -or
96- [int]$_.ci -lt 0 -or [int]$_.mi -lt 0 -or ([int]$_.ci + [int]$_.mi) -le 0
97- }).Count -gt 0) {
98- throw 'Missing or invalid measured helper coverage lines.'
99- }
100- $covered = @($lines | Where-Object { [int]$_.ci -gt 0 }).Count
101- if ($covered / $lines.Count -lt 0.8) {
102- throw "Insufficient measured Hidi helper coverage: $covered/$($lines.Count) lines."
86+ if ($sourceFiles.Count -ne $helpers.Count) {
87+ throw 'Expected measured coverage of both Hidi NuGet helpers.'
10388 }
10489 $coverage = [xml]'<coverage version="1"/>'
105- $file = $coverage.CreateElement('file')
106- $file.SetAttribute('path', $helperPath)
107- [void]$coverage.DocumentElement.AppendChild($file)
108- foreach ($line in $lines) {
109- $entry = $coverage.CreateElement('lineToCover')
110- $entry.SetAttribute('lineNumber', $line.nr)
111- $entry.SetAttribute('covered', ([int]$line.ci -gt 0).ToString().ToLowerInvariant())
112- [void]$file.AppendChild($entry)
90+ foreach ($helperPath in $helperPaths) {
91+ $helper = (Resolve-Path $helperPath).Path
92+ $sourceFile = @($sourceFiles | Where-Object { $_.name -eq [IO.Path]::GetFileName($helper) })
93+ if ($sourceFile.Count -ne 1) { throw "Missing or ambiguous helper coverage: $helperPath" }
94+ $lines = @($sourceFile[0].SelectNodes('line'))
95+ $sourceLineCount = @(Get-Content $helper).Count
96+ $lineNumbers = @($lines | ForEach-Object { [int]$_.nr })
97+ if ($lines.Count -eq 0 -or @($lineNumbers | Select-Object -Unique).Count -ne $lines.Count -or
98+ @($lines | Where-Object {
99+ [int]$_.nr -le 0 -or [int]$_.nr -gt $sourceLineCount -or
100+ -not $_.HasAttribute('ci') -or -not $_.HasAttribute('mi') -or
101+ [int]$_.ci -lt 0 -or [int]$_.mi -lt 0 -or ([int]$_.ci + [int]$_.mi) -le 0
102+ }).Count -gt 0) {
103+ throw "Missing or invalid measured helper coverage lines: $helperPath"
104+ }
105+ $covered = @($lines | Where-Object { [int]$_.ci -gt 0 }).Count
106+ if ($covered / $lines.Count -lt 0.8) {
107+ throw "Insufficient measured Hidi helper coverage: $helperPath $covered/$($lines.Count) lines."
108+ }
109+ $file = $coverage.CreateElement('file')
110+ $file.SetAttribute('path', $helperPath)
111+ [void]$coverage.DocumentElement.AppendChild($file)
112+ foreach ($line in $lines) {
113+ $entry = $coverage.CreateElement('lineToCover')
114+ $entry.SetAttribute('lineNumber', $line.nr)
115+ $entry.SetAttribute('covered', ([int]$line.ci -gt 0).ToString().ToLowerInvariant())
116+ [void]$file.AppendChild($entry)
117+ }
118+ Write-Host "Measured Hidi helper coverage: $helperPath $covered/$($lines.Count) lines."
113119 }
114120 $coverage.Save((Join-Path $outputRoot 'sonar-coverage.xml'))
115- Write-Host "Measured Hidi NuGet helper coverage: $covered/$($lines.Count) lines; Sonar generic report generated."
121+ Write-Host 'Sonar generic report generated for both Hidi NuGet helpers.'
116122 - name : Build and analyze
117123 env :
118124 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
0 commit comments