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