test: integration tests for imports
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,4 +4,3 @@
|
||||
.vscode/
|
||||
wacc-examples/
|
||||
.idea/
|
||||
|
||||
|
||||
10
extension/examples/invalid/semantics/badWacc.wacc
Normal file
10
extension/examples/invalid/semantics/badWacc.wacc
Normal 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
|
||||
@@ -0,0 +1,6 @@
|
||||
import "./doesNotExist.wacc" (main)
|
||||
|
||||
begin
|
||||
int result = call main() ;
|
||||
exit result
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
import "../../../valid/sum.wacc" (mult)
|
||||
|
||||
begin
|
||||
int result = call mult(3, 2) ;
|
||||
exit result
|
||||
end
|
||||
@@ -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
|
||||
@@ -0,0 +1,6 @@
|
||||
import "./importBadSem.wacc" (sum)
|
||||
|
||||
begin
|
||||
int result = call sum(1, 2) ;
|
||||
exit result
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
import "../../../valid/imports/basic.wacc" (sum)
|
||||
|
||||
begin
|
||||
int result = call sum(3, 2) ;
|
||||
exit result
|
||||
end
|
||||
6
extension/examples/invalid/syntax/badWacc.wacc
Normal file
6
extension/examples/invalid/syntax/badWacc.wacc
Normal file
@@ -0,0 +1,6 @@
|
||||
int main() is
|
||||
println "Hello World!" ;
|
||||
return 0
|
||||
end
|
||||
|
||||
skip
|
||||
@@ -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
|
||||
@@ -0,0 +1,5 @@
|
||||
import "../../../valid/sum.wacc" ()
|
||||
|
||||
begin
|
||||
exit 0
|
||||
end
|
||||
@@ -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
|
||||
@@ -0,0 +1,6 @@
|
||||
import "./importBadSyntax.wacc" (sum)
|
||||
|
||||
begin
|
||||
int result = call sum(1, 2) ;
|
||||
exit result
|
||||
end
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,5 @@
|
||||
import "../../../valid/sum.wacc" *
|
||||
|
||||
begin
|
||||
exit 0
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
import "../../../valid/sum.wacc" (*)
|
||||
|
||||
begin
|
||||
exit 0
|
||||
end
|
||||
7
extension/examples/valid/.gitignore
vendored
Normal file
7
extension/examples/valid/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
*
|
||||
|
||||
!imports/
|
||||
imports/*
|
||||
|
||||
!.gitignore
|
||||
!*.wacc
|
||||
22
extension/examples/valid/imports/alias.wacc
Normal file
22
extension/examples/valid/imports/alias.wacc
Normal 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
|
||||
20
extension/examples/valid/imports/basic.wacc
Normal file
20
extension/examples/valid/imports/basic.wacc
Normal 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
|
||||
34
extension/examples/valid/imports/manyMains.wacc
Normal file
34
extension/examples/valid/imports/manyMains.wacc
Normal 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
|
||||
27
extension/examples/valid/imports/mutliFunc.wacc
Normal file
27
extension/examples/valid/imports/mutliFunc.wacc
Normal 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
|
||||
27
extension/examples/valid/sum.wacc
Normal file
27
extension/examples/valid/sum.wacc
Normal 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
|
||||
@@ -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,18 +42,21 @@ class ParallelExamplesSpec extends AsyncFreeSpec with AsyncIOSpec with BeforeAnd
|
||||
|
||||
s"$filename" - {
|
||||
"should be compiled with correct result" in {
|
||||
compileWacc(Path.of(filename), outputDir = None, log = false).map { result =>
|
||||
expectedResult should contain(result)
|
||||
}
|
||||
if (fileIsPendingFrontend(filename))
|
||||
IO.pure(pending)
|
||||
else
|
||||
compileWacc(Path.of(filename), outputDir = None, log = false).map { result =>
|
||||
expectedResult should contain(result)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -75,7 +87,6 @@ class ParallelExamplesSpec extends AsyncFreeSpec with AsyncIOSpec with BeforeAnd
|
||||
exitCode shouldBe expectedExit
|
||||
normalizeOutput(stdout.toString) shouldBe expectedOutput
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,10 +96,21 @@ class ParallelExamplesSpec extends AsyncFreeSpec with AsyncIOSpec with BeforeAnd
|
||||
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 =
|
||||
|
||||
Reference in New Issue
Block a user