test: integration tests for imports

This commit is contained in:
2025-03-13 09:43:29 +00:00
parent e881b736f8
commit f11fb9f881
23 changed files with 270 additions and 13 deletions

1
.gitignore vendored
View File

@@ -4,4 +4,3 @@
.vscode/
wacc-examples/
.idea/

View File

@@ -0,0 +1,10 @@
begin
int main() is
int a = 5 ;
string b = "Hello" ;
return a + b
end
int result = call main() ;
exit result
end

View File

@@ -0,0 +1,6 @@
import "./doesNotExist.wacc" (main)
begin
int result = call main() ;
exit result
end

View File

@@ -0,0 +1,6 @@
import "../../../valid/sum.wacc" (mult)
begin
int result = call mult(3, 2) ;
exit result
end

View File

@@ -0,0 +1,10 @@
import "../badWacc.wacc" (main)
begin
int sum(int a, int b) is
return a + b
end
int result = call main() ;
exit result
end

View File

@@ -0,0 +1,6 @@
import "./importBadSem.wacc" (sum)
begin
int result = call sum(1, 2) ;
exit result
end

View File

@@ -0,0 +1,6 @@
import "../../../valid/imports/basic.wacc" (sum)
begin
int result = call sum(3, 2) ;
exit result
end

View File

@@ -0,0 +1,6 @@
int main() is
println "Hello World!" ;
return 0
end
skip

View File

@@ -0,0 +1,8 @@
import "../../../valid/sum.wacc" sum, main
begin
int result1 = call sum(5, 10) ;
int result2 = call main() ;
println result1 ;
println result2
end

View File

@@ -0,0 +1,5 @@
import "../../../valid/sum.wacc" ()
begin
exit 0
end

View File

@@ -0,0 +1,10 @@
import "../badWacc.wacc" (main)
begin
int sum(int a, int b) is
return a + b
end
int result = call main() ;
exit result
end

View File

@@ -0,0 +1,6 @@
import "./importBadSyntax.wacc" (sum)
begin
int result = call sum(1, 2) ;
exit result
end

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,9 @@
import "../../../valid/sum.wacc" (sum) ;
import "../../../valid/sum.wacc" (main) ;
begin
int result1 = call sum(5, 10) ;
int result2 = call main() ;
println result1 ;
println result2
end

View File

@@ -0,0 +1,5 @@
import "../../../valid/sum.wacc" *
begin
exit 0
end

View File

@@ -0,0 +1,5 @@
import "../../../valid/sum.wacc" (*)
begin
exit 0
end

7
extension/examples/valid/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
*
!imports/
imports/*
!.gitignore
!*.wacc

View File

@@ -0,0 +1,22 @@
# import main from ../sum.wacc and ./basic.wacc
# Output:
# 15
# 0
# -33
#
# Exit:
# 0
# Program:
import "../sum.wacc" (main as sumMain)
import "./basic.wacc" (main)
begin
int result1 = call sumMain() ;
int result2 = call main() ;
println result1 ;
println result2
end

View File

@@ -0,0 +1,20 @@
# import sum from ../sum.wacc
# Output:
# -33
# Exit:
# 0
# Program:
import "../sum.wacc" (sum)
begin
int main() is
int result = call sum(-10, -23) ;
return result
end
int result = call main() ;
println result
end

View File

@@ -0,0 +1,34 @@
# import all the mains
# Output:
# 15
# 0
# -33
# 0
# -33
# 0
#
# Exit:
# 99
# Program:
import "../sum.wacc" (main as sumMain)
import "./basic.wacc" (main as basicMain)
import "./multiFunc.wacc" (main as multiFuncMain)
begin
int main() is
int result1 = call sumMain() ;
int result2 = call basicMain() ;
int result3 = call multiFuncMain() ;
println result1 ;
println result2 ;
println result3 ;
return 99
end
int result = call main() ;
exit result
end

View File

@@ -0,0 +1,27 @@
# import sum, main from ../sum.wacc
# Output:
# 15
# -33
# 0
# 0
#
# Exit:
# 0
# Program:
import "../sum.wacc" (sum, main as sumMain)
begin
int main() is
int result = call sum(-10, -23) ;
println result ;
return 0
end
int result1 = call sumMain() ;
int result2 = call main() ;
println result1 ;
println result2
end

View File

@@ -0,0 +1,27 @@
# simple sum program
# Output:
# 15
#
# Exit:
# 0
# Program:
begin
int sum(int a, int b) is
return a + b
end
int main() is
int a = 5 ;
int b = 10 ;
int result = call sum(a, b) ;
println result ;
return 0
end
int result = call main() ;
exit result
end

View File

@@ -26,6 +26,15 @@ class ParallelExamplesSpec extends AsyncFreeSpec with AsyncIOSpec with BeforeAnd
} ++
allWaccFiles("wacc-examples/invalid/whack").map { p =>
(p.toString, List(100, 200))
} ++
allWaccFiles("extension/examples/valid").map { p =>
(p.toString, List(0))
} ++
allWaccFiles("extension/examples/invalid/syntax").map { p =>
(p.toString, List(100))
} ++
allWaccFiles("extension/examples/invalid/semantics").map { p =>
(p.toString, List(200))
}
forEvery(files) { (filename, expectedResult) =>
@@ -33,6 +42,9 @@ class ParallelExamplesSpec extends AsyncFreeSpec with AsyncIOSpec with BeforeAnd
s"$filename" - {
"should be compiled with correct result" in {
if (fileIsPendingFrontend(filename))
IO.pure(pending)
else
compileWacc(Path.of(filename), outputDir = None, log = false).map { result =>
expectedResult should contain(result)
}
@@ -41,10 +53,10 @@ class ParallelExamplesSpec extends AsyncFreeSpec with AsyncIOSpec with BeforeAnd
if (expectedResult == List(0)) {
"should run with correct result" in {
if (fileIsDisallowedBackend(filename))
IO.pure(
succeed
) // TODO: remove when advanced tests removed. not sure how to "pending" this otherwise
else {
IO.pure(succeed)
else if (fileIsPendingBackend(filename))
IO.pure(pending)
else
for {
contents <- IO(Source.fromFile(File(filename)).getLines.toList)
inputLine = extractInput(contents)
@@ -79,16 +91,26 @@ class ParallelExamplesSpec extends AsyncFreeSpec with AsyncIOSpec with BeforeAnd
}
}
}
}
def allWaccFiles(dir: String): IndexedSeq[os.Path] =
val d = java.io.File(dir)
os.walk(os.Path(d.getAbsolutePath)).filter(_.ext == "wacc")
// TODO: eventually remove this I think
def fileIsDisallowedBackend(filename: String): Boolean =
Seq(
"^.*wacc-examples/valid/advanced.*$"
private def fileIsDisallowedBackend(filename: String): Boolean =
filename.matches("^.*wacc-examples/valid/advanced.*$")
private def fileIsPendingFrontend(filename: String): Boolean =
List(
"^.*extension/examples/invalid/syntax/imports/importBadSyntax.*$",
"^.*extension/examples/invalid/semantics/imports.*$",
"^.*extension/examples/valid/imports.*$"
).exists(filename.matches)
private def fileIsPendingBackend(filename: String): Boolean =
List(
"^.*extension/examples/invalid/syntax/imports.*$",
"^.*extension/examples/invalid/semantics/imports.*$",
"^.*extension/examples/valid/imports.*$"
).exists(filename.matches)
private def extractInput(contents: List[String]): String =