Skip to content

Commit 24da688

Browse files
Add tests for MAIN.
1 parent c6c7ddd commit 24da688

8 files changed

Lines changed: 144 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MAIN(0d1)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
$modulePath = Join-Path $tempDir 'main_func_wrapper.pre'
13+
$programPath = Join-Path $tempDir 'program.pre'
14+
15+
Set-Content -Path $modulePath -Encoding Ascii -Value @'
16+
FUNC BOOL: imported_main(){
17+
RETURN(MAIN())
18+
}
19+
'@
20+
21+
$moduleLiteral = $modulePath.Replace('\', '\\')
22+
23+
Set-Content -Path $programPath -Encoding Ascii -Value @"
24+
IMPORT_PATH("$moduleLiteral", helper)
25+
26+
ASSERT(NOT(helper.imported_main()))
27+
"@
28+
29+
$output = & $exePath $programPath 2>&1
30+
if ($LASTEXITCODE -ne 0) {
31+
$outputText = ($output | ForEach-Object { $_.ToString() }) -join [Environment]::NewLine
32+
throw "Prefix exited with code $LASTEXITCODE`n$outputText"
33+
}
34+
}
35+
finally {
36+
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
37+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
$modulePath = Join-Path $tempDir 'main_top_result.pre'
13+
$programPath = Join-Path $tempDir 'program.pre'
14+
15+
Set-Content -Path $modulePath -Encoding Ascii -Value @'
16+
BOOL: top_result = MAIN()
17+
18+
FUNC BOOL: read_top_result(){
19+
RETURN(top_result)
20+
}
21+
'@
22+
23+
$moduleLiteral = $modulePath.Replace('\', '\\')
24+
25+
Set-Content -Path $programPath -Encoding Ascii -Value @"
26+
IMPORT_PATH("$moduleLiteral", helper)
27+
28+
ASSERT(NOT(helper.read_top_result()))
29+
ASSERT(EQ(TYPE(helper.read_top_result()), "BOOL"))
30+
"@
31+
32+
$output = & $exePath $programPath 2>&1
33+
if ($LASTEXITCODE -ne 0) {
34+
$outputText = ($output | ForEach-Object { $_.ToString() }) -join [Environment]::NewLine
35+
throw "Prefix exited with code $LASTEXITCODE`n$outputText"
36+
}
37+
}
38+
finally {
39+
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
40+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BOOL: branch_taken = FALSE
2+
3+
IF(MAIN()){
4+
branch_taken = TRUE
5+
} ELSE {
6+
ASSERT(FALSE)
7+
}
8+
9+
ASSERT(branch_taken)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FUNC BOOL: from_primary_function(){
2+
RETURN(MAIN())
3+
}
4+
5+
ASSERT(from_primary_function())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ASSERT(EQ(TYPE(MAIN()), "BOOL"))
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
$modulePath = Join-Path $tempDir 'main_func_wrapper.pre'
13+
$programPath = Join-Path $tempDir 'program.pre'
14+
15+
Set-Content -Path $modulePath -Encoding Ascii -Value @'
16+
FUNC BOOL: imported_main(){
17+
RETURN(MAIN())
18+
}
19+
20+
FUNC BOOL: call_callback(FUNC: callback){
21+
RETURN(callback())
22+
}
23+
24+
FUNC BOOL: call_imported_main(){
25+
RETURN(imported_main())
26+
}
27+
'@
28+
29+
$moduleLiteral = $modulePath.Replace('\', '\\')
30+
31+
Set-Content -Path $programPath -Encoding Ascii -Value @"
32+
IMPORT_PATH("$moduleLiteral", helper)
33+
34+
FUNC BOOL: local_main(){
35+
RETURN(MAIN())
36+
}
37+
38+
ASSERT(helper.call_callback(local_main))
39+
ASSERT(NOT(helper.call_imported_main()))
40+
"@
41+
42+
$output = & $exePath $programPath 2>&1
43+
if ($LASTEXITCODE -ne 0) {
44+
$outputText = ($output | ForEach-Object { $_.ToString() }) -join [Environment]::NewLine
45+
throw "Prefix exited with code $LASTEXITCODE`n$outputText"
46+
}
47+
}
48+
finally {
49+
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
50+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ASSERT(MAIN())

0 commit comments

Comments
 (0)