|
| 1 | +$helperPath = Join-Path (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) 'helpers\prefix-input.ps1' |
| 2 | +. $helperPath |
| 3 | + |
| 4 | +$tempDir = New-PrefixTempDir |
| 5 | + |
| 6 | +try { |
| 7 | + $programPath = Join-Path $tempDir 'program.pre' |
| 8 | + |
| 9 | + Set-Content -Path $programPath -Encoding Ascii -Value @' |
| 10 | +PRINT("custom") |
| 11 | +EXIT(0d23) |
| 12 | +PRINT("after") |
| 13 | +'@ |
| 14 | + |
| 15 | + $startInfo = New-Object System.Diagnostics.ProcessStartInfo |
| 16 | + $startInfo.FileName = Get-PrefixExePath |
| 17 | + $startInfo.Arguments = ('"{0}"' -f $programPath) |
| 18 | + $startInfo.RedirectStandardOutput = $true |
| 19 | + $startInfo.RedirectStandardError = $true |
| 20 | + $startInfo.UseShellExecute = $false |
| 21 | + $startInfo.CreateNoWindow = $true |
| 22 | + |
| 23 | + $process = [System.Diagnostics.Process]::Start($startInfo) |
| 24 | + try { |
| 25 | + $stdout = $process.StandardOutput.ReadToEnd() |
| 26 | + $stderr = $process.StandardError.ReadToEnd() |
| 27 | + $process.WaitForExit() |
| 28 | + |
| 29 | + $result = [pscustomobject]@{ |
| 30 | + ExitCode = $process.ExitCode |
| 31 | + Stdout = $stdout |
| 32 | + Stderr = $stderr |
| 33 | + } |
| 34 | + } |
| 35 | + finally { |
| 36 | + $process.Dispose() |
| 37 | + } |
| 38 | + |
| 39 | + if ($result.ExitCode -ne 23) { |
| 40 | + $stdout = Format-VisibleText $result.Stdout |
| 41 | + $stderr = Format-VisibleText $result.Stderr |
| 42 | + throw "Expected Prefix to exit with code 23, got $($result.ExitCode)`nSTDOUT: $stdout`nSTDERR: $stderr" |
| 43 | + } |
| 44 | + |
| 45 | + Assert-NoErrorOutput $result |
| 46 | + |
| 47 | + if (-not [regex]::IsMatch($result.Stdout, '\Acustom(?:\r\n|\n)\z')) { |
| 48 | + $stdout = Format-VisibleText $result.Stdout |
| 49 | + throw "Unexpected stdout: $stdout" |
| 50 | + } |
| 51 | +} |
| 52 | +finally { |
| 53 | + Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue |
| 54 | +} |
0 commit comments