Skip to content

Commit

Permalink
Add back args handling + missing printing + files printing + introduc…
Browse files Browse the repository at this point in the history
…e MkInMemoryTestFile
  • Loading branch information
dwijnand committed Oct 4, 2020
1 parent 9fca6c0 commit c99ff6a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
39 changes: 30 additions & 9 deletions src/main/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import scala.util.chaining._

import scala.meta._

import shisa.testdata._

object Main {
val cwdAbs = Paths.get("").toAbsolutePath
val targetDir = Paths.get("target")
Expand All @@ -36,19 +38,31 @@ object Main {
FreshCompiler3("3.1", "-source 3.1"),
)

val inMemoryTestFiles = List(Call_##, Call_pos).map { mk =>
InMemoryTestFile(mk.path, mk.outerPrelude, mk.innerPrelude, mk.testStats)
}
val inMemoryTestFilesMap = inMemoryTestFiles.map(tf => tf.src -> tf).toMap

def main(args: Array[String]): Unit = {
val sourceFiles = args.toList match {
case Nil => Files.find(Paths.get("testdata"), /* maxDepth = */ 10, (p, _) => s"$p".endsWith(".scala")).toScala(List).sorted
case xs => xs.map(Paths.get(_)).map(p => if (p.isAbsolute) cwdAbs.relativize(p) else p)
val testFiles = args.toList match {
case Nil =>
val realTestFiles = Files.find(Paths.get("testdata"), 10, (p, _) => s"$p".endsWith(".scala")).toScala(List)
.map(p => if (p.isAbsolute) cwdAbs.relativize(p) else p)
.map(RealTestFile(_))
(realTestFiles ::: inMemoryTestFiles).sortBy(_.src)
.tap(fs => println(s"Files: ${fs.map(_.src).mkString("[", ", ", "]")}"))
case xs => xs
.map(Paths.get(_))
.map(p => if (p.isAbsolute) cwdAbs.relativize(p) else p)
.map(p => inMemoryTestFilesMap.getOrElse(p, RealTestFile(p)))
}

if (Files.exists(Paths.get("target/testdata")))
IOUtil.deleteRecursive(Paths.get("target/testdata"))
val missing = testFiles.collect { case RealTestFile(p) if !Files.exists(p) => p }
if (missing.nonEmpty)
sys.error(s"Missing test files: ${missing.mkString("[", ", ", "]")}")

val testFiles =
testdata.Call_##.testFile ::
testdata.Call_pos.testFile ::
sourceFiles.map(RealTestFile(_))
if (Files.exists(Paths.get("tests/testdata")))
IOUtil.deleteRecursive(Paths.get("tests/testdata"))

val pool = Executors.newFixedThreadPool(Runtime.getRuntime.availableProcessors)
val futures = testFiles.map(f => pool.submit[Unit](() => compile1(f, mkCompilers)))
Expand Down Expand Up @@ -152,6 +166,13 @@ final case class InMemoryTestFile(
testStats: List[List[Stat]],
) extends TestFile

trait MkInMemoryTestFile {
def path: Path
def outerPrelude: List[List[Defn]]
def innerPrelude: List[Defn]
def testStats: List[List[Stat]]
}

sealed abstract class CompileFile(src: Path) {
val name = src.getFileName.toString.stripSuffix(".scala").stripSuffix(".lines")
val dir = src.resolveSibling(name)
Expand Down
6 changes: 3 additions & 3 deletions src/main/testdata/Call_##.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import java.nio.file._

import scala.meta._

object Call_## {
object Call_## extends MkInMemoryTestFile {
val path = Paths.get("testdata/Call.##.scala")

val variants = List(q"any" -> t"Any", q"ref" -> t"AnyRef")

val outerPrelude = Nil

val innerPrelude = variants.map { case (nme, tpe) =>
Defn.Val(Nil, List(Pat.Var(nme)), Some(tpe), Lit.String(""))
}

val testStats = variants.map { case (nme, _) => List(q"$nme.##", q"$nme.##()") }

val testFile = InMemoryTestFile(path, outerPrelude = Nil, innerPrelude, testStats)
}
4 changes: 1 addition & 3 deletions src/main/testdata/Call_pos.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.nio.file._

import scala.meta._

object Call_pos {
object Call_pos extends MkInMemoryTestFile {
val path = Paths.get("testdata/Call.pos.scala")

val vals = List(
Expand Down Expand Up @@ -61,6 +61,4 @@ object Call_pos {

def toStrings(r: Term) = duo(r, q"toString") ::: duo(alt(r, 'S'), q"toString") ::: duo(alt(r, 'J'), q"toString")
def toStringsAndRun(r: Term) = duo(r, q"run") ::: toStrings(r)

val testFile = InMemoryTestFile(path, outerPrelude, innerPrelude, testStats)
}

0 comments on commit c99ff6a

Please sign in to comment.