Skip tests that use ExecutionPolicy cmdlets on Unix (#6021)

This commit is contained in:
Dongbo Wang 2018-01-25 11:18:21 -08:00 committed by Aditya Patwardhan
parent 2f1aec1496
commit 875a12d3d1

View file

@ -252,23 +252,28 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
Context "-SettingsFile Commandline switch" { Context "-SettingsFile Commandline switch" {
BeforeAll { BeforeAll {
$CustomSettingsFile = Join-Path -Path $TestDrive -ChildPath 'Powershell.test.json' if ($IsWindows) {
$DefaultExecutionPolicy = 'RemoteSigned' $CustomSettingsFile = Join-Path -Path $TestDrive -ChildPath 'Powershell.test.json'
$DefaultExecutionPolicy = 'RemoteSigned'
}
} }
BeforeEach { BeforeEach {
# reset the content of the settings file to a known state. if ($IsWindows) {
Set-Content -Path $CustomSettingsfile -Value "{`"Microsoft.PowerShell:ExecutionPolicy`":`"$DefaultExecutionPolicy`"}" -ErrorAction Stop # reset the content of the settings file to a known state.
Set-Content -Path $CustomSettingsfile -Value "{`"Microsoft.PowerShell:ExecutionPolicy`":`"$DefaultExecutionPolicy`"}" -ErrorAction Stop
}
} }
# NOTE: The -settingsFile command-line option only reads settings for the local machine. As a result, the tests that use Set/Get-ExecutionPolicy # NOTE: The -settingsFile command-line option only reads settings for the local machine. As a result, the tests that use Set/Get-ExecutionPolicy
# must use an explicit scope of LocalMachine to ensure the setting is written to the expected file. # must use an explicit scope of LocalMachine to ensure the setting is written to the expected file.
# Skip the tests on Unix platforms because *-ExecutionPolicy cmdlets don't work by design.
It "Verifies PowerShell reads from the custom -settingsFile" { It "Verifies PowerShell reads from the custom -settingsFile" -skip:(!$IsWindows) {
$actualValue = & $powershell -NoProfile -SettingsFile $CustomSettingsFile -Command {(Get-ExecutionPolicy -Scope LocalMachine).ToString()} $actualValue = & $powershell -NoProfile -SettingsFile $CustomSettingsFile -Command {(Get-ExecutionPolicy -Scope LocalMachine).ToString()}
$actualValue | Should Be $DefaultExecutionPolicy $actualValue | Should Be $DefaultExecutionPolicy
} }
It "Verifies PowerShell writes to the custom -settingsFile" { It "Verifies PowerShell writes to the custom -settingsFile" -skip:(!$IsWindows) {
$expectedValue = 'AllSigned' $expectedValue = 'AllSigned'
# Update the execution policy; this should update the settings file. # Update the execution policy; this should update the settings file.
@ -283,7 +288,7 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
$actualValue | Should Be $expectedValue $actualValue | Should Be $expectedValue
} }
It "Verify PowerShell removes a setting from the custom -settingsFile" { It "Verify PowerShell removes a setting from the custom -settingsFile" -skip:(!$IsWindows) {
# Remove the LocalMachine execution policy; this should update the settings file. # Remove the LocalMachine execution policy; this should update the settings file.
& $powershell -NoProfile -SettingsFile $CustomSettingsFile -Command {Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope LocalMachine } & $powershell -NoProfile -SettingsFile $CustomSettingsFile -Command {Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope LocalMachine }
@ -291,7 +296,6 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
$content = (Get-Content -Path $CustomSettingsFile | ConvertFrom-Json) $content = (Get-Content -Path $CustomSettingsFile | ConvertFrom-Json)
$content.'Microsoft.PowerShell:ExecutionPolicy' | Should Be $null $content.'Microsoft.PowerShell:ExecutionPolicy' | Should Be $null
} }
} }
Context "Pipe to/from powershell" { Context "Pipe to/from powershell" {