forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpSystem.Tests.ps1
More file actions
203 lines (168 loc) · 7.2 KB
/
HelpSystem.Tests.ps1
File metadata and controls
203 lines (168 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#
# Validates Get-Help for cmdlets in Microsoft.PowerShell.Core.
function UpdateHelpFromLocalContentPath
{
param ([string]$ModuleName, [string]$Tag = 'CI')
if ($Tag -eq 'CI')
{
$helpContentPath = Join-Path $PSScriptRoot "assets"
$helpFiles = @(Get-ChildItem "$helpContentPath\*" -ea SilentlyContinue)
if ($helpFiles.Count -eq 0)
{
throw "Unable to find help content at '$helpContentPath'"
}
Update-Help -Module $ModuleName -SourcePath $helpContentPath -Force -ErrorAction Stop
}
else
{
Update-Help -Module $ModuleName -Force -ErrorAction Stop
}
}
function RunTestCase
{
param ([string]$tag = "CI")
$moduleName = "Microsoft.PowerShell.Core"
UpdateHelpFromLocalContentPath $moduleName $tag
$cmdlets = get-command -module $moduleName
$cmdletsToSkip = @(
"Get-PSHostProcessInfo",
"Out-Default",
"Register-ArgumentCompleter",
"New-PSRoleCapabilityFile",
"Get-PSSessionCapability"
)
foreach ($cmdletName in $cmdlets)
{
if ($cmdletsToSkip -notcontains $cmdletName)
{
It "Validate -Description and -Examples sections in help content. Run 'Get-help -name $cmdletName'" {
$help = get-help -name $cmdletName
$help.Description | Out-String | Should Match $cmdletName
$help.Examples | Out-String | Should Match $cmdletName
}
if ($tag -eq "CI")
{
# For a CI test run, we are only interested in validating one cmdlet to ensure that
# get-help <cmdletName> works.
break
}
}
}
}
Describe "Validate that <pshome>/<culture>/default.help.txt is present" -Tags @('CI') {
It "Get-Help returns information about the help system." {
$help = Get-Help
$help.Name | Should Be "default"
$help.Category | Should Be "HelpFile"
$help.Synopsis | Should Match "SHORT DESCRIPTION"
}
}
Describe "Validate that get-help <cmdletName> works" -Tags @('CI', 'RequireAdminOnWindows') {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
RunTestCase -tag "CI"
}
Describe "Validate Get-Help for all cmdlets in 'Microsoft.PowerShell.Core'" -Tags @('Feature', 'RequireAdminOnWindows') {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
RunTestCase -tag "Feature"
}
Describe "Validate that Get-Help returns provider-specific help" -Tags @('CI', 'RequireAdminOnWindows') {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
$namespaces = @{
command = 'http://schemas.microsoft.com/maml/dev/command/2004/10'
dev = 'http://schemas.microsoft.com/maml/dev/2004/10'
maml = 'http://schemas.microsoft.com/maml/2004/10'
msh = 'http://msh'
}
# Currently these test cases are verified only on Windows, because
# - WSMan:\ and Cert:\ providers are not yet supported on non-Windows platforms.
$testCases = @(
@{
helpFile = "$PSHOME\$([Globalization.CultureInfo]::CurrentUICulture)\System.Management.Automation.dll-help.xml"
path = "$PSHOME"
helpContext = "[@id='FileSystem' or @ID='FileSystem']"
verb = 'Add'
noun = 'Content'
pending = !$IsWindows
}
)
if ($IsWindows)
{
$testCases += @(
@{
helpFile = "$PSHOME\$([Globalization.CultureInfo]::CurrentUICulture)\Microsoft.WSMan.Management.dll-help.xml"
path = 'WSMan:\localhost\ClientCertificate'
helpContext = "[@id='ClientCertificate' or @ID='ClientCertificate']"
verb = 'New'
noun = 'Item'
pending = $false
}
,
@{
helpFile = "$PSHOME\$([Globalization.CultureInfo]::CurrentUICulture)\Microsoft.PowerShell.Security.dll-help.xml"
path = 'Cert:\'
helpContext = $null # CertificateProvider uses only verb and noun in XPath query
verb = 'New'
noun = 'Item'
pending = $false
}
)
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.WSMan.Management' -Tag 'CI'
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Security' -Tag 'CI'
}
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Tag 'CI'
}
AfterAll {
$ProgressPreference = $SavedProgressPreference
}
foreach ($helptest in $testCases)
{
$helpFile = $helptest.helpFile
$path = $helptest.path
$helpContext = $helptest.helpContext
$verb = $helptest.verb
$noun = $helptest.noun
$pending = $helptest.pending
It -Pending:$pending "Shows contextual help when Get-Help is invoked for provider-specific path (Get-Help -Name $verb-$noun -Path $path)" {
# Path should exist or else Get-Help will fallback to default help text
$path | Should Exist
$xpath = "/msh:helpItems/msh:providerHelp/msh:CmdletHelpPaths/msh:CmdletHelpPath$helpContext/command:command/command:details[command:verb='$verb' and command:noun='$noun']"
$helpXmlNode = Select-Xml -Path $helpFile -XPath $xpath -Namespace $namespaces | Select-Object -ExpandProperty Node
# Synopsis comes from command:command/command:details/maml:description
$expected = Get-Help -Name "$verb-$noun" -Path $path | Select-Object -ExpandProperty Synopsis
# System.Management.Automation.ProviderContext.GetProviderSpecificHelpInfo ignores extra whitespace, line breaks and
# comments when loading help XML, but Select-Xml can not; use BeLikeExactly operator to omit trailing line breaks:
$helpXmlNode.description.para -clike "$expected*" | Should Be $true
}
}
}
Describe "Validate about_help.txt under culture specific folder works" -Tags @('CI') {
BeforeAll {
$modulePath = "$pshome\Modules\Test"
$null = New-Item -Path $modulePath\en-US -ItemType Directory -Force
New-ModuleManifest -Path $modulePath\test.psd1 -RootModule test.psm1
Set-Content -Path $modulePath\test.psm1 -Value "function foo{}"
Set-Content -Path $modulePath\en-US\about_testhelp.help.txt -Value "Hello" -NoNewline
}
AfterAll {
Remove-Item $modulePath -Recurse -Force
}
It "Get-Help should return help text and not multiple HelpInfo objects when help is under `$pshome path" {
$help = Get-Help about_testhelp
$help.count | Should Be 1
$help | Should BeExactly "Hello"
}
}