aboutsummaryrefslogtreecommitdiff
path: root/test/test/CompilerTest.scala
blob: d52e74de7b9e7aae5438ed75c9905c8a4d28ae3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package test

import scala.reflect.io._
import org.junit.Test
import scala.collection.mutable.ListBuffer
import dotty.tools.dotc.{Main, Bench, Driver}
import dotty.tools.dotc.reporting.Reporter

class CompilerTest extends DottyTest {

  def defaultOptions: List[String] = Nil

  def compileArgs(args: Array[String], xerrors: Int = 0): Unit = {
    val allArgs = args ++ defaultOptions
    val processor = if (allArgs.exists(_.startsWith("#"))) Bench else Main
    val nerrors = processor.process(allArgs, ctx).count(Reporter.ERROR.level)
    assert(nerrors == xerrors, s"Wrong # of errors. Expected: $xerrors, found: $nerrors")
  }

  def compileLine(cmdLine: String, xerrors: Int = 0): Unit = compileArgs(cmdLine.split("\n"), xerrors)

  def compileFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0): Unit =
    compileArgs((s"$prefix$fileName.scala" :: args).toArray, xerrors)

  def compileDir(path: String, args: List[String] = Nil, xerrors: Int = 0): Unit =
    compileDir(Directory(path), args, xerrors)

  def compileDir(dir: Directory, args: List[String], xerrors: Int): Unit = {
    val fileNames = dir.files.toArray.map(_.toString).filter(_ endsWith ".scala")
    compileArgs(fileNames ++ args, xerrors)
  }

  def compileFiles(path: String, args: List[String] = Nil): Unit = {
    val dir = Directory(path)
    val fileNames = dir.files.toArray.map(_.toString).filter(_ endsWith ".scala")
    for (name <- fileNames) {
      println(s"testing $name")
      compileArgs((name :: args).toArray, 0)
    }
    for (subdir <- dir.dirs) {
      println(s"testing $subdir")
      compileDir(subdir, args, 0)
    }
  }
}
object CompilerText extends App {

//  val dotcDir = "/Users/odersky/workspace/dotty/src/dotty/"

//  new CompilerTest().compileFile(dotcDir + "tools/dotc/", "CompilationUnit")
//  new CompilerTest().compileFile(dotcDir + "tools/dotc/", "Compiler")
//  new CompilerTest().compileFile(dotcDir + "tools/dotc/", "Driver")
//  new CompilerTest().compileFile(dotcDir + "tools/dotc/", "Main")
//  new CompilerTest().compileFile(dotcDir + "tools/dotc/", "Run")

//  new CompilerTest().compileDir(dotcDir + "tools/dotc")
 // new CompilerTest().compileFile(dotcDir + "tools/dotc/", "Run")
}