Skip to content

Commit 7f857db

Browse files
Add tests for PRINT.
1 parent fe67584 commit 7f857db

8 files changed

Lines changed: 57 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PRINT()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PRINT(LAMBDA BOOL: (){})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PRINT(<"key" = 0d1>)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PRINT(ASYNC{})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PRINT([0d1])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ASSERT(NOT(PRINT(TRUE)))
2+
ASSERT(NOT(PRINT(0d42)))
3+
ASSERT(NOT(PRINT(0d1.5)))
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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`nSTDOUT:`n$stdout`nSTDERR:`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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ASSERT(EQ(PRINT("value"), FALSE))

0 commit comments

Comments
 (0)