1+ $prefixDir = Split-Path - Parent (Split-Path - Parent (Split-Path - Parent $PSScriptRoot ))
2+ $exePath = Join-Path $prefixDir ' prefix.exe'
3+
4+ if (-not (Test-Path $exePath )) {
5+ throw " Interpreter executable not found at: $exePath "
6+ }
7+
8+ $tempDir = Join-Path ([IO.Path ]::GetTempPath()) ([IO.Path ]::GetRandomFileName())
9+ New-Item - ItemType Directory - Path $tempDir | Out-Null
10+
11+ try {
12+ $programPath = Join-Path $tempDir ' program.pre'
13+
14+ Set-Content - Path $programPath - Encoding Ascii - Value @'
15+ PRINT("left=", TRUE, ",right=", 0d42, ",flt=", INF)
16+ '@
17+
18+ $startInfo = New-Object System.Diagnostics.ProcessStartInfo
19+ $startInfo.FileName = $exePath
20+ $startInfo.Arguments = (' "{0}"' -f $programPath )
21+ $startInfo.RedirectStandardOutput = $true
22+ $startInfo.RedirectStandardError = $true
23+ $startInfo.UseShellExecute = $false
24+ $startInfo.CreateNoWindow = $true
25+
26+ $process = [System.Diagnostics.Process ]::Start($startInfo )
27+ $stdout = $process.StandardOutput.ReadToEnd ()
28+ $stderr = $process.StandardError.ReadToEnd ()
29+ $process.WaitForExit ()
30+ $exitCode = $process.ExitCode
31+ $process.Dispose ()
32+
33+ if ($exitCode -ne 0 ) {
34+ throw " Prefix exited with code $exitCode `n STDOUT:`n $stdout `n STDERR:`n $stderr "
35+ }
36+
37+ if ($stderr.Length -ne 0 ) {
38+ throw " Expected no stderr output, got:`n $stderr "
39+ }
40+
41+ if (-not [regex ]::IsMatch($stdout , ' \Aleft=TRUE,right=0d42,flt=INF(?:\r\n|\n)\z' )) {
42+ $escapedStdout = $stdout.Replace (" `r " , ' \r' ).Replace(" `n " , ' \n' )
43+ throw " Unexpected stdout: $escapedStdout "
44+ }
45+ }
46+ finally {
47+ Remove-Item - Path $tempDir - Recurse - Force - ErrorAction SilentlyContinue
48+ }
0 commit comments