mirror of
https://github.com/PowerShell/PowerShell.git
synced 2024-11-24 02:04:07 +08:00
Add Read-Host regression test
This commit is contained in:
parent
68875f0942
commit
8d23dad0ab
20
test/powershell/Host/Read-Host.Tests.ps1
Normal file
20
test/powershell/Host/Read-Host.Tests.ps1
Normal file
@ -0,0 +1,20 @@
|
||||
Describe "Read-Host" {
|
||||
Context "[Console]::ReadKey() implementation on non-Windows" {
|
||||
BeforeAll {
|
||||
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
|
||||
$assetsDir = Join-Path -Path $PSScriptRoot -ChildPath assets
|
||||
if ($IsWindows) {
|
||||
$ItArgs = @{ skip = $true }
|
||||
} elseif (-not (Get-Command expect -ErrorAction Ignore)) {
|
||||
$ItArgs = @{ pending = $true }
|
||||
} else {
|
||||
$ItArgs = @{ }
|
||||
}
|
||||
}
|
||||
|
||||
It @ItArgs "Should output correctly" {
|
||||
& (Join-Path $assetsDir "Read-Host.Output.expect") $powershell | Out-Null
|
||||
$LASTEXITCODE | Should Be 0
|
||||
}
|
||||
}
|
||||
}
|
27
test/powershell/Host/assets/Read-Host.Output.expect
Executable file
27
test/powershell/Host/assets/Read-Host.Output.expect
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/expect -f
|
||||
|
||||
exp_internal 1
|
||||
|
||||
# Expects path to PowerShell as first argument
|
||||
set powershell [lindex $argv 0]
|
||||
|
||||
set timeout 5
|
||||
|
||||
spawn $powershell -nologo -noprofile Read-Host prompt
|
||||
|
||||
expect "prompt: $" {
|
||||
send "input\r"
|
||||
}
|
||||
|
||||
# This is the old, incorrect behavior
|
||||
expect "input\r\ninput\r" {
|
||||
exit 2
|
||||
}
|
||||
|
||||
# This is the expected behavior
|
||||
expect "input\r\n" {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Anything else is wrong
|
||||
exit 1
|
Loading…
Reference in New Issue
Block a user