Disabled external gits
This commit is contained in:
59
cs420-acc/l3-compiler/compiler/test/l3/ExamplesTests.scala
Normal file
59
cs420-acc/l3-compiler/compiler/test/l3/ExamplesTests.scala
Normal file
@@ -0,0 +1,59 @@
|
||||
package l3
|
||||
|
||||
import java.io.{ ByteArrayInputStream }
|
||||
import java.nio.file.{ Files, Paths, Path }
|
||||
import java.nio.charset.StandardCharsets.UTF_8
|
||||
|
||||
import scala.util.Using.{resource => using}
|
||||
|
||||
import utest._
|
||||
|
||||
import SymbolicCL3TreeModule.Tree
|
||||
|
||||
trait ExamplesTests {
|
||||
val backEnd: Tree => TerminalPhaseResult
|
||||
|
||||
def compileAndRun(fileName: String, input: String): Either[String, String] = {
|
||||
using(new ByteArrayInputStream(input.getBytes(UTF_8))) { inS =>
|
||||
val in0 = System.in
|
||||
try {
|
||||
System.setIn(inS)
|
||||
L3Tester.compileAndRun(backEnd)(Seq(fileName))
|
||||
} finally {
|
||||
System.setIn(in0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def readFile(fileName: String): String =
|
||||
new String(Files.readAllBytes(Paths.get(fileName)), UTF_8)
|
||||
|
||||
def testExpectedOutput(implicit path: utest.framework.TestPath) = {
|
||||
val testName = path.value.last
|
||||
val input = readFile(s"../tests/${testName}.in")
|
||||
val expectedOut = readFile(s"../tests/${testName}.out")
|
||||
assertMatch(compileAndRun(s"../examples/${testName}.l3m", input)) {
|
||||
case Right(s: String) if s == expectedOut =>
|
||||
}
|
||||
}
|
||||
|
||||
val tests = Tests {
|
||||
// Note: sudoku is too slow to be included here
|
||||
test("bignums") { testExpectedOutput }
|
||||
test("maze") { testExpectedOutput }
|
||||
test("queens") { testExpectedOutput }
|
||||
test("unimaze") { testExpectedOutput }
|
||||
}
|
||||
}
|
||||
|
||||
object ExamplesTests1 extends TestSuite with ExamplesTests {
|
||||
val backEnd = L3Tester.backEnd1
|
||||
}
|
||||
|
||||
object ExamplesTests2 extends TestSuite with ExamplesTests {
|
||||
val backEnd = L3Tester.backEnd2
|
||||
}
|
||||
|
||||
object ExamplesTests3 extends TestSuite with ExamplesTests {
|
||||
val backEnd = L3Tester.backEnd3
|
||||
}
|
58
cs420-acc/l3-compiler/compiler/test/l3/L3Tester.scala
Normal file
58
cs420-acc/l3-compiler/compiler/test/l3/L3Tester.scala
Normal file
@@ -0,0 +1,58 @@
|
||||
package l3
|
||||
|
||||
import java.io.{ ByteArrayOutputStream, PrintStream }
|
||||
import java.nio.file.{ Paths }
|
||||
|
||||
import scala.util.Using.{resource => using}
|
||||
|
||||
import SymbolicCL3TreeModule.Tree
|
||||
|
||||
object L3Tester {
|
||||
def compile[T](backEnd: Tree => Either[String, T])
|
||||
(inFileNames: Seq[String]): Either[String, T] = {
|
||||
val basePath = Paths.get(".").toAbsolutePath.normalize
|
||||
Right(inFileNames)
|
||||
.flatMap(L3FileReader.readFilesExpandingModules(basePath, _))
|
||||
.flatMap(p => L3Parser.parse(p._1, p._2))
|
||||
.flatMap(CL3NameAnalyzer)
|
||||
.flatMap(backEnd)
|
||||
}
|
||||
|
||||
def compileNoFail[T](backEnd: Tree => T)
|
||||
(inFileNames: Seq[String]): Either[String, T] =
|
||||
compile(t => Right(backEnd(t)))(inFileNames)
|
||||
|
||||
def compileAndRun(backEnd: Tree => TerminalPhaseResult)
|
||||
(inFileNames: Seq[String]): Either[String, String] = {
|
||||
def outputCapturingBackend(t: Tree): Either[String, String] = {
|
||||
val outBS = new ByteArrayOutputStream()
|
||||
using(new PrintStream(outBS)) { outPS =>
|
||||
val out0 = System.out
|
||||
try {
|
||||
System.setOut(outPS)
|
||||
backEnd(t)
|
||||
.flatMap(_ => Right(outBS.toString("UTF-8")))
|
||||
} finally {
|
||||
System.setOut(out0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compile(outputCapturingBackend(_))(inFileNames)
|
||||
}
|
||||
|
||||
val backEnd1 = (
|
||||
CL3Interpreter
|
||||
)
|
||||
|
||||
val backEnd2 = (
|
||||
CL3ToCPSTranslator
|
||||
andThen CPSInterpreterHigh
|
||||
)
|
||||
|
||||
val backEnd3 = (
|
||||
CL3ToCPSTranslator
|
||||
andThen CPSValueRepresenter
|
||||
andThen CPSInterpreterLowNoCC
|
||||
)
|
||||
}
|
95
cs420-acc/l3-compiler/compiler/test/l3/SyntheticTests.scala
Normal file
95
cs420-acc/l3-compiler/compiler/test/l3/SyntheticTests.scala
Normal file
@@ -0,0 +1,95 @@
|
||||
package l3
|
||||
|
||||
import utest._
|
||||
|
||||
import SymbolicCL3TreeModule.Tree
|
||||
|
||||
trait SyntheticTests {
|
||||
val backEnd: Tree => TerminalPhaseResult
|
||||
|
||||
def compileAndRun(inFileNames: String*): Either[String, String] =
|
||||
L3Tester.compileAndRun(backEnd)(inFileNames)
|
||||
|
||||
// Validate the output of a self-validating test.
|
||||
def isValidTestResult(s: String): Boolean =
|
||||
! s.isEmpty && (s == ((s(0) +: ('A' to s(0))).mkString))
|
||||
|
||||
def testSelfValidatingOutput(implicit path: utest.framework.TestPath) = {
|
||||
val testFileName = "../tests/" + path.value.last.split(" ")(0) + ".l3"
|
||||
assertMatch(compileAndRun(testFileName)) {
|
||||
case Right(s: String) if isValidTestResult(s) =>
|
||||
}
|
||||
}
|
||||
|
||||
val tests = Tests {
|
||||
test("primitives") {
|
||||
// Block primitives
|
||||
test("prim-blockp (@block?)"){ testSelfValidatingOutput }
|
||||
test("prim-block-alloc (@block-alloc-0)"){ testSelfValidatingOutput }
|
||||
test("prim-block-tag (@block-tag)"){ testSelfValidatingOutput }
|
||||
test("prim-block-length (@block-length)"){ testSelfValidatingOutput }
|
||||
test("prim-block-get-set (@block-[sg]et,)"){ testSelfValidatingOutput }
|
||||
|
||||
// Integer primitives
|
||||
test("prim-intp (@int?)"){ testSelfValidatingOutput }
|
||||
test("prim-add (@+)"){ testSelfValidatingOutput }
|
||||
test("prim-sub (@-)"){ testSelfValidatingOutput }
|
||||
test("prim-mul (@*)"){ testSelfValidatingOutput }
|
||||
test("prim-div (@/)"){ testSelfValidatingOutput }
|
||||
test("prim-mod (@%)"){ testSelfValidatingOutput }
|
||||
test("prim-shift-left (@shift-left)"){ testSelfValidatingOutput }
|
||||
test("prim-shift-right (@shift-right)"){ testSelfValidatingOutput }
|
||||
test("prim-and (@and)"){ testSelfValidatingOutput }
|
||||
test("prim-or (@or)"){ testSelfValidatingOutput }
|
||||
test("prim-xor (@xor)"){ testSelfValidatingOutput }
|
||||
test("prim-lt (@<)"){ testSelfValidatingOutput }
|
||||
test("prim-le (@<=)"){ testSelfValidatingOutput }
|
||||
test("prim-int-to-char (@int->char)"){ testSelfValidatingOutput }
|
||||
|
||||
// Character primitives
|
||||
test("prim-charp (@char?)"){ testSelfValidatingOutput }
|
||||
test("prim-char-to-int (@char->int)"){ testSelfValidatingOutput }
|
||||
|
||||
// Boolean primitives
|
||||
test("prim-boolp (@bool?)"){ testSelfValidatingOutput }
|
||||
|
||||
// Unit primitives
|
||||
test("prim-unitp (@unit?)"){ testSelfValidatingOutput }
|
||||
|
||||
// Primitives on arbitrary values
|
||||
test("prim-eq (@=)"){ testSelfValidatingOutput }
|
||||
}
|
||||
|
||||
test("expressions") {
|
||||
test("expr-let (let …)"){ testSelfValidatingOutput }
|
||||
test("expr-lets (let* …)"){ testSelfValidatingOutput }
|
||||
test("expr-letrec (letrec …)"){ testSelfValidatingOutput }
|
||||
test("expr-rec (rec …)"){ testSelfValidatingOutput }
|
||||
test("expr-fun (fun …)"){ testSelfValidatingOutput }
|
||||
test("expr-begin (begin …)"){ testSelfValidatingOutput }
|
||||
test("expr-if (if …)"){ testSelfValidatingOutput }
|
||||
test("expr-cond (cond …)"){ testSelfValidatingOutput }
|
||||
test("expr-and (and …)"){ testSelfValidatingOutput }
|
||||
test("expr-or (or …)"){ testSelfValidatingOutput }
|
||||
test("expr-not (not …)"){ testSelfValidatingOutput }
|
||||
}
|
||||
|
||||
test("statements") {
|
||||
test("stmt-def (def …)"){ testSelfValidatingOutput }
|
||||
test("stmt-defrec (defrec …)"){ testSelfValidatingOutput }
|
||||
test("stmt-halt (halt …)"){ testSelfValidatingOutput }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object SyntheticTests1 extends TestSuite with SyntheticTests {
|
||||
val backEnd = L3Tester.backEnd1
|
||||
}
|
||||
|
||||
object SyntheticTests2 extends TestSuite with SyntheticTests {
|
||||
val backEnd = L3Tester.backEnd2
|
||||
}
|
||||
|
||||
object SyntheticTests3 extends TestSuite with SyntheticTests {
|
||||
val backEnd = L3Tester.backEnd3
|
||||
}
|
Reference in New Issue
Block a user