-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Update-Help test updates #6093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update-Help test updates #6093
Changes from all commits
a31b1c9
979af9e
bef2ee4
28cb469
e51a32a
bc3238e
6c10641
5cd8bfd
75826f8
417310c
82e35f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,18 @@ function UpdateHelpFromLocalContentPath | |
| { | ||
| param ([string]$ModuleName, [string]$Tag = 'CI') | ||
|
|
||
| # Update-Help fails if module path is Not writable, so skip tests in this situation | ||
| if ($moduleName -eq "Microsoft.PowerShell.Core") | ||
| { | ||
| if ($MicrosoftPowerShellCorePathIsReadOnly) { return } | ||
| } | ||
| else | ||
| { | ||
| $modulePath = (Get-Module -Name $ModuleName -ListAvailable).ModuleBase | ||
| $modulePathIsReadOnly = PathIsReadOnly $modulePath | ||
| if ($modulePathIsReadOnly) { return } | ||
| } | ||
|
|
||
| if ($Tag -eq 'CI') | ||
| { | ||
| $helpContentPath = Join-Path $PSScriptRoot "assets" | ||
|
|
@@ -47,7 +59,7 @@ function RunTestCase | |
| { | ||
| if ($cmdletsToSkip -notcontains $cmdletName) | ||
| { | ||
| It "Validate -Description and -Examples sections in help content. Run 'Get-help -name $cmdletName'" { | ||
| It "Validate -Description and -Examples sections in help content. Run 'Get-help -name $cmdletName'" -Skip:$MicrosoftPowerShellCorePathIsReadOnly { | ||
|
|
||
| $help = get-help -name $cmdletName | ||
| $help.Description | Out-String | Should Match $cmdletName | ||
|
|
@@ -64,6 +76,28 @@ function RunTestCase | |
| } | ||
| } | ||
|
|
||
| function PathIsReadOnly | ||
| { | ||
| param ([string]$Path) | ||
| # attempt to write to location and catch | ||
| $readonly = $false | ||
| try | ||
| { | ||
| $filepath = Join-Path $Path "testfile-deleteme.txt" | ||
| "test" | Out-File $filepath | ||
| } | ||
| catch | ||
| { | ||
| $readonly = $_.Exception.GetType().Name -eq 'UnauthorizedAccessException' | ||
| } | ||
| Remove-Item -Path $filepath -ErrorAction SilentlyContinue | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||
|
|
||
| $readonly | ||
| } | ||
|
|
||
| $PsHomePathIsReadOnly = PathIsReadOnly $PSHOME | ||
| $MicrosoftPowerShellCorePathIsReadOnly = $PsHomePathIsReadOnly | ||
|
|
||
| Describe "Validate that <pshome>/<culture>/default.help.txt is present" -Tags @('CI') { | ||
|
|
||
| It "Get-Help returns information about the help system." { | ||
|
|
@@ -184,9 +218,19 @@ Describe "Validate that Get-Help returns provider-specific help" -Tags @('CI', ' | |
| } | ||
|
|
||
| Describe "Validate about_help.txt under culture specific folder works" -Tags @('CI', 'RequireAdminOnWindows') { | ||
|
|
||
| BeforeAll { | ||
| $modulePath = "$pshome\Modules\Test" | ||
| $null = New-Item -Path $modulePath\en-US -ItemType Directory -Force | ||
| try | ||
| { | ||
| $null = New-Item -Path $modulePath\en-US -ItemType Directory -Force -ErrorAction Stop | ||
| } | ||
| catch | ||
| { | ||
| # $pshome is readonly-path for non-sudo on Linux, skip tests in this case | ||
| $skip = $_.Exception.GetType().Name -eq 'UnauthorizedAccessException' | ||
| if ($skip) {return} | ||
| } | ||
| 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 | ||
|
|
@@ -201,26 +245,26 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @(' | |
| } | ||
|
|
||
| AfterAll { | ||
| Remove-Item $modulePath -Recurse -Force | ||
| Remove-Item $modulePath -Recurse -Force -ErrorAction SilentlyContinue | ||
| # Remove all the help content. | ||
| Get-ChildItem -Path $PSHOME -Include @('about_*.txt', "*help.xml") -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue | ||
| } | ||
|
|
||
| It "Get-Help should return help text and not multiple HelpInfo objects when help is under `$pshome path" { | ||
| It "Get-Help should return help text and not multiple HelpInfo objects when help is under `$pshome path" -Skip:$skip { | ||
|
|
||
| $help = Get-Help about_testhelp | ||
| $help.count | Should Be 1 | ||
| $help | Should BeExactly "Hello" | ||
| } | ||
|
|
||
| It "Get-Help for about_Variable should return only one help object" { | ||
| It "Get-Help for about_Variable should return only one help object" -Skip:$skip { | ||
| $help = Get-Help about_Variables | ||
| $help.count | Should Be 1 | ||
| } | ||
| } | ||
|
|
||
| Describe "Get-Help should find help info within help files" -Tags @('CI', 'RequireAdminOnWindows') { | ||
| It "Get-Help should find help files under pshome" { | ||
| It "Get-Help should find help files under pshome" -Skip:$PsHomePathIsReadOnly { | ||
| $helpFile = "about_testCase.help.txt" | ||
| $culture = (Get-Culture).Name | ||
| $helpFolderPath = Join-Path $PSHOME $culture | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,6 +133,27 @@ $testCases = @{ | |
| $modulesInBox = @("Microsoft.PowerShell.Core" | ||
| Get-Module -ListAvailable | ForEach-Object{$_.Name} | ||
| ) | ||
| function PathIsReadOnly | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this function to a common file and then dot source it in both the test files. |
||
| { | ||
| param ([string]$Path) | ||
| # attempt to write to location and catch | ||
| $readonly = $false | ||
| try | ||
| { | ||
| $filepath = Join-Path $Path "testfile-deleteme.txt" | ||
| "test" | Out-File $filepath | ||
| } | ||
| catch | ||
| { | ||
| $readonly = $_.Exception.GetType().Name -eq 'UnauthorizedAccessException' | ||
| } | ||
| Remove-Item -Path $filepath -ErrorAction SilentlyContinue | ||
|
|
||
| $readonly | ||
| } | ||
|
|
||
| $PsHomePathIsReadOnly = PathIsReadOnly $PSHOME | ||
| $MicrosoftPowerShellCorePathIsReadOnly = $PsHomePathIsReadOnly | ||
|
|
||
| function GetFiles | ||
| { | ||
|
|
@@ -174,8 +195,20 @@ function RunUpdateHelpTests | |
| { | ||
| if ($powershellCoreModules -contains $moduleName) | ||
| { | ||
| if ($moduleName -eq "Microsoft.PowerShell.Core") | ||
| { | ||
| $skip = $MicrosoftPowerShellCorePathIsReadOnly | ||
| } | ||
| else | ||
| { | ||
| $modulePath = (Get-Module -Name $moduleName -ListAvailable).ModuleBase | ||
| $skip = PathIsReadOnly $modulePath | ||
| } | ||
|
|
||
| # -Skip and -$Pending are mutually exclusive on It block, so skip Pending tests | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skip and Pending have specific meanings. you can use splatting to choose one of them for the It block. |
||
| If ($Pending) {$skip = $true} | ||
|
|
||
| It "Validate Update-Help for module '$moduleName'" -Pending:$Pending { | ||
| It "Validate Update-Help for module '$moduleName'" -Skip:$skip { | ||
|
|
||
| # If the help file is already installed, delete it. | ||
| Get-ChildItem $testCases[$moduleName].HelpInstallationPath -Include @("*help.xml") -Recurse -ea SilentlyContinue | | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the path can be read only if we run the tests with 'RequireAdminOnWindows' tag? Do you means Unix where we haven't still such tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we do not run the tests under sudo on Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should not complicate these tests if we want to implement #5645?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we need to go through a bunch to tests when #5645 is done. We can revert these changes then.