Update tests to account for when $PSHOME is readonly (#9279)
Co-Authored-By: SteveL-MSFT <slee@microsoft.com> Co-authored-by: Travis Plunk <travis.plunk@microsoft.com>
This commit is contained in:
parent
4ec36a0d4a
commit
b8317de469
|
@ -1,12 +1,16 @@
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
|
Import-Module HelpersCommon
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
# Skip all tests on non-windows and non-PowerShellCore and non-elevated platforms.
|
# Skip all tests on non-windows and non-PowerShellCore and non-elevated platforms.
|
||||||
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
|
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
|
||||||
$originalWarningPreference = $WarningPreference
|
$originalWarningPreference = $WarningPreference
|
||||||
$WarningPreference = "SilentlyContinue"
|
$WarningPreference = "SilentlyContinue"
|
||||||
$IsNotSkipped = ($IsWindows -and $IsCoreCLR -and (Test-IsElevated))
|
# Skip all tests if can't write to $PSHOME as Register-PSSessionConfiguration writes to $PSHOME
|
||||||
|
$IsNotSkipped = ($IsWindows -and $IsCoreCLR -and (Test-IsElevated) -and (Test-CanWriteToPsHome))
|
||||||
$PSDefaultParameterValues["it:skip"] = !$IsNotSkipped
|
$PSDefaultParameterValues["it:skip"] = !$IsNotSkipped
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
Import-Module HelpersCommon
|
Import-Module HelpersCommon
|
||||||
|
|
||||||
#
|
#
|
||||||
# These are general tests that verify non-Windows behavior
|
# These are general tests that verify non-Windows behavior
|
||||||
#
|
#
|
||||||
|
@ -45,7 +47,7 @@ try {
|
||||||
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
|
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
|
||||||
$IsNotSkipped = ($IsWindows -eq $true);
|
$IsNotSkipped = ($IsWindows -eq $true);
|
||||||
$PSDefaultParameterValues["it:skip"] = !$IsNotSkipped
|
$PSDefaultParameterValues["it:skip"] = !$IsNotSkipped
|
||||||
$ShouldSkipTest = !$IsNotSkipped
|
$ShouldSkipTest = !$IsNotSkipped -or !(Test-CanWriteToPsHome)
|
||||||
|
|
||||||
Describe "Help work with ExecutionPolicy Restricted " -Tags "Feature" {
|
Describe "Help work with ExecutionPolicy Restricted " -Tags "Feature" {
|
||||||
|
|
||||||
|
@ -480,7 +482,9 @@ ZoneId=$FileType
|
||||||
|
|
||||||
foreach($fileInfo in $testFilesInfo)
|
foreach($fileInfo in $testFilesInfo)
|
||||||
{
|
{
|
||||||
createTestFile -FilePath $fileInfo.filePath -FileType $fileInfo.fileType -AddSignature:$fileInfo.AddSignature -Corrupted:$fileInfo.corrupted
|
if ((Test-CanWriteToPsHome) -or (!(Test-CanWriteToPsHome) -and !$fileInfo.filePath.StartsWith($PSHOME, $true, $null)) ) {
|
||||||
|
createTestFile -FilePath $fileInfo.filePath -FileType $fileInfo.fileType -AddSignature:$fileInfo.AddSignature -Corrupted:$fileInfo.corrupted
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Get Execution Policy
|
#Get Execution Policy
|
||||||
|
@ -651,21 +655,27 @@ ZoneId=$FileType
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = "UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand"
|
$error = "UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand"
|
||||||
|
|
||||||
$testData = @(
|
$testData = @(
|
||||||
@{
|
|
||||||
module = $PSHomeUntrustedModule
|
|
||||||
error = $null
|
|
||||||
}
|
|
||||||
@{
|
|
||||||
module = $PSHomeUnsignedModule
|
|
||||||
error = $null
|
|
||||||
}
|
|
||||||
@{
|
@{
|
||||||
module = "Microsoft.PowerShell.Archive"
|
module = "Microsoft.PowerShell.Archive"
|
||||||
error = $null
|
error = $null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (Test-CanWriteToPsHome) {
|
||||||
|
$testData += @(
|
||||||
|
@{
|
||||||
|
module = $PSHomeUntrustedModule
|
||||||
|
error = $null
|
||||||
|
}
|
||||||
|
@{
|
||||||
|
module = $PSHomeUnsignedModule
|
||||||
|
error = $null
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
$TestTypePrefix = "Test 'Unrestricted' execution policy."
|
$TestTypePrefix = "Test 'Unrestricted' execution policy."
|
||||||
It "$TestTypePrefix Importing <module> Module should throw '<error>'" -TestCases $testData {
|
It "$TestTypePrefix Importing <module> Module should throw '<error>'" -TestCases $testData {
|
||||||
param([string]$module, [string]$error)
|
param([string]$module, [string]$error)
|
||||||
|
@ -898,20 +908,25 @@ ZoneId=$FileType
|
||||||
|
|
||||||
$error = "UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand"
|
$error = "UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand"
|
||||||
$testData = @(
|
$testData = @(
|
||||||
@{
|
|
||||||
module = $PSHomeUntrustedModule
|
|
||||||
error = $error
|
|
||||||
}
|
|
||||||
@{
|
|
||||||
module = $PSHomeUnsignedModule
|
|
||||||
error = $error
|
|
||||||
}
|
|
||||||
@{
|
@{
|
||||||
module = "Microsoft.PowerShell.Archive"
|
module = "Microsoft.PowerShell.Archive"
|
||||||
error = $null
|
error = $null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (Test-CanWriteToPsHome) {
|
||||||
|
$testData += @(
|
||||||
|
@{
|
||||||
|
module = $PSHomeUntrustedModule
|
||||||
|
error = $error
|
||||||
|
}
|
||||||
|
@{
|
||||||
|
module = $PSHomeUnsignedModule
|
||||||
|
error = $error
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
It "$TestTypePrefix Importing <module> Module should throw '<error>'" -TestCases $testData {
|
It "$TestTypePrefix Importing <module> Module should throw '<error>'" -TestCases $testData {
|
||||||
param([string]$module, [string]$error)
|
param([string]$module, [string]$error)
|
||||||
$testScript = {Import-Module -Name $module -Force}
|
$testScript = {Import-Module -Name $module -Force}
|
||||||
|
@ -1132,7 +1147,7 @@ ZoneId=$FileType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
It '-Scope LocalMachine is Settable, but overridden' {
|
It '-Scope LocalMachine is Settable, but overridden' -Skip:(!(Test-CanWriteToPsHome)) {
|
||||||
# In this test, we first setup execution policy in the following way:
|
# In this test, we first setup execution policy in the following way:
|
||||||
# CurrentUser is specified and takes precedence over LocalMachine.
|
# CurrentUser is specified and takes precedence over LocalMachine.
|
||||||
# That's why we will get an error, when we are setting up LocalMachine policy.
|
# That's why we will get an error, when we are setting up LocalMachine policy.
|
||||||
|
@ -1154,7 +1169,7 @@ ZoneId=$FileType
|
||||||
Get-ExecutionPolicy -Scope LocalMachine | Should -Be "ByPass"
|
Get-ExecutionPolicy -Scope LocalMachine | Should -Be "ByPass"
|
||||||
}
|
}
|
||||||
|
|
||||||
It '-Scope LocalMachine is Settable' {
|
It '-Scope LocalMachine is Settable' -Skip:(!(Test-CanWriteToPsHome)) {
|
||||||
# We need to make sure that both Process and CurrentUser policies are Undefined
|
# We need to make sure that both Process and CurrentUser policies are Undefined
|
||||||
# before we can set LocalMachine policy without ExecutionPolicyOverride error.
|
# before we can set LocalMachine policy without ExecutionPolicyOverride error.
|
||||||
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Undefined
|
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Undefined
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
@{ ModuleVersion = '1.0'; NestedModules = 'D:\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Security\Modules\ImportUnTrustedManifestWithBinFnExport_System32.dll'; CmdletsToExport = 'Invoke-Hello' }
|
|
@ -74,7 +74,7 @@ Describe "Get-Command Feature tests" -Tag Feature {
|
||||||
It "Can return multiple results for cmdlets matching abbreviation" {
|
It "Can return multiple results for cmdlets matching abbreviation" {
|
||||||
# use mixed casing to validate case insensitivity
|
# use mixed casing to validate case insensitivity
|
||||||
$results = pwsh -outputformat xml -settingsfile $configFilePath -command "Get-Command i-C -UseAbbreviationExpansion"
|
$results = pwsh -outputformat xml -settingsfile $configFilePath -command "Get-Command i-C -UseAbbreviationExpansion"
|
||||||
$results | Should -HaveCount 3
|
$results.Count | Should -BeGreaterOrEqual 3
|
||||||
$results.Name | Should -Contain "Invoke-Command"
|
$results.Name | Should -Contain "Invoke-Command"
|
||||||
$results.Name | Should -Contain "Import-Clixml"
|
$results.Name | Should -Contain "Import-Clixml"
|
||||||
$results.Name | Should -Contain "Import-Csv"
|
$results.Name | Should -Contain "Import-Csv"
|
||||||
|
|
|
@ -129,14 +129,14 @@ Categories=Application;
|
||||||
$windows = $shell.Windows()
|
$windows = $shell.Windows()
|
||||||
|
|
||||||
$before = $windows.Count
|
$before = $windows.Count
|
||||||
Invoke-Item -Path $PSHOME
|
Invoke-Item -Path ~
|
||||||
# may take time for explorer to open window
|
# may take time for explorer to open window
|
||||||
Wait-UntilTrue -sb { $windows.Count -gt $before } -TimeoutInMilliseconds (10*1000) -IntervalInMilliseconds 100 > $null
|
Wait-UntilTrue -sb { $windows.Count -gt $before } -TimeoutInMilliseconds (10*1000) -IntervalInMilliseconds 100 > $null
|
||||||
$after = $windows.Count
|
$after = $windows.Count
|
||||||
|
|
||||||
$before + 1 | Should -Be $after
|
$before + 1 | Should -Be $after
|
||||||
$item = $windows.Item($after - 1)
|
$item = $windows.Item($after - 1)
|
||||||
$item.LocationURL | Should -Match ($PSHOME -replace '\\', '/')
|
$item.LocationURL | Should -Match ((Resolve-Path ~) -replace '\\', '/')
|
||||||
## close the windows explorer
|
## close the windows explorer
|
||||||
$item.Quit()
|
$item.Quit()
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,9 +149,7 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Transcription should be closed if the only runspace gets closed" {
|
It "Transcription should be closed if the only runspace gets closed" {
|
||||||
$powerShellPath = [System.Diagnostics.Process]::GetCurrentProcess().Path
|
pwsh -c "start-transcript $transcriptFilePath; Write-Host ''Before Dispose'';"
|
||||||
$powerShellCommand = $powerShellPath + ' -c "start-transcript $transcriptFilePath; Write-Host ''Before Dispose'';"'
|
|
||||||
Invoke-Expression $powerShellCommand
|
|
||||||
|
|
||||||
$transcriptFilePath | Should -Exist
|
$transcriptFilePath | Should -Exist
|
||||||
$transcriptFilePath | Should -FileContentMatch "Before Dispose"
|
$transcriptFilePath | Should -FileContentMatch "Before Dispose"
|
||||||
|
@ -300,7 +298,7 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
|
||||||
Stop-Transcript
|
Stop-Transcript
|
||||||
}
|
}
|
||||||
|
|
||||||
$transcriptMinHeaderFilePath = $transcriptFilePath + "_minimal"
|
$transcriptMinHeaderFilePath = $transcriptFilePath + "_minimal"
|
||||||
$scriptMinHeader = {
|
$scriptMinHeader = {
|
||||||
Start-Transcript -Path $transcriptMinHeaderFilePath -UseMinimalHeader
|
Start-Transcript -Path $transcriptMinHeaderFilePath -UseMinimalHeader
|
||||||
Stop-Transcript
|
Stop-Transcript
|
||||||
|
@ -309,7 +307,7 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
|
||||||
& $script
|
& $script
|
||||||
$transcriptFilePath | Should -Exist
|
$transcriptFilePath | Should -Exist
|
||||||
$transcriptLength = (Get-Content -Path $transcriptFilePath -Raw).Length
|
$transcriptLength = (Get-Content -Path $transcriptFilePath -Raw).Length
|
||||||
|
|
||||||
& $scriptMinHeader
|
& $scriptMinHeader
|
||||||
$transcriptMinHeaderFilePath | Should -Exist
|
$transcriptMinHeaderFilePath | Should -Exist
|
||||||
$transcriptMinHeaderLength = (Get-Content -Path $transcriptMinHeaderFilePath -Raw).Length
|
$transcriptMinHeaderLength = (Get-Content -Path $transcriptMinHeaderFilePath -Raw).Length
|
||||||
|
|
|
@ -13,7 +13,13 @@ Describe "PSReadLine" -tags "CI" {
|
||||||
$module = Get-Module PSReadLine
|
$module = Get-Module PSReadLine
|
||||||
$module.Name | Should -BeExactly 'PSReadLine'
|
$module.Name | Should -BeExactly 'PSReadLine'
|
||||||
$module.Version | Should -BeExactly '2.0.0'
|
$module.Version | Should -BeExactly '2.0.0'
|
||||||
$module.Path | Should -Be (Join-Path -Path $PSHOME -ChildPath "Modules/PSReadLine/PSReadLine.psm1")
|
}
|
||||||
|
|
||||||
|
It "Should be installed to `$PSHOME" {
|
||||||
|
$module = Get-Module (Join-Path -Path $PSHOME -ChildPath "Modules" -AdditionalChildPath "PSReadLine") -ListAvailable
|
||||||
|
$module.Name | Should -BeExactly 'PSReadLine'
|
||||||
|
$module.Version | Should -BeExactly '2.0.0'
|
||||||
|
$module.Path | Should -Be (Join-Path -Path $PSHOME -ChildPath "Modules/PSReadLine/PSReadLine.psd1")
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should use Emacs Bindings on Linux and macOS" -skip:$IsWindows {
|
It "Should use Emacs Bindings on Linux and macOS" -skip:$IsWindows {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
|
Import-Module HelpersCommon
|
||||||
|
|
||||||
Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tags "Feature","RequireAdminOnWindows" {
|
Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tags "Feature","RequireAdminOnWindows" {
|
||||||
|
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
|
@ -52,6 +54,10 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag
|
||||||
) {
|
) {
|
||||||
param ($scope)
|
param ($scope)
|
||||||
|
|
||||||
|
if (!(Test-CanWriteToPsHome) -and $scope -eq "AllUsers") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
$feature = pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
|
$feature = pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
|
||||||
$feature.Enabled | Should -BeFalse -Because "All Experimental Features disabled when no config file"
|
$feature.Enabled | Should -BeFalse -Because "All Experimental Features disabled when no config file"
|
||||||
$feature = pwsh -noprofile -output xml -command Enable-ExperimentalFeature ExpTest.FeatureOne -Scope $scope -WarningAction SilentlyContinue
|
$feature = pwsh -noprofile -output xml -command Enable-ExperimentalFeature ExpTest.FeatureOne -Scope $scope -WarningAction SilentlyContinue
|
||||||
|
@ -66,6 +72,10 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag
|
||||||
) {
|
) {
|
||||||
param ($scope, $configPath)
|
param ($scope, $configPath)
|
||||||
|
|
||||||
|
if (!(Test-CanWriteToPsHome) -and $scope -eq "AllUsers") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
'{"ExperimentalFeatures":["ExpTest.FeatureOne"]}' > $configPath
|
'{"ExperimentalFeatures":["ExpTest.FeatureOne"]}' > $configPath
|
||||||
$feature = pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
|
$feature = pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
|
||||||
$feature.Enabled | Should -BeTrue -Because "Test config should enable ExpTest.FeatureOne"
|
$feature.Enabled | Should -BeTrue -Because "Test config should enable ExpTest.FeatureOne"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
|
Import-Module HelpersCommon
|
||||||
|
|
||||||
Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows" {
|
Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows" {
|
||||||
|
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
|
@ -31,7 +33,7 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows"
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
if ($systemConfigExists) {
|
if ($systemConfigExists -and (Test-CanWriteToPsHome)) {
|
||||||
Move-Item "$systemConfigPath.backup" $systemConfigPath -Force -ErrorAction SilentlyContinue
|
Move-Item "$systemConfigPath.backup" $systemConfigPath -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +45,10 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows"
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterEach {
|
AfterEach {
|
||||||
Remove-Item $systemConfigPath -Force -ErrorAction SilentlyContinue
|
if (Test-CanWriteToPsHome) {
|
||||||
|
Remove-Item $systemConfigPath -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
Remove-Item $userConfigPath -Force -ErrorAction SilentlyContinue
|
Remove-Item $userConfigPath -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +118,7 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows"
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "User config takes precedence over system config" {
|
Context "User config takes precedence over system config" {
|
||||||
It "Feature is enabled in user config only" {
|
It "Feature is enabled in user config only" -Skip:(!(Test-CanWriteToPsHome)) {
|
||||||
'{"ExperimentalFeatures":["ExpTest.FeatureOne"]}' > $userConfigPath
|
'{"ExperimentalFeatures":["ExpTest.FeatureOne"]}' > $userConfigPath
|
||||||
'{"ExperimentalFeatures":["ExpTest.FeatureTwo"]}' > $systemConfigPath
|
'{"ExperimentalFeatures":["ExpTest.FeatureTwo"]}' > $systemConfigPath
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#
|
#
|
||||||
# Validates Get-Help for cmdlets in Microsoft.PowerShell.Core.
|
# Validates Get-Help for cmdlets in Microsoft.PowerShell.Core.
|
||||||
|
|
||||||
|
Import-Module HelpersCommon
|
||||||
|
|
||||||
$script:cmdletsToSkip = @(
|
$script:cmdletsToSkip = @(
|
||||||
"Get-PSHostProcessInfo",
|
"Get-PSHostProcessInfo",
|
||||||
"Out-Default",
|
"Out-Default",
|
||||||
|
@ -122,14 +124,16 @@ Describe "Validate that get-help works for AllUsers Scope" -Tags @('Feature', 'R
|
||||||
Context "for module : $moduleName" {
|
Context "for module : $moduleName" {
|
||||||
|
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
UpdateHelpFromLocalContentPath $moduleName -Scope 'AllUsers'
|
if (Test-CanWriteToPsHome) {
|
||||||
|
UpdateHelpFromLocalContentPath $moduleName -Scope 'AllUsers'
|
||||||
|
}
|
||||||
$cmdlets = Get-Command -Module $moduleName
|
$cmdlets = Get-Command -Module $moduleName
|
||||||
}
|
}
|
||||||
|
|
||||||
$testCases = @()
|
$testCases = @()
|
||||||
$cmdlets | Where-Object { $cmdletsToSkip -notcontains $_ } | ForEach-Object { $testCases += @{ cmdletName = $_.Name }}
|
$cmdlets | Where-Object { $cmdletsToSkip -notcontains $_ } | ForEach-Object { $testCases += @{ cmdletName = $_.Name }}
|
||||||
|
|
||||||
It "Validate -Description and -Examples sections in help content. Run 'Get-help -name <cmdletName>" -TestCases $testCases {
|
It "Validate -Description and -Examples sections in help content. Run 'Get-help -name <cmdletName>" -TestCases $testCases -Skip:(!(Test-CanWriteToPsHome)) {
|
||||||
param($cmdletName)
|
param($cmdletName)
|
||||||
$help = get-help -name $cmdletName
|
$help = get-help -name $cmdletName
|
||||||
$help.Description | Out-String | Should Match $cmdletName
|
$help.Description | Out-String | Should Match $cmdletName
|
||||||
|
@ -214,10 +218,12 @@ Describe "Validate that get-help works for provider specific help" -Tags @('CI')
|
||||||
Describe "Validate about_help.txt under culture specific folder works" -Tags @('CI', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {
|
Describe "Validate about_help.txt under culture specific folder works" -Tags @('CI', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
$modulePath = "$pshome\Modules\Test"
|
$modulePath = "$pshome\Modules\Test"
|
||||||
$null = New-Item -Path $modulePath\en-US -ItemType Directory -Force
|
if (Test-CanWriteToPsHome) {
|
||||||
New-ModuleManifest -Path $modulePath\test.psd1 -RootModule test.psm1
|
$null = New-Item -Path $modulePath\en-US -ItemType Directory -Force
|
||||||
Set-Content -Path $modulePath\test.psm1 -Value "function foo{}"
|
New-ModuleManifest -Path $modulePath\test.psd1 -RootModule test.psm1
|
||||||
Set-Content -Path $modulePath\en-US\about_testhelp.help.txt -Value "Hello" -NoNewline
|
Set-Content -Path $modulePath\test.psm1 -Value "function foo{}"
|
||||||
|
Set-Content -Path $modulePath\en-US\about_testhelp.help.txt -Value "Hello" -NoNewline
|
||||||
|
}
|
||||||
|
|
||||||
$aboutHelpPath = Join-Path (GetCurrentUserHelpRoot) (Get-Culture).Name
|
$aboutHelpPath = Join-Path (GetCurrentUserHelpRoot) (Get-Culture).Name
|
||||||
|
|
||||||
|
@ -228,12 +234,14 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @('
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
Remove-Item $modulePath -Recurse -Force
|
if (Test-CanWriteToPsHome) {
|
||||||
|
Remove-Item $modulePath -Recurse -Force
|
||||||
|
}
|
||||||
# Remove all the help content.
|
# Remove all the help content.
|
||||||
Get-ChildItem -Path $aboutHelpPath -Include @('about_*.txt', "*help.xml") -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue
|
Get-ChildItem -Path $aboutHelpPath -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:(!(Test-CanWriteToPsHome)) {
|
||||||
|
|
||||||
$help = Get-Help about_testhelp
|
$help = Get-Help about_testhelp
|
||||||
$help.count | Should -Be 1
|
$help.count | Should -Be 1
|
||||||
|
@ -258,10 +266,12 @@ Describe "About help files can be found in AllUsers scope" -Tags @('Feature', 'R
|
||||||
Remove-Item $userHelpRoot -Force -Recurse -ErrorAction Stop
|
Remove-Item $userHelpRoot -Force -Recurse -ErrorAction Stop
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'AllUsers'
|
if (Test-CanWriteToPsHome) {
|
||||||
|
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'AllUsers'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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:(!(Test-CanWriteToPsHome)) {
|
||||||
$help = Get-Help about_Variables
|
$help = Get-Help about_Variables
|
||||||
$help.count | Should Be 1
|
$help.count | Should Be 1
|
||||||
}
|
}
|
||||||
|
@ -455,25 +465,27 @@ Describe 'help can be found for AllUsers Scope' -Tags @('Feature', 'RequireAdmin
|
||||||
## Delete help from global scope if it exists.
|
## Delete help from global scope if it exists.
|
||||||
$currentCulture = (Get-Culture).Name
|
$currentCulture = (Get-Culture).Name
|
||||||
|
|
||||||
$managementHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'Microsoft.PowerShell.Commands.Management.dll-Help.xml'
|
if (Test-CanWriteToPsHome) {
|
||||||
if (Test-Path $managementHelpFilePath) {
|
$managementHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'Microsoft.PowerShell.Commands.Management.dll-Help.xml'
|
||||||
Remove-Item $managementHelpFilePath -Force -ErrorAction SilentlyContinue
|
if (Test-Path $managementHelpFilePath) {
|
||||||
}
|
Remove-Item $managementHelpFilePath -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
$coreHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'System.Management.Automation.dll-Help.xml'
|
$coreHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'System.Management.Automation.dll-Help.xml'
|
||||||
if (Test-Path $coreHelpFilePath) {
|
if (Test-Path $coreHelpFilePath) {
|
||||||
Remove-Item $coreHelpFilePath -Force -ErrorAction SilentlyContinue
|
Remove-Item $coreHelpFilePath -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
$archiveHelpFilePath = Join-Path (Get-Module Microsoft.PowerShell.Archive -ListAvailable).ModuleBase -ChildPath $currentCulture -AdditionalChildPath 'Microsoft.PowerShell.Archive-help.xml'
|
$archiveHelpFilePath = Join-Path (Get-Module Microsoft.PowerShell.Archive -ListAvailable).ModuleBase -ChildPath $currentCulture -AdditionalChildPath 'Microsoft.PowerShell.Archive-help.xml'
|
||||||
if (Test-Path $archiveHelpFilePath) {
|
if (Test-Path $archiveHelpFilePath) {
|
||||||
Remove-Item $archiveHelpFilePath -Force -ErrorAction SilentlyContinue
|
Remove-Item $archiveHelpFilePath -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'AllUsers'
|
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'AllUsers'
|
||||||
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Management' -Scope 'AllUsers'
|
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Management' -Scope 'AllUsers'
|
||||||
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Archive' -Scope 'AllUsers' -Force
|
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Archive' -Scope 'AllUsers' -Force
|
||||||
UpdateHelpFromLocalContentPath -ModuleName 'PackageManagement' -Scope 'AllUsers' -Force
|
UpdateHelpFromLocalContentPath -ModuleName 'PackageManagement' -Scope 'AllUsers' -Force
|
||||||
|
}
|
||||||
|
|
||||||
$TestCases = @(
|
$TestCases = @(
|
||||||
@{TestName = 'module under $PSHOME'; CmdletName = 'Add-Content'}
|
@{TestName = 'module under $PSHOME'; CmdletName = 'Add-Content'}
|
||||||
|
@ -483,7 +495,7 @@ Describe 'help can be found for AllUsers Scope' -Tags @('Feature', 'RequireAdmin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'help in user scope be found for <TestName>' -TestCases $TestCases {
|
It 'help in user scope be found for <TestName>' -TestCases $TestCases -Skip:(!(Test-CanWriteToPsHome)) {
|
||||||
param($CmdletName)
|
param($CmdletName)
|
||||||
|
|
||||||
$helpObj = Get-Help -Name $CmdletName -Full
|
$helpObj = Get-Help -Name $CmdletName -Full
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
|
Import-Module HelpersCommon
|
||||||
|
|
||||||
# Test Settings:
|
# Test Settings:
|
||||||
# This is the list of PowerShell Core modules for which we test update-help
|
# This is the list of PowerShell Core modules for which we test update-help
|
||||||
$powershellCoreModules = @(
|
$powershellCoreModules = @(
|
||||||
|
@ -197,7 +199,7 @@ function RunUpdateHelpTests
|
||||||
if ($powershellCoreModules -contains $moduleName)
|
if ($powershellCoreModules -contains $moduleName)
|
||||||
{
|
{
|
||||||
|
|
||||||
It "Validate Update-Help for module '$moduleName' with scope as '$userscope'" {
|
It "Validate Update-Help for module '$moduleName' with scope as '$userscope'" -Skip:(!(Test-CanWriteToPsHome) -and $userscope -eq $false) {
|
||||||
|
|
||||||
if($userscope)
|
if($userscope)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
|
Import-Module HelpersCommon
|
||||||
|
|
||||||
Describe "Test-ModuleManifest tests" -tags "CI" {
|
Describe "Test-ModuleManifest tests" -tags "CI" {
|
||||||
|
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
|
@ -235,15 +238,17 @@ Describe "Tests for circular references in required modules" -tags "CI" {
|
||||||
Describe "Test-ModuleManifest Performance bug followup" -tags "CI" {
|
Describe "Test-ModuleManifest Performance bug followup" -tags "CI" {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
$TestModulesPath = [System.IO.Path]::Combine($PSScriptRoot, 'assets', 'testmodulerunspace')
|
$TestModulesPath = [System.IO.Path]::Combine($PSScriptRoot, 'assets', 'testmodulerunspace')
|
||||||
$UserModulesPath = "$pshome\Modules"
|
$PSHomeModulesPath = "$pshome\Modules"
|
||||||
|
|
||||||
# Install the Test Module
|
# Install the Test Module
|
||||||
Copy-Item $TestModulesPath\* $UserModulesPath -Recurse -Force
|
if (Test-CanWriteToPsHome) {
|
||||||
|
Copy-Item $TestModulesPath\* $PSHomeModulesPath -Recurse -Force -ErrorAction Stop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Test-ModuleManifest should not load unnessary modules" {
|
It "Test-ModuleManifest should not load unnessary modules" -Skip:(!(Test-CanWriteToPsHome)) {
|
||||||
|
|
||||||
$job = start-job -name "job1" -ScriptBlock {test-modulemanifest "$using:UserModulesPath\ModuleWithDependencies2\2.0\ModuleWithDependencies2.psd1" -verbose} | Wait-Job
|
$job = start-job -name "job1" -ScriptBlock {test-modulemanifest "$using:PSHomeModulesPath\ModuleWithDependencies2\2.0\ModuleWithDependencies2.psd1" -verbose} | Wait-Job
|
||||||
|
|
||||||
$verbose = $job.ChildJobs[0].Verbose.ReadAll()
|
$verbose = $job.ChildJobs[0].Verbose.ReadAll()
|
||||||
# Before the fix, all modules under $pshome will be imported and will be far more than 15 verbose messages. However, we cannot fix the number in case verbose message may vary.
|
# Before the fix, all modules under $pshome will be imported and will be far more than 15 verbose messages. However, we cannot fix the number in case verbose message may vary.
|
||||||
|
@ -252,8 +257,10 @@ Describe "Test-ModuleManifest Performance bug followup" -tags "CI" {
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
#clean up the test modules
|
#clean up the test modules
|
||||||
Remove-Item $UserModulesPath\ModuleWithDependencies2 -Recurse -Force -ErrorAction SilentlyContinue
|
if (Test-CanWriteToPsHome) {
|
||||||
Remove-Item $UserModulesPath\NestedRequiredModule1 -Recurse -Force -ErrorAction SilentlyContinue
|
Remove-Item $PSHomeModulesPath\ModuleWithDependencies2 -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Item $PSHomeModulesPath\NestedRequiredModule1 -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
|
Import-Module HelpersCommon
|
||||||
|
|
||||||
Describe "New-PSSession basic test" -Tag @("CI") {
|
Describe "New-PSSession basic test" -Tag @("CI") {
|
||||||
It "New-PSSession should not crash powershell" {
|
It "New-PSSession should not crash powershell" {
|
||||||
{ New-PSSession -ComputerName nonexistcomputer -Authentication Basic } |
|
{ New-PSSession -ComputerName nonexistcomputer -Authentication Basic } |
|
||||||
|
@ -52,7 +54,7 @@ Describe "JEA session Transcript script test" -Tag @("Feature", 'RequireAdminOnW
|
||||||
$global:PSDefaultParameterValues = $originalDefaultParameterValues
|
$global:PSDefaultParameterValues = $originalDefaultParameterValues
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Configuration name should be in the transcript header" {
|
It "Configuration name should be in the transcript header" -Skip:(!(Test-CanWriteToPsHome)) {
|
||||||
[string] $RoleCapDirectory = (New-Item -Path "$TestDrive\RoleCapability" -ItemType Directory -Force).FullName
|
[string] $RoleCapDirectory = (New-Item -Path "$TestDrive\RoleCapability" -ItemType Directory -Force).FullName
|
||||||
[string] $PSSessionConfigFile = "$RoleCapDirectory\TestConfig.pssc"
|
[string] $PSSessionConfigFile = "$RoleCapDirectory\TestConfig.pssc"
|
||||||
[string] $transScriptFile = "$RoleCapDirectory\*.txt"
|
[string] $transScriptFile = "$RoleCapDirectory\*.txt"
|
||||||
|
@ -94,7 +96,7 @@ Describe "JEA session Get-Help test" -Tag @("CI", 'RequireAdminOnWindows') {
|
||||||
$global:PSDefaultParameterValues = $originalDefaultParameterValues
|
$global:PSDefaultParameterValues = $originalDefaultParameterValues
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Get-Help should work in JEA sessions" {
|
It "Get-Help should work in JEA sessions" -Skip:(!(Test-CanWriteToPsHome)) {
|
||||||
[string] $RoleCapDirectory = (New-Item -Path "$TestDrive\RoleCapability" -ItemType Directory -Force).FullName
|
[string] $RoleCapDirectory = (New-Item -Path "$TestDrive\RoleCapability" -ItemType Directory -Force).FullName
|
||||||
[string] $PSSessionConfigFile = "$RoleCapDirectory\TestConfig.pssc"
|
[string] $PSSessionConfigFile = "$RoleCapDirectory\TestConfig.pssc"
|
||||||
try
|
try
|
||||||
|
|
|
@ -2,12 +2,13 @@
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
Import-Module HelpersRemoting
|
Import-Module HelpersRemoting
|
||||||
|
Import-Module HelpersCommon
|
||||||
|
|
||||||
Describe "Remote runspace pool should expose commands in endpoint configuration" -Tags 'Feature','RequireAdminOnWindows' {
|
Describe "Remote runspace pool should expose commands in endpoint configuration" -Tags 'Feature','RequireAdminOnWindows' {
|
||||||
|
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
|
|
||||||
if ($isWindows)
|
if ($isWindows -and (Test-CanWriteToPsHome))
|
||||||
{
|
{
|
||||||
$configName = "restrictedV"
|
$configName = "restrictedV"
|
||||||
$configPath = Join-Path $TestDrive ($configName + ".pssc")
|
$configPath = Join-Path $TestDrive ($configName + ".pssc")
|
||||||
|
@ -22,7 +23,7 @@ Describe "Remote runspace pool should expose commands in endpoint configuration"
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
|
|
||||||
if ($IsWindows)
|
if ($IsWindows -and (Test-CanWriteToPsHome))
|
||||||
{
|
{
|
||||||
if ($remoteRunspacePool -ne $null)
|
if ($remoteRunspacePool -ne $null)
|
||||||
{
|
{
|
||||||
|
@ -33,7 +34,7 @@ Describe "Remote runspace pool should expose commands in endpoint configuration"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Verifies that the configured endpoint cmdlet is available in all runspace pool instances" -Skip:(! $IsWindows) {
|
It "Verifies that the configured endpoint cmdlet is available in all runspace pool instances" -Skip:(!$IsWindows -or !(Test-CanWriteToPsHome)) {
|
||||||
|
|
||||||
[powershell] $ps1 = [powershell]::Create()
|
[powershell] $ps1 = [powershell]::Create()
|
||||||
$ps1.RunspacePool = $remoteRunspacePool
|
$ps1.RunspacePool = $remoteRunspacePool
|
||||||
|
|
|
@ -18,6 +18,7 @@ Description = 'Temporary module contains functions for using in tests'
|
||||||
|
|
||||||
FunctionsToExport = @(
|
FunctionsToExport = @(
|
||||||
'Add-TestDynamicType'
|
'Add-TestDynamicType'
|
||||||
|
'Test-CanWriteToPsHome'
|
||||||
'Disable-Testhook'
|
'Disable-Testhook'
|
||||||
'Enable-Testhook'
|
'Enable-Testhook'
|
||||||
'Get-RandomFileName'
|
'Get-RandomFileName'
|
||||||
|
|
|
@ -320,3 +320,27 @@ function New-RandomHexString
|
||||||
return ((1..$Length).ForEach{ '{0:x}' -f $random.Next(0xf) }) -join ''
|
return ((1..$Length).ForEach{ '{0:x}' -f $random.Next(0xf) }) -join ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$script:CanWriteToPsHome = $null
|
||||||
|
function Test-CanWriteToPsHome
|
||||||
|
{
|
||||||
|
if ($null -ne $script:CanWriteToPsHome) {
|
||||||
|
return $script:CanWriteToPsHome
|
||||||
|
}
|
||||||
|
|
||||||
|
$script:CanWriteToPsHome = $true
|
||||||
|
|
||||||
|
try {
|
||||||
|
$testFileName = Join-Path $PSHome (New-Guid).Guid
|
||||||
|
$null = New-Item -ItemType File -Path $testFileName -ErrorAction Stop
|
||||||
|
}
|
||||||
|
catch [System.UnauthorizedAccessException] {
|
||||||
|
$script:CanWriteToPsHome = $false
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if ($script:CanWriteToPsHome) {
|
||||||
|
Remove-Item -Path $testFileName -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$script:CanWriteToPsHome
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue