diff --git a/test/powershell/Host/HostUtilities.Tests.ps1 b/test/powershell/Host/HostUtilities.Tests.ps1 index 1f064408e3..7f738cb01c 100644 --- a/test/powershell/Host/HostUtilities.Tests.ps1 +++ b/test/powershell/Host/HostUtilities.Tests.ps1 @@ -37,8 +37,10 @@ Describe "InvokeOnRunspace method on remote runspace" -tags "Feature","RequireAd BeforeAll { $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() - if (Test-IsWinWow64) { - $global:PSDefaultParameterValues["it:skip"] = $true + $pendingTest = (Test-IsWinWow64) + + if ($pendingTest) { + $global:PSDefaultParameterValues["it:pending"] = $true return } @@ -48,7 +50,7 @@ Describe "InvokeOnRunspace method on remote runspace" -tags "Feature","RequireAd } AfterAll { - if ($script:remoteRunspace) + if ($script:remoteRunspace -and -not $pendingTest) { $script:remoteRunspace.Dispose(); } diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index d7c98b1589..c56cd2ca94 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -2427,7 +2427,10 @@ function MyFunction ($param1, $param2) Describe "Tab completion tests with remote Runspace" -Tags Feature,RequireAdminOnWindows { BeforeAll { - if ($IsWindows -and -not (Test-IsWinWow64)) { + $skipTest = -not $IsWindows + $pendingTest = $IsWindows -and (Test-IsWinWow64) + + if (-not $skipTest -and -not $pendingTest) { $session = New-RemoteSession $powershell = [powershell]::Create() $powershell.Runspace = $session.Runspace @@ -2445,11 +2448,16 @@ Describe "Tab completion tests with remote Runspace" -Tags Feature,RequireAdminO ) } else { $defaultParameterValues = $PSDefaultParameterValues.Clone() - $PSDefaultParameterValues["It:Skip"] = $true + + if ($skipTest) { + $PSDefaultParameterValues["It:Skip"] = $true + } elseif ($pendingTest) { + $PSDefaultParameterValues["It:Pending"] = $true + } } } AfterAll { - if ($IsWindows) { + if (-not $skipTest -and -not $pendingTest) { Remove-PSSession $session $powershell.Dispose() } else { diff --git a/test/powershell/Language/Scripting/SuppressAnsiEscapeSequence.Tests.ps1 b/test/powershell/Language/Scripting/SuppressAnsiEscapeSequence.Tests.ps1 index 0530aea93e..c1440857b4 100644 --- a/test/powershell/Language/Scripting/SuppressAnsiEscapeSequence.Tests.ps1 +++ b/test/powershell/Language/Scripting/SuppressAnsiEscapeSequence.Tests.ps1 @@ -6,7 +6,7 @@ Describe '$env:__SuppressAnsiEscapeSequences tests' -Tag CI { $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() if (-not $host.ui.SupportsVirtualTerminal) { - $global:PSDefaultParameterValues["it:skip"] = $true + $PSDefaultParameterValues["it:skip"] = $true } $originalSuppressPref = $env:__SuppressAnsiEscapeSequences diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 index 8ab4047c27..48763dc00f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 @@ -838,7 +838,7 @@ namespace PowershellTestConfigNamespace } if ($IsNotSkipped) { - Enable-PSRemoting + Enable-PSRemoting -SkipNetworkProfileCheck -Force } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteGetModule.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteGetModule.Tests.ps1 index 95e522ab9a..d410e4db2f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteGetModule.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteGetModule.Tests.ps1 @@ -3,11 +3,22 @@ Describe "Remote module tests" -Tags 'Feature','RequireAdminOnWindows' { BeforeAll { + $pendingTest = (Test-IsWinWow64) + $skipTest = !$IsWindows - if (!$IsWindows -or (Test-IsWinWow64)) + $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() + + if ($pendingTest -or $skipTest) { - $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() - $PSDefaultParameterValues["it:skip"] = $true + if ($skipTest) + { + $PSDefaultParameterValues["it:skip"] = $true + } + elseif ($pendingTest) + { + $PSDefaultParameterValues["it:pending"] = $true + } + return } @@ -18,7 +29,7 @@ Describe "Remote module tests" -Tags 'Feature','RequireAdminOnWindows' { AfterAll { - if (!$IsWindows) + if ($pendingTest -or $skipTest) { $global:PSDefaultParameterValues = $originalDefaultParameterValues return diff --git a/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteImportModule.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteImportModule.Tests.ps1 index ba7f35f048..19cf4e0787 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteImportModule.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Core/RemoteImportModule.Tests.ps1 @@ -5,8 +5,14 @@ Describe "Remote import-module tests" -Tags 'Feature','RequireAdminOnWindows' { BeforeAll { $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() $modulePath = "$testdrive\Modules\TestImport" - if (!$IsWindows -or (Test-IsWinWow64)) { + + $pendingTest = (Test-IsWinWow64) + $skipTest = !$IsWindows + + if ($skipTest) { $PSDefaultParameterValues["it:skip"] = $true + } elseif ($pendingTest) { + $PSDefaultParameterValues["it:pending"] = $true } else { $pssession = New-RemoteSession Invoke-Command -Session $pssession -Scriptblock { $env:PSModulePath += ";${using:testdrive}" } @@ -21,7 +27,7 @@ Describe "Remote import-module tests" -Tags 'Feature','RequireAdminOnWindows' { AfterAll { $global:PSDefaultParameterValues = $originalDefaultParameterValues - if ($IsWindows) { + if ($IsWindows -and !$pendingTest -and !$skipTest) { $pssession | Remove-PSSession -ErrorAction SilentlyContinue } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/TimeZone.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/TimeZone.Tests.ps1 index 43b1cae28d..5a23c7df75 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/TimeZone.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/TimeZone.Tests.ps1 @@ -13,14 +13,12 @@ [snippet] Both StandardName and DaylightName are localized according to the current user default UI language. #> -function Assert-ListsSame -{ +function Assert-ListsSame { param([object[]] $expected, [object[]] $observed ) $compResult = Compare-Object $observed $expected | Select-Object -ExpandProperty InputObject - if ($compResult) - { - $observedList = ([string]::Join("|",$observed)) - $expectedList = ([string]::Join("|",$expected)) + if ($compResult) { + $observedList = ([string]::Join("|", $observed)) + $expectedList = ([string]::Join("|", $expected)) $observedList | Should -Be $expectedList } } @@ -53,7 +51,7 @@ Describe "Get-Timezone test cases" -Tags "CI" { $list = Get-TimeZone -ListAvailable $list.Count | Should -BeGreaterThan 0 - ,$list | Should -BeOfType Object[] + , $list | Should -BeOfType Object[] $list[0] | Should -BeOfType TimeZoneInfo } @@ -86,8 +84,8 @@ Describe "Get-Timezone test cases" -Tags "CI" { It "Call Get-TimeZone using ID param and multiple items, where first and third are invalid ids - expect error" { $selectedTZ = $TimeZonesAvailable[0].Id - $null = Get-TimeZone -Id @("Cape Verde Standard",$selectedTZ,"Azores Standard") ` - -ErrorVariable errVar -ErrorAction SilentlyContinue + $null = Get-TimeZone -Id @("Cape Verde Standard", $selectedTZ, "Azores Standard") ` + -ErrorVariable errVar -ErrorAction SilentlyContinue $errVar.Count | Should -Be 2 $errVar[0].FullyQualifiedErrorID | Should -Be "TimeZoneNotFound,Microsoft.PowerShell.Commands.GetTimeZoneCommand" } @@ -126,112 +124,118 @@ Describe "Get-Timezone test cases" -Tags "CI" { } } -try { - $defaultParamValues = $PSdefaultParameterValues.Clone() - # Set-TimeZone fails due to missing ApiSet dependency on Windows Server 2012 R2. - $osInfo = [System.Environment]::OSVersion.Version - $isSrv2k12R2 = $osInfo.Major -eq 6 -and $osInfo.Minor -eq 3 +Describe "Set-Timezone test case: call by single Id" -Tags @('CI', 'RequireAdminOnWindows') { + BeforeAll { - $PSDefaultParameterValues["it:skip"] = !$IsWindows -or $isSrv2k12R2 + $defaultParamValues = $PSdefaultParameterValues.Clone() - Describe "Set-Timezone test case: call by single Id" -Tags @('CI', 'RequireAdminOnWindows') { - BeforeAll { - if ($IsWindows) { - $originalTimeZoneId = (Get-TimeZone).Id - } - } - AfterAll { - if ($IsWindows) { - Set-TimeZone -Id $originalTimeZoneId - } + if (-not $IsWindows -or (Test-IsWinServer2012R2)) { + # Set-TimeZone fails due to missing ApiSet dependency on Windows Server 2012 R2. + $PSDefaultParameterValues["it:skip"] = $true + return } - It "Call Set-TimeZone by Id" { - $origTimeZoneID = (Get-TimeZone).Id - $timezoneList = Get-TimeZone -ListAvailable - $testTimezone = $null - foreach ($timezone in $timezoneList) { - if ($timezone.Id -ne $origTimeZoneID) { - $testTimezone = $timezone - break - } - } - Set-TimeZone -Id $testTimezone.Id - $observed = Get-TimeZone - $testTimezone.Id | Should -Be $observed.Id + $originalTimeZoneId = (Get-TimeZone).Id + } + AfterAll { + if (-not $IsWindows -or (Test-IsWinServer2012R2)) { + $global:PSDefaultParameterValues = $defaultParamValues + return } + + Set-TimeZone -Id $originalTimeZoneId } - Describe "Set-Timezone test cases" -Tags @('Feature', 'RequireAdminOnWindows') { - BeforeAll { - if ($IsWindows) - { - $originalTimeZoneId = (Get-TimeZone).Id + It "Call Set-TimeZone by Id" { + $origTimeZoneID = (Get-TimeZone).Id + $timezoneList = Get-TimeZone -ListAvailable + $testTimezone = $null + foreach ($timezone in $timezoneList) { + if ($timezone.Id -ne $origTimeZoneID) { + $testTimezone = $timezone + break } } - AfterAll { - if ($IsWindows) { - Set-TimeZone -Id $originalTimeZoneId - } - } - - It "Call Set-TimeZone with invalid Id" { - { Set-TimeZone -Id "zzInvalidID" } | Should -Throw -ErrorId "TimeZoneNotFound,Microsoft.PowerShell.Commands.SetTimeZoneCommand" - } - - It "Call Set-TimeZone by Name" { - $origTimeZoneName = (Get-TimeZone).StandardName - $timezoneList = Get-TimeZone -ListAvailable - $testTimezone = $null - foreach ($timezone in $timezoneList) { - if ($timezone.StandardName -ne $origTimeZoneName) { - $testTimezone = $timezone - break - } - } - Set-TimeZone -Name $testTimezone.StandardName - $observed = Get-TimeZone - $testTimezone.StandardName | Should -Be $observed.StandardName - } - - It "Call Set-TimeZone with invalid Name" { - { Set-TimeZone -Name "zzINVALID_Name" } | Should -Throw -ErrorId "TimeZoneNotFound,Microsoft.PowerShell.Commands.SetTimeZoneCommand" - } - - It "Call Set-TimeZone from pipeline input object of type TimeZoneInfo" { - $origTimeZoneID = (Get-TimeZone).Id - $timezoneList = Get-TimeZone -ListAvailable - $testTimezone = $null - foreach ($timezone in $timezoneList) { - if ($timezone.Id -ne $origTimeZoneID) { - $testTimezone = $timezone - break - } - } - - $testTimezone | Set-TimeZone - $observed = Get-TimeZone - $observed.ID | Should -Be $testTimezone.Id - } - - It "Call Set-TimeZone from pipeline input object of type TimeZoneInfo, verify supports whatif" { - $origTimeZoneID = (Get-TimeZone).Id - $timezoneList = Get-TimeZone -ListAvailable - $testTimezone = $null - foreach ($timezone in $timezoneList) { - if ($timezone.Id -ne $origTimeZoneID) { - $testTimezone = $timezone - break - } - } - - Set-TimeZone -Id $testTimezone.Id -WhatIf > $null - $observed = Get-TimeZone - $observed.Id | Should -Be $origTimeZoneID - } + Set-TimeZone -Id $testTimezone.Id + $observed = Get-TimeZone + $testTimezone.Id | Should -Be $observed.Id } } -finally { - $global:PSDefaultParameterValues = $defaultParamValues + +Describe "Set-Timezone test cases" -Tags @('Feature', 'RequireAdminOnWindows') { + BeforeAll { + $defaultParamValues = $PSdefaultParameterValues.Clone() + + if (-not $IsWindows -or (Test-IsWinServer2012R2)) { + # Set-TimeZone fails due to missing ApiSet dependency on Windows Server 2012 R2. + $PSDefaultParameterValues["it:skip"] = $true + return + } + + $originalTimeZoneId = (Get-TimeZone).Id + } + AfterAll { + if (-not $IsWindows -or (Test-IsWinServer2012R2)) { + $global:PSDefaultParameterValues = $defaultParamValues + return + } + + Set-TimeZone -Id $originalTimeZoneId + } + + It "Call Set-TimeZone with invalid Id" { + { Set-TimeZone -Id "zzInvalidID" } | Should -Throw -ErrorId "TimeZoneNotFound,Microsoft.PowerShell.Commands.SetTimeZoneCommand" + } + + It "Call Set-TimeZone by Name" { + $origTimeZoneName = (Get-TimeZone).StandardName + $timezoneList = Get-TimeZone -ListAvailable + $testTimezone = $null + foreach ($timezone in $timezoneList) { + if ($timezone.StandardName -ne $origTimeZoneName) { + $testTimezone = $timezone + break + } + } + Set-TimeZone -Name $testTimezone.StandardName + $observed = Get-TimeZone + $testTimezone.StandardName | Should -Be $observed.StandardName + } + + It "Call Set-TimeZone with invalid Name" { + { Set-TimeZone -Name "zzINVALID_Name" } | Should -Throw -ErrorId "TimeZoneNotFound,Microsoft.PowerShell.Commands.SetTimeZoneCommand" + } + + It "Call Set-TimeZone from pipeline input object of type TimeZoneInfo" { + $origTimeZoneID = (Get-TimeZone).Id + $timezoneList = Get-TimeZone -ListAvailable + $testTimezone = $null + foreach ($timezone in $timezoneList) { + if ($timezone.Id -ne $origTimeZoneID) { + $testTimezone = $timezone + break + } + } + + $testTimezone | Set-TimeZone + $observed = Get-TimeZone + $observed.ID | Should -Be $testTimezone.Id + } + + It "Call Set-TimeZone from pipeline input object of type TimeZoneInfo, verify supports whatif" { + $origTimeZoneID = (Get-TimeZone).Id + $timezoneList = Get-TimeZone -ListAvailable + $testTimezone = $null + foreach ($timezone in $timezoneList) { + if ($timezone.Id -ne $origTimeZoneID) { + $testTimezone = $timezone + break + } + } + + Set-TimeZone -Id $testTimezone.Id -WhatIf > $null + $observed = Get-TimeZone + $observed.Id | Should -Be $origTimeZoneID + } } diff --git a/test/powershell/engine/Formatting/OutputRendering.Tests.ps1 b/test/powershell/engine/Formatting/OutputRendering.Tests.ps1 index dda4bdbd1e..52aef0151a 100644 --- a/test/powershell/engine/Formatting/OutputRendering.Tests.ps1 +++ b/test/powershell/engine/Formatting/OutputRendering.Tests.ps1 @@ -7,7 +7,7 @@ Describe 'OutputRendering tests' -Tag 'CI' { # Console host does not support VT100 escape sequences on Windows 2012R2 or earlier if (-not $host.ui.SupportsVirtualTerminal) { - $global:PSDefaultParameterValues["it:skip"] = $true + $PSDefaultParameterValues["it:skip"] = $true } } diff --git a/test/powershell/engine/Remoting/RemoteSession.Disconnect.Tests.ps1 b/test/powershell/engine/Remoting/RemoteSession.Disconnect.Tests.ps1 index a6a4f23e08..60c69c09a0 100644 --- a/test/powershell/engine/Remoting/RemoteSession.Disconnect.Tests.ps1 +++ b/test/powershell/engine/Remoting/RemoteSession.Disconnect.Tests.ps1 @@ -7,7 +7,15 @@ Describe "WinRM based remoting session abrupt disconnect" -Tags 'Feature','Requi BeforeAll { $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() - if (! $IsWindows -or (Test-IsWinWow64)) + $pendingTest = (Test-IsWinWow64) + $skipTest = !$IsWindows + + if ($pendingTest) + { + $PSDefaultParameterValues["it:pending"] = $true + return + } + elseif ($skipTest) { $PSDefaultParameterValues["it:skip"] = $true return @@ -56,6 +64,11 @@ Describe "WinRM based remoting session abrupt disconnect" -Tags 'Feature','Requi AfterAll { $global:PSDefaultParameterValues = $originalDefaultParameterValues + if ($pendingTest -or $skipTest) + { + return + } + if ($ps -ne $null) { $ps.Dispose() } if ($session -ne $null) { Remove-PSSession -Session $session } if ($script:job -ne $null) { Remove-Job -Job $script:job -Force } diff --git a/test/powershell/engine/Remoting/RunspacePool.Tests.ps1 b/test/powershell/engine/Remoting/RunspacePool.Tests.ps1 index f4481c85eb..6f5ad9f113 100644 --- a/test/powershell/engine/Remoting/RunspacePool.Tests.ps1 +++ b/test/powershell/engine/Remoting/RunspacePool.Tests.ps1 @@ -8,40 +8,44 @@ Describe "Remote runspace pool should expose commands in endpoint configuration" BeforeAll { - if ($IsWindows -and (Test-CanWriteToPsHome) -and -not (Test-IsWinWow64)) - { - $configName = "restrictedV" - $configPath = Join-Path $TestDrive ($configName + ".pssc") + $pendingTest = (Test-IsWinWow64) + $skipTest = !$IsWindows -or !(Test-CanWriteToPsHome) - New-PSSessionConfigurationFile -Path $configPath -SessionType RestrictedRemoteServer -VisibleCmdlets 'Get-CimInstance' + $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() - $null = Register-PSSessionConfiguration -Name $configName -Path $configPath -Force -ErrorAction SilentlyContinue - - $remoteRunspacePool = New-RemoteRunspacePool -ConfigurationName $configName + if ($pendingTest) { + $PSDefaultParameterValues["it:pending"] = $true + return } - elseif (Test-IsWinWow64) - { - $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() + + if ($skipTest) { $PSDefaultParameterValues["it:skip"] = $true + return } + + $configName = "restrictedV" + $configPath = Join-Path $TestDrive ($configName + ".pssc") + + New-PSSessionConfigurationFile -Path $configPath -SessionType RestrictedRemoteServer -VisibleCmdlets 'Get-CimInstance' + + $null = Register-PSSessionConfiguration -Name $configName -Path $configPath -Force -ErrorAction SilentlyContinue + + $remoteRunspacePool = New-RemoteRunspacePool -ConfigurationName $configName } AfterAll { - if (Test-IsWinWow64) { + if ($pendingTest -or $skipTest) { $global:PSDefaultParameterValues = $originalDefaultParameterValues return } - if ($IsWindows -and (Test-CanWriteToPsHome)) + if ($remoteRunspacePool -ne $null) { - if ($remoteRunspacePool -ne $null) - { - $remoteRunspacePool.Dispose() - } - - Unregister-PSSessionConfiguration -Name $configName -Force -ErrorAction SilentlyContinue + $remoteRunspacePool.Dispose() } + + Unregister-PSSessionConfiguration -Name $configName -Force -ErrorAction SilentlyContinue } It "Verifies that the configured endpoint cmdlet is available in all runspace pool instances" -Skip:(!$IsWindows -or !(Test-CanWriteToPsHome)) { diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 index f11f5432ad..ca9fb8a813 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psd1 @@ -36,6 +36,7 @@ FunctionsToExport = @( 'Test-IsVstsLinux' 'Test-IsVstsWindows' 'Test-IsWindowsArm64' + 'Test-IsWinServer2012R2' 'Test-IsWinWow64' 'Test-TesthookIsSet' 'Wait-FileToBePresent' diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 index 013bd2cf70..d59b64b794 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 @@ -446,3 +446,13 @@ function Test-IsReleaseCandidate return $false } + +function Test-IsWinServer2012R2 +{ + if (-not $IsWindows) { + return $false + } + + $osInfo = [System.Environment]::OSVersion.Version + return ($osInfo.Major -eq 6 -and $osInfo.Minor -eq 3) +}