File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,12 @@ public List<ExternalRule> GetExternalRule(string[] moduleNames)
231231 string script = string . Format ( CultureInfo . CurrentCulture , "Get-Module -Name '{0}' -ListAvailable" , moduleName ) ;
232232 shortModuleName = posh . AddScript ( script ) . Invoke < PSModuleInfo > ( ) . First ( ) . Name ;
233233
234+ // Invokes Update-Help for this module
235+ // Required since when invoking Get-Help later on, the cmdlet prompts for Update-Help interactively
236+ // By invoking Update-Help first, Get-Help will not prompt for downloading help later
237+ script = string . Format ( CultureInfo . CurrentCulture , "Update-Help -Module '{0}' -Force" , shortModuleName ) ;
238+ posh . AddScript ( script ) . Invoke ( ) ;
239+
234240 // Invokes Get-Command and Get-Help for each functions in the module.
235241 script = string . Format ( CultureInfo . CurrentCulture , "Get-Command -Module '{0}'" , shortModuleName ) ;
236242 var psobjects = posh . AddScript ( script ) . Invoke ( ) ;
Original file line number Diff line number Diff line change @@ -22,6 +22,27 @@ Describe "Test importing customized rules with null return results" {
2222}
2323
2424Describe " Test importing correct customized rules" {
25+
26+ Context " Test Get-Help functionality in ScriptRule parsing logic" {
27+ It " ScriptRule help section must be correctly processed when Get-Help is called for the first time" {
28+
29+ # Force Get-Help to prompt for interactive input to download help using Update-Help
30+ # By removing this registry key we force to turn on Get-Help interactivity logic during ScriptRule parsing
31+ $null , " Wow6432Node" | ForEach-Object {
32+ try
33+ {
34+ Remove-ItemProperty - Name " DisablePromptToUpdateHelp" - Path " HKLM:\SOFTWARE\$ ( $_ ) \Microsoft\PowerShell" - ErrorAction Stop
35+ } catch {
36+ # Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
37+ }
38+ }
39+
40+ $customizedRulePath = Invoke-ScriptAnalyzer $directory \TestScript.ps1 - CustomizedRulePath $directory \samplerule\samplerule.psm1 | Where-Object {$_.Message -eq $message }
41+ $customizedRulePath.Count | Should Be 1
42+ }
43+
44+ }
45+
2546 Context " Test Get-ScriptAnalyzer with customized rules" {
2647 It " will show the customized rule" {
2748 $customizedRulePath = Get-ScriptAnalyzerRule - CustomizedRulePath $directory \samplerule\samplerule.psm1 | Where-Object {$_.RuleName -eq $measure }
You can’t perform that action at this time.
0 commit comments