Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/powershell/Host/HostUtilities.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Describe "InvokeOnRunspace method as nested command" -tags "Feature" {
}
}

Describe "InvokeOnRunspace method on remote runspace" -tags "Feature" {
Describe "InvokeOnRunspace method on remote runspace" -tags "Feature","RequireAdminOnWindows" {

BeforeAll {

Expand Down
8 changes: 3 additions & 5 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ Describe "TabCompletion" -Tags CI {
## if $PSHOME contains a space tabcompletion adds ' around the path
@{ inputStr = 'cd $pshome\Modu'; expected = if($PSHOME.Contains(' ')) { "'$(Join-Path $PSHOME 'Modules')'" } else { Join-Path $PSHOME 'Modules' }; setup = $null }
@{ inputStr = 'cd "$pshome\Modu"'; expected = "`"$(Join-Path $PSHOME 'Modules')`""; setup = $null }
@{ inputStr = '$PSHOME\System.Management.Au'; expected = Join-Path $PSHOME 'System.Management.Automation.dll'; setup = $null }
@{ inputStr = '$PSHOME\System.Management.Au'; expected = if($PSHOME.Contains(' ')) { "`& '$(Join-Path $PSHOME 'System.Management.Automation.dll')'" } else { Join-Path $PSHOME 'System.Management.Automation.dll'; setup = $null }}
@{ inputStr = '"$PSHOME\System.Management.Au"'; expected = "`"$(Join-Path $PSHOME 'System.Management.Automation.dll')`""; setup = $null }
@{ inputStr = '& "$PSHOME\System.Management.Au"'; expected = "`"$(Join-Path $PSHOME 'System.Management.Automation.dll')`""; setup = $null }
## tab completion AST-based tests
Expand Down Expand Up @@ -1045,7 +1045,7 @@ dir -Recurse `
}
}

Describe "Tab completion tests with remote Runspace" -Tags Feature {
Describe "Tab completion tests with remote Runspace" -Tags Feature,RequireAdminOnWindows {
BeforeAll {
if ($IsWindows) {
$session = New-RemoteSession
Expand Down Expand Up @@ -1116,9 +1116,7 @@ Describe "WSMan Config Provider tab complete tests" -Tags Feature,RequireAdminOn
$res = TabExpansion2 -inputScript $path -cursorColumn $path.Length
$listener = Get-ChildItem WSMan:\localhost\Listener
$res.CompletionMatches.Count | Should -Be $listener.Count
for ($i = 0; $i -lt $res.CompletionMatches.Count; $i++) {
$res.CompletionMatches[$i].ListItemText | Should -Be $listener[$i].Name
}
$res.CompletionMatches.ListItemText | Should -BeIn $listener.Name
}

It "Tab completion gets dynamic parameters for '<path>' using '<parameter>'" -TestCases @(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@
Describe "Remote module tests" -Tags 'Feature','RequireAdminOnWindows' {

BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
if (!$IsWindows) {

if (!$IsWindows)
{
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["it:skip"] = $true
} else {
$pssession = New-RemoteSession
# pending https://github.com/PowerShell/PowerShell/issues/4819
# $cimsession = New-RemoteSession -CimSession
return
}

$pssession = New-RemoteSession
# pending https://github.com/PowerShell/PowerShell/issues/4819
# $cimsession = New-RemoteSession -CimSession
}

AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues

if (!$IsWindows)
{
$global:PSDefaultParameterValues = $originalDefaultParameterValues
return
}

if ($pssession -ne $null) { Remove-PSSession $pssession -ErrorAction SilentlyContinue }
}

It "Get-Module fails if not using -ListAvailable with '<parameter>'" -TestCases @(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ try
Enable-Testhook -testhookName TestStopComputer

# TEST START HERE
Describe "Rename-Computer" -Tag Feature {
Describe "Rename-Computer" -Tag Feature,RequireAdminOnWindows {
# if we throw in BeforeEach, the test will fail and the stop will not be called
BeforeEach {
if ( ! (Test-TesthookIsSet -testhookName $RenameTesthook) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try
$PSDefaultParameterValues["it:skip"] = ! $IsWindows
Enable-Testhook -testhookName $restartTesthookName

Describe "Restart-Computer" -Tag Feature {
Describe "Restart-Computer" -Tag Feature,RequireAdminOnWindows {
# if we throw in BeforeEach, the test will fail and the restart will not be called
BeforeEach {
if ( ! (Test-TesthookIsSet -testhookName $restartTesthookName) ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Start-Process" -Tags @("Feature") {
Describe "Start-Process" -Tag "Feature","RequireAdminOnWindows" {

BeforeAll {
$isNanoServer = [System.Management.Automation.Platform]::IsNanoServer
Expand Down Expand Up @@ -113,7 +113,7 @@ Describe "Start-Process" -Tags @("Feature") {
}

It "Should start notepad.exe with ShellExecute" -Skip:(!$isFullWin) {
$process = Start-Process notepad -PassThru -WindowStyle Normal
$process = Start-Process notepad.exe -PassThru -WindowStyle Normal
$process.Name | Should -Be "notepad"
$process | Stop-Process
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,6 @@ $PSDefaultParameterValues["it:skip"] = $skipTest

try
{
#
# Ensure WinRM remoting is enabled
#
if (! $skipTest)
{
# Check to see if a default endpoint has been created
$endpointName = "PowerShell.$($psversiontable.GitCommitId)"
$matchedEndpoint = Get-PSSessionConfiguration $endpointName -ErrorAction SilentlyContinue

if ($matchedEndpoint -eq $null)
{
# An endpoint for this instance of PowerShell does not exist.
#
# -SkipNetworkProfileCheck is used in case Docker or another application
# has created a publich virtual network profile on the system
Enable-PSRemoting -SkipNetworkProfileCheck
}
}

Describe "Implicit remoting and CIM cmdlets with AllSigned and Restricted policy" -tags "Feature","RequireAdminOnWindows" {

BeforeAll {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "TestWSMan tests" -Tags 'Feature' {
Describe "TestWSMan tests" -Tags 'Feature','RequireAdminOnWindows' {

BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
Expand Down Expand Up @@ -46,13 +46,14 @@ Describe "TestWSMan tests" -Tags 'Feature' {
{ Test-WSMan -Authentication foo -ErrorAction Stop } | Should -Throw -ErrorId "CannotConvertArgumentNoMessage,Microsoft.WSMan.Management.TestWSManCommand"
}

It "Test-WSMan works for '<computername>'" -TestCases @(
@{ computername = $null },
@{ computername = "localhost" },
@{ computername = $env:COMPUTERNAME }
It "Test-WSMan works for <testName>" -TestCases @(
@{ testName = "Null"; computername = $null },
@{ testName = "localhost"; computername = "localhost" },
@{ testName = "computername"; computername = $env:COMPUTERNAME }
) {
param($computername)
$response = Test-WSMan -ComputerName $computername
$response | Should -Not -BeNullOrEmpty
$response.PSObject.TypeNames[0] | Should -Be "System.Xml.XmlElement#http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd#IdentifyResponse"
$response.wsmid | Should -Be "http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd"
$response.ProtocolVersion | Should -Be "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"
Expand Down
39 changes: 36 additions & 3 deletions test/powershell/engine/Remoting/ImplicitRemotingBatching.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,55 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "TestImplicitRemotingBatching hook should correctly batch simple remote command pipelines" -Tags 'Feature','RequireAdminOnWindows' {
Describe "TestImplicitRemotingBatching hook should correctly batch simple remote command pipelines" -Tag 'Feature','RequireAdminOnWindows' {

BeforeAll {

if (! $isWindows) { return }

function ThrowSetupError
{
param (
[string] $errorMessage,
[System.Management.Automation.ErrorRecord[]] $eRecords
)

$msg = @()
foreach ($err in $powerShell.Streams.Error)
{
$msg += $err.ToString() + "`n"
}

throw "$errorMessage : '$msg'"
}

# Make sure we can create a remote session
$remotePSSession = New-RemoteSession
if ($remotePSSession -eq $null)
{
Write-Verbose "Unable to create a remote session in test."
}
else
{
Remove-PSSession $remotePSSession
}

[powershell] $powerShell = [powershell]::Create([System.Management.Automation.RunspaceMode]::NewRunspace)

# Create remote session in new PowerShell session
$powerShell.AddScript('Import-Module -Name HelpersRemoting; $remoteSession = New-RemoteSession').Invoke()
if ($powerShell.Streams.Error.Count -gt 0) { throw "Unable to create remote session for test" }
if ($powerShell.Streams.Error.Count -gt 0)
{
ThrowSetupError -errorMessage "Unable to create remote session for test with error" -eRecords $powerShell.Streams.Error
}

# Import implicit commands from remote session
$powerShell.Commands.Clear()
$powerShell.AddScript('Import-PSSession -Session $remoteSession -CommandName Get-Process,Write-Output -AllowClobber').Invoke()
if ($powerShell.Streams.Error.Count -gt 0) { throw "Unable to import pssession for test" }
if ($powerShell.Streams.Error.Count -gt 0)
{
ThrowSetupError -errorMessage "Unable to import pssession for test" -eRecords $powerShell.Streams.Error
}

# Define $filter variable in local session
$powerShell.Commands.Clear()
Expand Down
54 changes: 25 additions & 29 deletions test/powershell/engine/Remoting/InvokeCommandRemoteDebug.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -116,56 +116,52 @@ if ($IsWindows)
'@
}

Describe "Invoke-Command remote debugging tests" -Tags 'Feature' {
Describe "Invoke-Command remote debugging tests" -Tags 'Feature','RequireAdminOnWindows' {

BeforeAll {

if (!$IsWindows)
{
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["it:Pending"] = $true
$PSDefaultParameterValues["it:skip"] = $true
return
}
else
{
$sb = [scriptblock]::Create(@'
"Hello!"
'@)

Add-Type -TypeDefinition $typeDef
$sb = [scriptblock]::Create('"Hello!"')

$dummyHost = [TestRunner.DummyHost]::new()
[runspace] $rs = [runspacefactory]::CreateRunspace($dummyHost)
$rs.Open()
$dummyHost._runspace = $rs
Add-Type -TypeDefinition $typeDef

$testDebugger = [TestRunner.TestDebugger]::new($rs)
$dummyHost = [TestRunner.DummyHost]::new()
[runspace] $rs = [runspacefactory]::CreateRunspace($dummyHost)
$rs.Open()
$dummyHost._runspace = $rs

[runspace] $rs2 = [runspacefactory]::CreateRunspace()
$rs2.Open()
$testDebugger = [TestRunner.TestDebugger]::new($rs)

[powershell] $ps = [powershell]::Create()
$ps.Runspace = $rs
[runspace] $rs2 = [runspacefactory]::CreateRunspace()
$rs2.Open()

[powershell] $ps2 = [powershell]::Create()
$ps2.Runspace = $rs2
}
[powershell] $ps = [powershell]::Create()
$ps.Runspace = $rs

[powershell] $ps2 = [powershell]::Create()
$ps2.Runspace = $rs2
}

AfterAll {

if (!$IsWindows)
{
$global:PSDefaultParameterValues = $originalDefaultParameterValues
return
}
else
{
if ($null -ne $testDebugger) { $testDebugger.Release() }
if ($null -ne $ps) { $ps.Dispose() }
if ($null -ne $ps2) { $ps2.Dispose() }
if ($null -ne $rs) { $rs.Dispose() }
if ($null -ne $rs2) { $rs2.Dispose() }
if ($null -ne $remoteSession) { Remove-PSSession $remoteSession -ErrorAction SilentlyContinue }
}

if ($null -ne $testDebugger) { $testDebugger.Release() }
if ($null -ne $ps) { $ps.Dispose() }
if ($null -ne $ps2) { $ps2.Dispose() }
if ($null -ne $rs) { $rs.Dispose() }
if ($null -ne $rs2) { $rs2.Dispose() }
if ($null -ne $remoteSession) { Remove-PSSession $remoteSession -ErrorAction SilentlyContinue }
}

BeforeEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Describe "Remoting loopback tests" -Tags @('CI', 'RequireAdminOnWindows') {
}

It 'Can invoke-command as job' {
$result = Invoke-Command -ScriptBlock { 1 + 1 } -Session $openSession -AsJob | Receive-Job -AutoRemoveJob -Wait
$result = Invoke-Command -ScriptBlock { 1 + 1 } -Session $openSession -AsJob | Receive-Job -AutoRemoveJob -Wait -ErrorAction SilentlyContinue
$result | Should -Be 2
}

Expand Down
13 changes: 12 additions & 1 deletion test/powershell/engine/ResourceValidation/TestRunner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ function Test-ResourceStrings
# This is the reason why this is not a general module for use. There is
# no other way to run these tests
Describe "Resources strings in $AssemblyName (was -ResGen used with Start-PSBuild)" -tag Feature {

function NormalizeLineEnd
{
param (
[string] $string
)

$string -replace "`r`n", "`n"
}

foreach ( $resourceFile in $resourceFiles )
{
# in the event that the id has a space in it, it is replaced with a '_'
Expand All @@ -50,7 +60,8 @@ function Test-ResourceStrings
# check all the resource strings
$xmlData = [xml](Get-Content $resourceFile.Fullname)
foreach ( $inResource in $xmlData.root.data ) {
$resourceType.GetProperty($inResource.name,$bindingFlags).GetValue(0) | Should -Be $inresource.value
$resourceStringToCheck = $resourceType.GetProperty($inResource.name,$bindingFlags).GetValue(0)
NormalizeLineEnd($resourceStringToCheck) | Should -Be (NormalizeLineEnd($inresource.value))
}
}
}
Expand Down
Loading