Skip to content

Commit 4c6a88f

Browse files
authored
Fixed test coverage issue when a module was built but not tested. (#22708)
1 parent 8e052b2 commit 4c6a88f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tools/TestFx/Coverage/AnalyzeTestCoverage.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ $psCommonParameters = @("-Break", "-Confirm", "-Debug", "-DefaultProfile", "-Err
3333
"-OutBuffer", "-OutVariable", "-PassThru", "-PipelineVariable", "-Proxy", "-ProxyCredential", "-ProxyUseDefaultCredentials", "-Verbose", "-WarningAction", "-WarningVariable", "-WhatIf")
3434

3535
$repoDir = $PSScriptRoot | Split-Path | Split-Path | Split-Path
36-
$debugDir = Join-Path -Path $repoDir -ChildPath "artifacts" | Join-Path -ChildPath "Debug"
36+
$artifactsDir = Join-Path -Path $repoDir -ChildPath "artifacts"
37+
$debugDir = Join-Path -Path $artifactsDir -ChildPath "Debug"
3738

3839
$accountsModuleName = "Az.Accounts"
3940
$accountsModulePsd1 = Join-Path -Path $debugDir -ChildPath $accountsModuleName | Join-Path -ChildPath "$accountsModuleName.psd1"
@@ -59,16 +60,25 @@ else {
5960
$cvgReportCsv = Join-Path -Path $cvgResultsDir -ChildPath "Report.csv"
6061
({} | Select-Object "Module", "TotalCommands", "TestedCommands", "CommandCoverage", "TotalParameterSets", "TestedParameterSets", "ParameterSetCoverage", "TotalParameters", "TestedParameters", "ParameterCoverage" | ConvertTo-Csv -NoTypeInformation)[0] | Out-File -LiteralPath $cvgReportCsv -Encoding utf8 -Force
6162

63+
$allModules = Get-ChildItem -Path $debugDir -Filter "Az.*" -Directory -Name
64+
6265
if ($CalcBaseline.IsPresent) {
66+
$testedModules = $allModules
6367
$cvgBaselineCsv = Join-Path -Path $cvgResultsDir -ChildPath "Baseline.csv"
6468
({} | Select-Object "Module", "CommandCoverage" | ConvertTo-Csv -NoTypeInformation)[0] | Out-File -LiteralPath $cvgBaselineCsv -Encoding utf8 -Force
6569
}
70+
else {
71+
$ciPlanFilePath = Join-Path -Path $artifactsDir -ChildPath "PipelineResult" | Join-Path -ChildPath "CIPlan.json"
72+
$ciPlan = Get-Content -Path $ciPlanFilePath -Raw | ConvertFrom-Json
73+
if ($ciPlan.test.Length -gt 0) {
74+
$testedModules = $allModules | Where-Object { $_.Substring(3) -in $ciPlan.test }
75+
}
76+
}
6677

6778
$overallCommandsCount = 0
6879
$overallTestedCommandsCount = 0
6980

70-
$allModules = Get-ChildItem -Path $debugDir -Filter "Az.*" -Directory -Name
71-
foreach ($moduleName in $allModules) {
81+
foreach ($moduleName in $testedModules) {
7282
$simpleModuleName = $moduleName.Substring(3)
7383
$hasRawData = $true
7484

0 commit comments

Comments
 (0)