Skip to content

Commit d6fa2e3

Browse files
authored
Fix test coverage raw data empty issue on macOS (#21891)
1 parent df6be11 commit d6fa2e3

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

.azure-pipelines/util/test-steps.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ steps:
3131
packageType: sdk
3232
version: 3.1.x
3333

34+
- task: PowerShell@2
35+
displayName: Remove pre-installed Az modules
36+
inputs:
37+
pwsh: true
38+
targetType: filePath
39+
filePath: ./tools/TestFx/Utilities/CommonUtility.ps1
40+
3441
- task: DotNetCoreCLI@2
3542
displayName: Test
3643
inputs:
@@ -54,13 +61,12 @@ steps:
5461

5562
- pwsh: |
5663
Install-Module -Name Pester -RequiredVersion 4.10.1 -Force
57-
Import-Module (Join-Path -Path . -ChildPath Az.Accounts | Join-Path -ChildPath Az.Accounts.psd1) -Force
5864
if ($IsWindows) { $sp = ";" } else { $sp = ":" }
5965
$env:PSModulePath = $env:PSModulePath + $sp + (pwd).Path
6066
$rootFolder = (Get-item $PWD).Parent.Parent
6167
Get-ChildItem -File -Recurse test-module.ps1 | ForEach-Object {
6268
Write-Host $_.Directory.FullName
63-
cd $rootFolder;
69+
cd $rootFolder
6470
.\tools\ExecuteCIStep.ps1 -TestAutorest -AutorestDirectory $_.Directory.FullName
6571
}
6672
workingDirectory: 'artifacts/Debug'

tools/TestFx/Coverage/AnalyzeTestCoverage.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,13 @@ foreach ($moduleName in $allModules) {
191191
$cvgBaseline | Export-Csv -Path $cvgBaselineCsv -Encoding utf8 -NoTypeInformation -Append -Force
192192
}
193193

194-
Write-Host "##[section]`"$moduleName`" total commands # : $totalCommandsCount" -ForegroundColor Green
195-
Write-Host "##[section]`"$moduleName`" tested commands # : $totalTestedCommandsCount" -ForegroundColor Green
196-
Write-Host "##[section]`"$moduleName`" test coverage % : $cvgCommand" -ForegroundColor Green
194+
if ($CalcBaseline.IsPresent) {
195+
Write-Host "##[section]`"$moduleName`" total commands # : $totalCommandsCount" -ForegroundColor Green
196+
Write-Host "##[section]`"$moduleName`" tested commands # : $totalTestedCommandsCount" -ForegroundColor Green
197+
Write-Host "##[section]`"$moduleName`" test coverage % : $cvgCommand" -ForegroundColor Green
197198

198-
Write-Host
199+
Write-Host
200+
}
199201
}
200202

201203
if ($CalcBaseline.IsPresent) {
@@ -207,8 +209,8 @@ if ($CalcBaseline.IsPresent) {
207209
CommandCoverage = $cvgOverall
208210
}
209211
$cvgReportOverall | Export-Csv -Path $cvgReportCsv -Encoding utf8 -NoTypeInformation -Append -Force
210-
}
211212

212-
Write-Host "##[section]Overall commands # : $overallCommandsCount" -ForegroundColor Magenta
213-
Write-Host "##[section]Overall tested commands # : $overallTestedCommandsCount" -ForegroundColor Magenta
214-
Write-Host "##[section]Overall test coverage % : $cvgOverall" -ForegroundColor Magenta
213+
Write-Host "##[section]Overall commands # : $overallCommandsCount" -ForegroundColor Magenta
214+
Write-Host "##[section]Overall tested commands # : $overallTestedCommandsCount" -ForegroundColor Magenta
215+
Write-Host "##[section]Overall test coverage % : $cvgOverall" -ForegroundColor Magenta
216+
}

tools/TestFx/Coverage/ValidateTestCoverage.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ $cvgMessageHeader80 = "|Type|Title|Current Coverage|Last Coverage|Description|`n
3636

3737
$rptData | Where-Object Module -in $testedModules | ForEach-Object {
3838
$module = $_.Module
39-
Write-Host "##[section]Validating test coverage for module $module..."
39+
Write-Host "##[section]Validating test coverage for module $module ..."
4040

4141
$cmdCvg = $_.CommandCoverage
4242
$cmdCvgD = [decimal]$cmdCvg.TrimEnd("%") / 100

0 commit comments

Comments
 (0)