Files
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1
T

47 lines
1.3 KiB
PowerShell

using namespace System.Diagnostics
Describe "Invoke-Item" {
function NewProcessStartInfo([string]$CommandLine, [switch]$RedirectStdIn)
{
return [ProcessStartInfo]@{
FileName = $powershell
Arguments = $CommandLine
RedirectStandardInput = $RedirectStdIn
RedirectStandardOutput = $true
RedirectStandardError = $true
UseShellExecute = $false
}
}
function RunPowerShell([ProcessStartInfo]$debugfn)
{
$process = [Process]::Start($debugfn)
return $process
}
function EnsureChildHasExited([Process]$process, [int]$WaitTimeInMS = 15000)
{
$process.WaitForExit($WaitTimeInMS)
if (!$process.HasExited)
{
$process.HasExited | Should Be $true
$process.Kill()
}
}
BeforeAll {
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
Setup -File testfile.txt -Content "Hello World"
$testfile = Join-Path $TestDrive testfile.txt
}
It "Should invoke a text file without error" {
$debugfn = NewProcessStartInfo "-noprofile ""``Invoke-Item $testfile`n" -RedirectStdIn
$process = RunPowerShell $debugfn
EnsureChildHasExited $process
$process.ExitCode | Should Be 0
}
}