Files
PowerShell-PowerShell/test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1
T
Steve Lee c5dd3bd2c9 Support 'Get-PSHostProcessInfo' and 'Enter-PSHostProcess' on Unix platforms (#8232)
There a some differences in support of named pipes for Windows and non-Windows.  Named pipes on Unix have a 104 character path limit.  On macOS, the `$env:TMPDIR` (on my system) is already 49 characters; corefx adds 12 more.  Since AppDomainName isn't really used, changed it from `DefaultAppDomain` to `None` to shorten the name.  Need to keep it since Windows PowerShell expects it.  Changed `starttime` part of pipe name to 8 hex characters which is to provide uniqueness to the pipe name.
2018-11-15 12:50:04 -08:00

46 lines
1.5 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Enter-PSHostProcess tests" -Tag Feature {
BeforeAll {
$si = [System.Diagnostics.ProcessStartInfo]::new()
$si.FileName = "pwsh"
$si.Arguments = "-noexit"
$si.RedirectStandardInput = $true
$si.RedirectStandardOutput = $true
$si.RedirectStandardError = $true
$pwsh = [System.Diagnostics.Process]::Start($si)
if ($IsWindows) {
$si.FileName = "powershell"
$powershell = [System.Diagnostics.Process]::Start($si)
}
}
AfterAll {
$pwsh | Stop-Process
if ($IsWindows) {
$powershell | Stop-Process
}
}
It "Can enter and exit another PSHost" {
"enter-pshostprocess -id $($pwsh.Id)`n`$pid`nexit-pshostprocess" | pwsh -c - | Should -Be $pwsh.Id
}
It "Can enter and exit another Windows PowerShell PSHost" -Skip:(!$IsWindows) {
"enter-pshostprocess -id $($powershell.Id)`n`$pid`nexit-pshostprocess" | pwsh -c - | Should -Be $powershell.Id
}
It "Can enter using NamedPipeConnectionInfo" {
$npInfo = [System.Management.Automation.Runspaces.NamedPipeConnectionInfo]::new($pwsh.Id)
$rs = [runspacefactory]::CreateRunspace($npInfo)
$rs.Open()
$ps = [powershell]::Create()
$ps.Runspace = $rs
$ps.AddScript('$pid').Invoke() | Should -Be $pwsh.Id
$rs.Dispose()
}
}