@@ -47,35 +47,33 @@ $excludedModules = @(
4747 " Az.Elastic" ,
4848 " Az.HanaOnAzure" ,
4949 " Az.HealthBot" ,
50- " Az.ImportExport" ,
5150 " Az.LabServices" ,
5251 " Az.Logz" ,
5352 " Az.ManagedServices" ,
5453 " Az.Maps" ,
5554 " Az.MariaDb" ,
5655 " Az.Marketplace" ,
5756 " Az.MonitoringSolutions" ,
58- " Az.MySql" ,
5957 " Az.Portal" ,
6058 " Az.PostgreSql" ,
6159 " Az.ProviderHub" ,
6260 " Az.Purview" ,
6361 " Az.Quota" ,
6462 " Az.ResourceGraph" ,
6563 " Az.ResourceMover" ,
66- " Az.SignalR" ,
6764 " Az.StreamAnalytics" ,
6865 " Az.Synapse" ,
6966 " Az.TimeSeriesInsights" ,
7067 " Az.Websites" ,
7168 " Az.WindowsIotServices"
7269)
7370
74- if (-not (Test-Path - LiteralPath $testCoverageResultsDirectory - PathType Container))
75- {
71+ if (! (Test-Path - LiteralPath $testCoverageResultsDirectory - PathType Container)) {
7672 New-Item - Path $testCoverageRootDirectory - Name " Results" - ItemType Directory
7773}
78- Get-ChildItem - LiteralPath $testCoverageResultsDirectory - Filter " *.txt" | Remove-Item - Force
74+ else {
75+ Get-ChildItem - LiteralPath $testCoverageResultsDirectory - Filter " *.txt" | Remove-Item - Force
76+ }
7977
8078$accountModuleName = " Az.Accounts"
8179$accountModuleFullPath = Join-Path - Path $debugDirectory - ChildPath $accountModuleName | Join-Path - ChildPath " $accountModuleName .psd1"
@@ -89,22 +87,23 @@ $AzPSReportContent = [System.Text.StringBuilder]::new()
8987[void ]$AzPSReportContent.AppendLine ()
9088
9189$allModules = Get-ChildItem - LiteralPath $debugDirectory - Filter " Az.*" - Directory - Name
92- foreach ($moduleName in $allModules )
93- {
94- if ($moduleName -in $excludedModules )
95- {
90+ foreach ($moduleName in $allModules ) {
91+ Write-Host " ##[group]Start to analyze test coverage for the module '$moduleName '" - ForegroundColor Cyan
92+
93+ if ($moduleName -in $excludedModules ) {
94+ Write-Warning " The module '$moduleName ' has been excluded."
95+ Write-Host " ##[endgroup]" - ForegroundColor Cyan
9696 continue
9797 }
9898
99- Write-Host " ##[group]Calculating test coverage for module $moduleName "
100- Write-Host " ##[section]Start analyzing module $moduleName " - ForegroundColor Green
99+ $hasRawData = $true
101100
102101 $moduleCsvFullPath = Join-Path - Path $testCoverageRawDirectory - ChildPath " $moduleName .csv"
103- if (-not (Test-Path $moduleCsvFullPath ))
104- {
105- [void ]$AzPSReportContent.AppendLine (" Module name: $moduleName has no test raw data found!" )
102+ if (! (Test-Path $moduleCsvFullPath )) {
103+ Write-Warning " The module ' $moduleName ' has no test raw data generated. "
104+ [void ]$AzPSReportContent.AppendLine (" The module ' $moduleName ' has no test raw data file found!" )
106105 [void ]$AzPSReportContent.AppendLine ()
107- continue
106+ $hasRawData = $false
108107 }
109108
110109 [void ]$AzPSReportContent.AppendLine (" Module name: $moduleName " )
@@ -113,28 +112,17 @@ foreach ($moduleName in $allModules)
113112 [void ]$AzPSModuleReportContent.AppendLine (" Test coverage report for module $moduleName :" )
114113 [void ]$AzPSModuleReportContent.AppendLine ()
115114
116- if ($moduleName -ne $accountModuleName )
117- {
115+ if ($moduleName -ne $accountModuleName ) {
118116 $moduleFullPath = Join-Path - Path $debugDirectory - ChildPath $moduleName | Join-Path - ChildPath " $moduleName .psd1"
119117 Import-Module $moduleFullPath
120118 }
121119
122- Write-Host " ##[section]Start calculating cmdlet ..." - ForegroundColor Green
123-
124120 $module = Get-Module - Name $moduleName
125121 $moduleCmdlets = $module.ExportedCmdlets.Keys + $module.ExportedFunctions.Keys
126122
127123 $totalCmdletsCount = $moduleCmdlets.Count
128124 $overallCmdletsCount += $totalCmdletsCount
129125
130- $rawCsv = Import-Csv - LiteralPath $moduleCsvFullPath | Select-Object * - Unique
131-
132- $csvGroupByCmdlet = $rawCsv | Select-Object - ExpandProperty CommandName - Unique | Sort-Object CommandName
133- $totalExecutedCmdletsCount = $csvGroupByCmdlet.Count
134- $overallExecutedCmdletsCount += $totalExecutedCmdletsCount
135-
136- Write-Host " ##[section]Start calculating parameter set ..." - ForegroundColor Green
137-
138126 $totalParameterSetsCount = 0
139127 $totalParametersCount = 0
140128 $moduleCmdlets | ForEach-Object {
@@ -143,53 +131,75 @@ foreach ($moduleName in $allModules)
143131
144132 $cmdletParams = $cmdlet.Parameters
145133 $cmdletParams.Keys | ForEach-Object {
146- if ($_ -notin $psCommonParameters )
147- {
134+ if ($_ -notin $psCommonParameters ) {
148135 $totalParametersCount += $cmdletParams [$_ ].ParameterSets.Count
149136 }
150137 }
151138 }
152139
153- $csvGroupByParameterSet = $rawCsv | Select-Object CommandName, ParameterSetName - Unique | Sort-Object CommandName, ParameterSetName | Group-Object CommandName
154- $totalExecutedParameterSetsCount = ($csvGroupByParameterSet | Measure-Object - Property Count - Sum).Sum
140+ if ($hasRawData ) {
141+ $rawCsv = Import-Csv - LiteralPath $moduleCsvFullPath | Select-Object * - Unique
142+
143+ Write-Host " ##[section]Start to calculate cmdlets." - ForegroundColor Green
144+
145+ $csvGroupByCmdlet = $rawCsv | Select-Object - ExpandProperty CommandName - Unique | Sort-Object CommandName
146+ $totalExecutedCmdletsCount = $csvGroupByCmdlet.Count
147+ $overallExecutedCmdletsCount += $totalExecutedCmdletsCount
148+
149+ Write-Host " ##[section]Finished calculating cmdlets." - ForegroundColor Green
150+
151+ Write-Host " ##[section]Start to calculate parameter sets." - ForegroundColor Green
152+
153+ $csvGroupByParameterSet = $rawCsv | Select-Object CommandName, ParameterSetName - Unique | Sort-Object CommandName, ParameterSetName | Group-Object CommandName
154+ $totalExecutedParameterSetsCount = ($csvGroupByParameterSet | Measure-Object - Property Count - Sum).Sum
155155
156- [void ]$AzPSModuleReportContent.AppendLine (" Following cmdlets were executed :" )
157- $csvGroupByParameterSet | ForEach-Object {
158- $_.Group | ForEach-Object {
159- [void ]$AzPSModuleReportContent.AppendLine (" --> Cmdlet $ ( $_.CommandName ) with parameter set $ ( $_.ParameterSetName ) was tested" )
156+ [void ]$AzPSModuleReportContent.AppendLine (" Following cmdlets were executed :" )
157+ $csvGroupByParameterSet | ForEach-Object {
158+ $_.Group | ForEach-Object {
159+ [void ]$AzPSModuleReportContent.AppendLine (" --> Cmdlet $ ( $_.CommandName ) with parameter set $ ( $_.ParameterSetName ) was tested" )
160+ }
160161 }
161- }
162162
163- [void ]$AzPSModuleReportContent.AppendLine ()
163+ [void ]$AzPSModuleReportContent.AppendLine ()
164164
165- [void ]$AzPSModuleReportContent.AppendLine (" Following cmdlets were not executed :" )
166- $moduleCmdlets | Where-Object { $_ -notin $csvGroupByCmdlet } | ForEach-Object {
167- [void ]$AzPSModuleReportContent.AppendLine (" --> $_ " )
168- }
165+ [void ]$AzPSModuleReportContent.AppendLine (" Following cmdlets were not executed :" )
166+ $moduleCmdlets | Where-Object { $_ -notin $csvGroupByCmdlet } | ForEach-Object {
167+ [void ]$AzPSModuleReportContent.AppendLine (" --> $_ " )
168+ }
169+
170+ Write-Host " ##[section]Finished calculating parameter sets." - ForegroundColor Green
169171
170- Write-Host " ##[section]Start calculating parameter .. ." - ForegroundColor Green
172+ Write-Host " ##[section]Start to calculate parameters ." - ForegroundColor Green
171173
172- $csvGroupByParameter = $rawCsv | Select-Object CommandName, ParameterSetName, Parameters - Unique | Sort-Object CommandName, ParameterSetName, Parameters | Group-Object CommandName, ParameterSetName
173- $totalExecutedParametersCount = 0
174- $csvGroupByParameter | ForEach-Object {
175- $executedParams = @ ()
176- $_.Group | ForEach-Object {
177- $executedParams += $_.Parameters -split " \*\*\*\s*"
174+ $csvGroupByParameter = $rawCsv | Select-Object CommandName, ParameterSetName, Parameters - Unique | Sort-Object CommandName, ParameterSetName, Parameters | Group-Object CommandName, ParameterSetName
175+ $totalExecutedParametersCount = 0
176+ $csvGroupByParameter | ForEach-Object {
177+ $executedParams = @ ()
178+ $_.Group | ForEach-Object {
179+ $executedParams += $_.Parameters -split " \*\*\*\s*"
180+ }
181+ $totalExecutedParametersCount += ($executedParams | Where-Object { $_ -and $_ -notin $psCommonParameters } | Select-Object - Unique).Count
178182 }
179- $totalExecutedParametersCount += ($executedParams | Where-Object { $_ -and $_ -notin $psCommonParameters } | Select-Object - Unique).Count
180- }
181183
182- $AzPSModuleReportContent.ToString () | Out-File - LiteralPath ([System.IO.Path ]::Combine($testCoverageResultsDirectory , " $moduleName .txt" )) - NoNewLine
184+ Write-Host " ##[section]Finished calculating parameters." - ForegroundColor Green
185+
186+ $AzPSModuleReportContent.ToString () | Out-File - LiteralPath ([System.IO.Path ]::Combine($testCoverageResultsDirectory , " $moduleName .txt" )) - NoNewline
183187
184- [void ]$AzPSReportContent.AppendLine (" --> By cmdlet: $ ( ($totalExecutedCmdletsCount / $totalCmdletsCount ).ToString(" P0" )) " )
185- [void ]$AzPSReportContent.AppendLine (" --> By parameter set: $ ( ($totalExecutedParameterSetsCount / $totalParameterSetsCount ).ToString(" P0" )) " )
186- [void ]$AzPSReportContent.AppendLine (" --> By parameter: $ ( ($totalExecutedParametersCount / $totalParametersCount ).ToString(" P0" )) " )
187- [void ]$AzPSReportContent.AppendLine ()
188+ [void ]$AzPSReportContent.AppendLine (" --> By cmdlet: $ ( ($totalExecutedCmdletsCount / $totalCmdletsCount ).ToString(" P0" )) " )
189+ [void ]$AzPSReportContent.AppendLine (" --> By parameter set: $ ( ($totalExecutedParameterSetsCount / $totalParameterSetsCount ).ToString(" P0" )) " )
190+ [void ]$AzPSReportContent.AppendLine (" --> By parameter: $ ( ($totalExecutedParametersCount / $totalParametersCount ).ToString(" P0" )) " )
191+ [void ]$AzPSReportContent.AppendLine ()
192+ }
188193
189- Write-Host " ##[section]Finished analyzing module $moduleName " - ForegroundColor Green
190- Write-Host " ##[endgroup]"
194+ Write-Host " ##[section]Successfully analyzed module ' $moduleName '. " - ForegroundColor Green
195+ Write-Host " ##[endgroup]" - ForegroundColor Cyan
191196 Write-Host
192197}
193198
199+ Write-Host " Total tested cmdlets count: $overallExecutedCmdletsCount " - ForegroundColor Cyan
200+ Write-Host " Total cmdlets count: $overallCmdletsCount " - ForegroundColor Cyan
201+
202+ [void ]$AzPSReportContent.AppendLine (" Total tested cmdlets count: $overallExecutedCmdletsCount " )
203+ [void ]$AzPSReportContent.AppendLine (" Total cmdlets count: $overallCmdletsCount " )
194204[void ]$AzPSReportContent.AppendLine (" Total Azure PowerShell cmdlets coverage: $ ( ($overallExecutedCmdletsCount / $overallCmdletsCount ).ToString(" P0" )) " )
195- $AzPSReportContent.ToString () | Out-File - LiteralPath ([System.IO.Path ]::Combine($testCoverageResultsDirectory , " Azure PowerShell Test Coverage Report.txt" )) - NoNewLine
205+ $AzPSReportContent.ToString () | Out-File - LiteralPath ([System.IO.Path ]::Combine($testCoverageResultsDirectory , " Azure PowerShell Test Coverage Report.txt" )) - NoNewline
0 commit comments