mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
* Stifle progress output in build.psm1 for some operations
Modify test failure presentation to use platform available XML methods
* Add timeout support for returning runtime parsing errors
Some of the language/parser tests have been hanging in a non-reproducable manner which
causes the CI system to invalidate the entire run. This change adds support for timeout
which will fail a test if it runs to long, rather than invalidate the entire run.
current behavior is still supported, and is not done in a new session:
PS> get-runtimeerror -src '1/'
At line:1 char:3
+ 1/
+ ~
You must provide a value expression following the '/' operator.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression
Adding a timeout will do the operation in a async powershell session
PS> get-runtimeerror -src '1/' -timeout 5
You must provide a value expression following the '/' operator.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression
If the operation takes longer than the supplied timeout, a timeout error will be returned
PS> get-runtimeerror -src 'start-sleep 6' -timeout 2
get-runtimeerror : Operation Timed Out ('start-sleep 6')
At line:1 char:1
+ get-runtimeerror -src 'start-sleep 6' -timeout 2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-RuntimeError
* Modify native linux command tests to skip on Windows and pending on Mac
* remove verbose and progress output from help tests
* Be sure that Feature Counter tests only run on Windows
Also, only call add-type in CounterTestHelperFunctions.ps1 if we're going to actually run the tests
* do not run any get-computerinfo tests on non-windows systems
* suppress progress output from PowerShell Get tests
* remove -quiet from API and CRON Builds
Travis watches output from the build to ensure that it hasn't hung
we need to find a balance between too much output and not enough output.
A run which has too much output is killed because it looks like an error loop
A run which has too little output is killed because it looks like a hang
* Remove commented line in Import-Counter.Tests.ps1
Remove extraneous extra line in PowerShellGet.Tests.ps1
* Change `-as "type"` to `-as [type]` in build.psm1
Alter timeout to 10 seconds to be improve chances of not timing out for runtime parser checks
improve logic for counter tests to also skip for IoT
* use the existing function of SkipCounterTests rather than duplicate the logic in import-counter.tests.ps1
172 lines
6.1 KiB
PowerShell
172 lines
6.1 KiB
PowerShell
#
|
|
# 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 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
|
|
}
|
|
}
|
|
}
|