2015-11-10 09:45:21 -08:00
|
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
|
|
|
. $here/Test-Common.ps1
|
|
|
|
|
|
|
|
|
|
Describe "Start-Process" {
|
2015-11-11 13:16:00 -08:00
|
|
|
$pingCommand = (Get-Command -CommandType Application ping)[0].Definition
|
2015-11-10 09:45:21 -08:00
|
|
|
$pingDirectory = Split-Path $pingCommand -Parent
|
2015-12-18 17:22:39 -08:00
|
|
|
$tempFile = "$(GetTempDir)/PSTest"
|
2015-11-10 10:52:00 -08:00
|
|
|
$assetsFile = $here + "/assets/SortTest.txt"
|
2015-11-10 09:45:21 -08:00
|
|
|
$windows = IsWindows
|
|
|
|
|
if ($windows)
|
|
|
|
|
{
|
|
|
|
|
$pingParamNoStop = "localhost -t"
|
|
|
|
|
$pingParamStop = "localhost -n 2"
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$pingParamNoStop = "localhost"
|
|
|
|
|
$pingParamStop = "localhost -c 2"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AfterEach {
|
|
|
|
|
Stop-Process -Name ping -ErrorAction SilentlyContinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should start a process without error" {
|
|
|
|
|
{ Start-Process ping } | Should Not Throw
|
2015-11-11 10:17:22 -08:00
|
|
|
}
|
2015-11-10 09:45:21 -08:00
|
|
|
|
|
|
|
|
It "Should process arguments without error" {
|
|
|
|
|
{ Start-Process ping -ArgumentList $pingParamNoStop} | Should Not Throw
|
|
|
|
|
|
|
|
|
|
$process = Get-Process -Name ping
|
2015-11-11 10:17:22 -08:00
|
|
|
|
2015-11-10 09:45:21 -08:00
|
|
|
$process.Length | Should Be 1
|
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
|
|
|
|
$process.ProcessName | Should Be "ping"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should create process object when used with PassThru argument" {
|
|
|
|
|
$process = Start-Process ping -ArgumentList $pingParamNoStop -PassThru
|
|
|
|
|
|
|
|
|
|
$process.Length | Should Be 1
|
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
|
|
|
|
$process.ProcessName | Should Be "ping"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should work correctly when used with full path name" {
|
|
|
|
|
$process = Start-Process $pingCommand -ArgumentList $pingParamNoStop -PassThru
|
|
|
|
|
|
|
|
|
|
$process.Length | Should Be 1
|
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
|
|
|
|
$process.ProcessName | Should Be "ping"
|
|
|
|
|
}
|
2015-11-11 10:17:22 -08:00
|
|
|
|
2015-11-10 09:45:21 -08:00
|
|
|
It "Should invoke correct path when used with FilePath argument" {
|
|
|
|
|
$process = Start-Process -FilePath $pingCommand -ArgumentList $pingParamNoStop -PassThru
|
|
|
|
|
|
|
|
|
|
$process.Length | Should Be 1
|
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
|
|
|
|
$process.ProcessName | Should Be "ping"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should wait for command completion if used with Wait argument" {
|
|
|
|
|
Start-Process ping -ArgumentList $pingParamStop -Wait
|
|
|
|
|
|
|
|
|
|
$process = Get-Process -Name ping -ErrorAction SilentlyContinue
|
2015-11-11 10:17:22 -08:00
|
|
|
|
2015-11-10 09:45:21 -08:00
|
|
|
$process.Length | Should Be 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should work correctly with WorkingDirectory argument" {
|
|
|
|
|
$process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParamNoStop -PassThru
|
|
|
|
|
|
|
|
|
|
$process.Length | Should Be 1
|
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
|
|
|
|
$process.ProcessName | Should Be "ping"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should should handle stderr redirection without error" {
|
|
|
|
|
$process = Start-Process ping -ArgumentList $pingParamNoStop -PassThru -RedirectStandardError $tempFile
|
|
|
|
|
|
|
|
|
|
$process.Length | Should Be 1
|
|
|
|
|
$process.Id | Should BeGreaterThan 1
|
|
|
|
|
$process.ProcessName | Should Be "ping"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should should handle stdout redirection without error" {
|
|
|
|
|
$process = Start-Process ping -ArgumentList $pingParamStop -Wait -RedirectStandardOutput $tempFile
|
2015-11-11 10:17:22 -08:00
|
|
|
$dirEntry = dir $tempFile
|
2015-11-10 09:45:21 -08:00
|
|
|
|
|
|
|
|
$dirEntry.Length | Should BeGreaterThan 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should should handle stdin redirection without error" {
|
2015-11-10 10:52:00 -08:00
|
|
|
$process = Start-Process sort -Wait -RedirectStandardOutput $tempFile -RedirectStandardInput $assetsFile
|
2015-11-11 10:17:22 -08:00
|
|
|
$dirEntry = dir $tempFile
|
2015-11-10 09:45:21 -08:00
|
|
|
|
|
|
|
|
$dirEntry.Length | Should BeGreaterThan 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|