@@ -47,35 +47,33 @@ $excludedModules = @(
47
47
" Az.Elastic" ,
48
48
" Az.HanaOnAzure" ,
49
49
" Az.HealthBot" ,
50
- " Az.ImportExport" ,
51
50
" Az.LabServices" ,
52
51
" Az.Logz" ,
53
52
" Az.ManagedServices" ,
54
53
" Az.Maps" ,
55
54
" Az.MariaDb" ,
56
55
" Az.Marketplace" ,
57
56
" Az.MonitoringSolutions" ,
58
- " Az.MySql" ,
59
57
" Az.Portal" ,
60
58
" Az.PostgreSql" ,
61
59
" Az.ProviderHub" ,
62
60
" Az.Purview" ,
63
61
" Az.Quota" ,
64
62
" Az.ResourceGraph" ,
65
63
" Az.ResourceMover" ,
66
- " Az.SignalR" ,
67
64
" Az.StreamAnalytics" ,
68
65
" Az.Synapse" ,
69
66
" Az.TimeSeriesInsights" ,
70
67
" Az.Websites" ,
71
68
" Az.WindowsIotServices"
72
69
)
73
70
74
- if (-not (Test-Path - LiteralPath $testCoverageResultsDirectory - PathType Container))
75
- {
71
+ if (! (Test-Path - LiteralPath $testCoverageResultsDirectory - PathType Container)) {
76
72
New-Item - Path $testCoverageRootDirectory - Name " Results" - ItemType Directory
77
73
}
78
- Get-ChildItem - LiteralPath $testCoverageResultsDirectory - Filter " *.txt" | Remove-Item - Force
74
+ else {
75
+ Get-ChildItem - LiteralPath $testCoverageResultsDirectory - Filter " *.txt" | Remove-Item - Force
76
+ }
79
77
80
78
$accountModuleName = " Az.Accounts"
81
79
$accountModuleFullPath = Join-Path - Path $debugDirectory - ChildPath $accountModuleName | Join-Path - ChildPath " $accountModuleName .psd1"
@@ -89,22 +87,23 @@ $AzPSReportContent = [System.Text.StringBuilder]::new()
89
87
[void ]$AzPSReportContent.AppendLine ()
90
88
91
89
$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
96
96
continue
97
97
}
98
98
99
- Write-Host " ##[group]Calculating test coverage for module $moduleName "
100
- Write-Host " ##[section]Start analyzing module $moduleName " - ForegroundColor Green
99
+ $hasRawData = $true
101
100
102
101
$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!" )
106
105
[void ]$AzPSReportContent.AppendLine ()
107
- continue
106
+ $hasRawData = $false
108
107
}
109
108
110
109
[void ]$AzPSReportContent.AppendLine (" Module name: $moduleName " )
@@ -113,28 +112,17 @@ foreach ($moduleName in $allModules)
113
112
[void ]$AzPSModuleReportContent.AppendLine (" Test coverage report for module $moduleName :" )
114
113
[void ]$AzPSModuleReportContent.AppendLine ()
115
114
116
- if ($moduleName -ne $accountModuleName )
117
- {
115
+ if ($moduleName -ne $accountModuleName ) {
118
116
$moduleFullPath = Join-Path - Path $debugDirectory - ChildPath $moduleName | Join-Path - ChildPath " $moduleName .psd1"
119
117
Import-Module $moduleFullPath
120
118
}
121
119
122
- Write-Host " ##[section]Start calculating cmdlet ..." - ForegroundColor Green
123
-
124
120
$module = Get-Module - Name $moduleName
125
121
$moduleCmdlets = $module.ExportedCmdlets.Keys + $module.ExportedFunctions.Keys
126
122
127
123
$totalCmdletsCount = $moduleCmdlets.Count
128
124
$overallCmdletsCount += $totalCmdletsCount
129
125
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
-
138
126
$totalParameterSetsCount = 0
139
127
$totalParametersCount = 0
140
128
$moduleCmdlets | ForEach-Object {
@@ -143,53 +131,75 @@ foreach ($moduleName in $allModules)
143
131
144
132
$cmdletParams = $cmdlet.Parameters
145
133
$cmdletParams.Keys | ForEach-Object {
146
- if ($_ -notin $psCommonParameters )
147
- {
134
+ if ($_ -notin $psCommonParameters ) {
148
135
$totalParametersCount += $cmdletParams [$_ ].ParameterSets.Count
149
136
}
150
137
}
151
138
}
152
139
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
155
155
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
+ }
160
161
}
161
- }
162
162
163
- [void ]$AzPSModuleReportContent.AppendLine ()
163
+ [void ]$AzPSModuleReportContent.AppendLine ()
164
164
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
169
171
170
- Write-Host " ##[section]Start calculating parameter .. ." - ForegroundColor Green
172
+ Write-Host " ##[section]Start to calculate parameters ." - ForegroundColor Green
171
173
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
178
182
}
179
- $totalExecutedParametersCount += ($executedParams | Where-Object { $_ -and $_ -notin $psCommonParameters } | Select-Object - Unique).Count
180
- }
181
183
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
183
187
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
+ }
188
193
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
191
196
Write-Host
192
197
}
193
198
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 " )
194
204
[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