From 875a12d3d1e8464f6b75912a543b98e225f4dff2 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 25 Jan 2018 11:18:21 -0800 Subject: [PATCH] Skip tests that use ExecutionPolicy cmdlets on Unix (#6021) --- test/powershell/Host/ConsoleHost.Tests.ps1 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index 70bbc0006..44cc50695 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -252,23 +252,28 @@ Describe "ConsoleHost unit tests" -tags "Feature" { Context "-SettingsFile Commandline switch" { BeforeAll { - $CustomSettingsFile = Join-Path -Path $TestDrive -ChildPath 'Powershell.test.json' - $DefaultExecutionPolicy = 'RemoteSigned' + if ($IsWindows) { + $CustomSettingsFile = Join-Path -Path $TestDrive -ChildPath 'Powershell.test.json' + $DefaultExecutionPolicy = 'RemoteSigned' + } } BeforeEach { - # reset the content of the settings file to a known state. - Set-Content -Path $CustomSettingsfile -Value "{`"Microsoft.PowerShell:ExecutionPolicy`":`"$DefaultExecutionPolicy`"}" -ErrorAction Stop + if ($IsWindows) { + # 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 # 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 | Should Be $DefaultExecutionPolicy } - It "Verifies PowerShell writes to the custom -settingsFile" { + It "Verifies PowerShell writes to the custom -settingsFile" -skip:(!$IsWindows) { $expectedValue = 'AllSigned' # Update the execution policy; this should update the settings file. @@ -283,7 +288,7 @@ Describe "ConsoleHost unit tests" -tags "Feature" { $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. & $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.'Microsoft.PowerShell:ExecutionPolicy' | Should Be $null } - } Context "Pipe to/from powershell" {