11# Taken with love from @juneb_get_help (https://raw.githubusercontent.com/juneb/PesterTDD/master/Module.Help.Tests.ps1)
22
33BeforeDiscovery {
4+
45 function global :FilterOutCommonParams {
56 param ($Params )
6- $commonParams = [System.Management.Automation.PSCmdlet ]::OptionalCommonParameters +
7- [System.Management.Automation.PSCmdlet ]::CommonParameters
8- $params | Where-Object { $_.Name -notin $commonParams } | Sort-Object - Property Name - Unique
7+ $commonParameters = [System.Management.Automation.PSCmdlet ]::CommonParameters + [System.Management.Automation.PSCmdlet ]::OptionalCommonParameters
8+ $params | Where-Object { $_.Name -notin $commonParameters } | Sort-Object - Property Name - Unique
99 }
1010
11- $manifest = Import-PowerShellDataFile - Path $env: BHPSModuleManifest
12- $outputDir = Join-Path - Path $env: BHProjectPath - ChildPath ' Output'
13- $outputModDir = Join-Path - Path $outputDir - ChildPath $env: BHProjectName
14- $outputModVerDir = Join-Path - Path $outputModDir - ChildPath $manifest.ModuleVersion
11+ $manifest = Import-PowerShellDataFile - Path $env: BHPSModuleManifest
12+ $outputDir = Join-Path - Path $env: BHProjectPath - ChildPath ' Output'
13+ $outputModDir = Join-Path - Path $outputDir - ChildPath $env: BHProjectName
14+ $outputModVerDir = Join-Path - Path $outputModDir - ChildPath $manifest.ModuleVersion
1515 $outputModVerManifest = Join-Path - Path $outputModVerDir - ChildPath " $ ( $env: BHProjectName ) .psd1"
1616
1717 # Get module commands
@@ -25,36 +25,32 @@ BeforeDiscovery {
2525 if ($PSVersionTable.PSVersion.Major -lt 6 ) {
2626 $params.CommandType [0 ] += ' Workflow'
2727 }
28- $commands = Get-Command @params
28+ $script : commands = Get-Command @params
2929
3030 # # When testing help, remember that help is cached at the beginning of each session.
3131 # # To test, restart session.
3232}
3333
34- AfterAll {
35- Remove-Item Function:/ FilterOutCommonParams
36- }
37-
3834Describe " Test help for <_.Name>" - ForEach $commands {
3935
4036 BeforeDiscovery {
4137 # Get command help, parameters, and links
42- $command = $_
43- $commandHelp = Get-Help $command.Name - ErrorAction SilentlyContinue
44- $commandParameters = global:FilterOutCommonParams - Params $command.ParameterSets.Parameters
45- $commandParameterNames = $commandParameters.Name
46- $helpLinks = $commandHelp.relatedLinks.navigationLink.uri
38+ $command = $_
39+ $commandHelp = Get-Help $command.Name - ErrorAction SilentlyContinue
40+ $commandParameters = global:FilterOutCommonParams - Params $command.ParameterSets.Parameters
41+ $script : commandParameterNames = $commandParameters.Name
42+ $script : helpLinks = $commandHelp.relatedLinks.navigationLink.uri
4743 }
4844
4945 BeforeAll {
5046 # These vars are needed in both discovery and test phases so we need to duplicate them here
51- $command = $_
52- $commandName = $_.Name
53- $commandHelp = Get-Help $command.Name - ErrorAction SilentlyContinue
54- $commandParameters = global:FilterOutCommonParams - Params $command.ParameterSets.Parameters
55- $commandParameterNames = $commandParameters.Name
56- $helpParameters = global:FilterOutCommonParams - Params $commandHelp.Parameters.Parameter
57- $helpParameterNames = $helpParameters.Name
47+ $command = $_
48+ $script : commandName = $_.Name
49+ $commandHelp = Get-Help $command.Name - ErrorAction SilentlyContinue
50+ $commandParameters = global:FilterOutCommonParams - Params $command.ParameterSets.Parameters
51+ $script : commandParameterNames = $commandParameters.Name
52+ $helpParameters = global:FilterOutCommonParams - Params $commandHelp.Parameters.Parameter
53+ $script : helpParameterNames = $helpParameters.Name
5854 }
5955
6056 # If help is not found, synopsis in auto-generated help is the syntax diagram
@@ -81,13 +77,13 @@ Describe "Test help for <_.Name>" -ForEach $commands {
8177 (Invoke-WebRequest - Uri $_ - UseBasicParsing).StatusCode | Should - Be ' 200'
8278 }
8379
84- Context " Parameter <_.Name>" - Foreach $commandParameters {
80+ Context " Parameter <_.Name>" - ForEach $commandParameters {
8581
8682 BeforeAll {
87- $parameter = $_
88- $parameterName = $parameter.Name
89- $parameterHelp = $commandHelp.parameters.parameter | Where-Object Name -eq $parameterName
90- $parameterHelpType = if ($parameterHelp.ParameterValue ) { $parameterHelp.ParameterValue.Trim () }
83+ $parameter = $_
84+ $parameterName = $parameter.Name
85+ $parameterHelp = $commandHelp.parameters.parameter | Where-Object Name -EQ $parameterName
86+ $script : parameterHelpType = if ($parameterHelp.ParameterValue ) { $parameterHelp.ParameterValue.Trim () }
9187 }
9288
9389 # Should be a description for every parameter
@@ -107,7 +103,7 @@ Describe "Test help for <_.Name>" -ForEach $commands {
107103 }
108104 }
109105
110- Context " Test <_> help parameter help for <commandName>" - Foreach $helpParameterNames {
106+ Context " Test <_> help parameter help for <commandName>" - ForEach $helpParameterNames {
111107
112108 # Shouldn't find extra parameters in help.
113109 It " finds help parameter in code: <_>" {
0 commit comments