Skip to content

Commit 46e89de

Browse files
authored
fix #1417 modulehelp false positives (#1418)
* fix modulehelp false positives When looking up module version, if the module is not installed, also check if it is loaded and get module version from loaded module Add 'AttachAndDebug' to paramBlackList, so it does not throw false positives for DEBUG builds. Small bugfix for the actual blacklist check, the property 'name' of the $parameter variable needs to be used to check against the blacklist. * undo check for loaded module, because $env:psmodulepath is set to .\out\ module during testing, the built module will always appear 'installed'. * simplify command discovery
1 parent 163d2c2 commit 46e89de

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Tests/Engine/ModuleHelp.Tests.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,17 @@ Get-Module $ModuleName | Remove-Module
214214
Import-Module $ModuleName -RequiredVersion $RequiredVersion -ErrorAction Stop
215215
$ms = $null
216216
$commands =$null
217-
$paramBlackList = @()
217+
$paramBlackList = @(
218+
'AttachAndDebug' # Reason: When building with DEGUG configuration, an additional parameter 'AttachAndDebug' will be added to Invoke-ScriptAnalyzer and Invoke-Formatter, but there is no Help for those, as they are not intended for production usage.
219+
)
218220
if ($PSVersionTable.PSVersion -lt [Version]'5.0.0') {
219221
$ms = New-Object -TypeName 'Microsoft.PowerShell.Commands.ModuleSpecification' -ArgumentList $ModuleName
220222
$commands = Get-Command -Module $ms.Name
221223
$paramBlackList += 'SaveDscDependency'
222224
}
223225
else {
224226
$ms = [Microsoft.PowerShell.Commands.ModuleSpecification]@{ ModuleName = $ModuleName; RequiredVersion = $RequiredVersion }
225-
$commands = Get-Command -FullyQualifiedModule $ms -CommandType Cmdlet,Function,Workflow # Not alias
227+
$commands = Get-Command -FullyQualifiedModule $ms
226228
}
227229

228230
## When testing help, remember that help is cached at the beginning of each session.
@@ -276,7 +278,7 @@ foreach ($command in $commands) {
276278
$HelpParameterNames = $Help.Parameters.Parameter.Name | Sort-Object -Unique
277279

278280
foreach ($parameter in $parameters) {
279-
if ($parameter -in $paramBlackList) {
281+
if ($parameter.Name -in $paramBlackList) {
280282
continue
281283
}
282284
$parameterName = $parameter.Name

0 commit comments

Comments
 (0)