Allow partial culture matching in Update-Help (#18037)

This commit is contained in:
Dominik Kaszewski
2023-05-09 09:46:59 -07:00
committed by GitHub
parent 7888196b87
commit 270f8f1be7
5 changed files with 108 additions and 33 deletions
@@ -30,7 +30,7 @@ function UpdateHelpFromLocalContentPath {
throw "Unable to find help content at '$helpContentPath'"
}
# Test files are 'en-US', set explicit culture so test does not help on non-US systems
# Test files are 'en-US', set explicit culture so test does not fail on non-US systems
Update-Help -Module $ModuleName -SourcePath $helpContentPath -UICulture 'en-US' -Force -ErrorAction Stop -Scope $Scope
}
@@ -635,3 +635,54 @@ Describe 'help renders when using a PAGER with a space in the path' -Tags 'CI' {
help Get-Command | Should -Be "R2V0LUNvbW1hbmQ="
}
}
Describe 'Update-Help allows partial culture matches' -Tags 'CI' {
BeforeAll {
function Test-UpdateHelpAux($UICulture, $Pass)
{
# If null (in system culture tests), omit entirely
$CultureArg = $UICulture ? @{ UICulture = $UICulture } : @{}
$Args = @{
Module = 'Microsoft.PowerShell.Core'
SourcePath = Join-Path $PSScriptRoot 'assets'
Force = $true
ErrorAction = $Pass ? 'Stop' : 'SilentlyContinue'
ErrorVariable = 'ErrorVariable'
}
Update-Help @Args @CultureArg
if (-not $Pass) {
$ErrorVariable | Should -Match 'Failed to update Help for the module.*'
}
}
}
AfterEach {
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('CurrentUICulture', $null)
}
It 'Checks culture match against en-US: <UICulture>' -TestCases @(
@{ UICulture = 'en-US' }
@{ UICulture = 'en' }
@{ UICulture = 'en-GB'; Pass = $false }
@{ UICulture = 'de-DE'; Pass = $false }
) {
param($UICulture, $Pass = $true)
Test-UpdateHelpAux $UICulture $Pass
}
# When using system culture, "en-GB" will use "en" as fallback, so passes
It 'Checks system culture match against en-US: <UICulture>' -TestCases @(
@{ UICulture = 'en-US' }
@{ UICulture = 'en' }
@{ UICulture = 'en-GB' }
@{ UICulture = 'de-DE'; Pass = $false }
) {
param($UICulture, $Pass = $true)
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('CurrentUICulture', [System.Globalization.CultureInfo]::new($UICulture))
Test-UpdateHelpAux $null $Pass
}
}