Skip to content

Commit e651a28

Browse files
tablackburnclaude
andauthored
fix(tests): run the param-help check (populate vars in BeforeDiscovery) (#21)
* fix(tests): populate help-parameter vars + commandName in BeforeDiscovery so the param-help check runs Propagates PowerShellModuleTemplate#35. The 'help parameter help' Context used -Foreach $helpParameterNames with the variable set only in BeforeAll (run phase). Pester evaluates -Foreach during DISCOVERY, so the collection was $null then and the Context expanded to ZERO tests -- the 'no stale/extra parameters documented in help' check was a silent no-op. Populate $helpParameters/$helpParameterNames (and $commandName, used in the Context name) in BeforeDiscovery so the check actually runs. Surgical fix on current main; the broader test-scaffolding alignment (this repo's open style/align-test-scaffolding-with-template PR) remains separate. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(tests): use $commandParameterNames in the param-help assertion This repo's older scaffolding had drifted: the param-help Context asserted against $parameterNames, which is never defined (only $commandParameterNames exists). The discovery-phase fix activates that Context, so correct the variable. Surfaced by Copilot on ReScenePS #21. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 838114d commit e651a28

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

tests/Help.tests.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,16 @@ BeforeAll {
143143
Describe "Test help for <_.Name>" -ForEach $commands {
144144

145145
BeforeDiscovery {
146-
# Get command help, parameters, and links
146+
# Get command help, parameters, and links. These are duplicated in BeforeAll
147+
# below; they must also exist here because the nested Context blocks use them in
148+
# -ForEach, which Pester evaluates during discovery (before BeforeAll runs).
147149
$command = $_
150+
$commandName = $command.Name
148151
$commandHelp = Get-Help -Name $command.Name -ErrorAction 'SilentlyContinue'
149152
$commandParameters = global:FilterOutCommonParameters -Parameters $command.ParameterSets.Parameters
150153
$commandParameterNames = $commandParameters.Name
154+
$helpParameters = global:FilterOutCommonParameters -Parameters $commandHelp.Parameters.Parameter
155+
$helpParameterNames = $helpParameters.Name
151156
$helpLinks = $commandHelp.relatedLinks.navigationLink.uri | Where-Object { $_ -match '^https?://' }
152157
}
153158

@@ -233,7 +238,7 @@ Describe "Test help for <_.Name>" -ForEach $commands {
233238

234239
# Shouldn't find extra parameters in help
235240
It 'finds help parameter in code: <_>' {
236-
$_ -in $parameterNames | Should -Be $true
241+
$_ -in $commandParameterNames | Should -Be $true
237242
}
238243
}
239244
}

0 commit comments

Comments
 (0)