From 8d23dad0ab62945219317a61adf2e245d9fcf840 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 7 Jul 2016 14:46:14 -0700 Subject: [PATCH] Add Read-Host regression test --- test/powershell/Host/Read-Host.Tests.ps1 | 20 ++++++++++++++ .../Host/assets/Read-Host.Output.expect | 27 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/powershell/Host/Read-Host.Tests.ps1 create mode 100755 test/powershell/Host/assets/Read-Host.Output.expect diff --git a/test/powershell/Host/Read-Host.Tests.ps1 b/test/powershell/Host/Read-Host.Tests.ps1 new file mode 100644 index 0000000000..847198154a --- /dev/null +++ b/test/powershell/Host/Read-Host.Tests.ps1 @@ -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 + } + } +} diff --git a/test/powershell/Host/assets/Read-Host.Output.expect b/test/powershell/Host/assets/Read-Host.Output.expect new file mode 100755 index 0000000000..7cfb718d6d --- /dev/null +++ b/test/powershell/Host/assets/Read-Host.Output.expect @@ -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