aboutsummaryrefslogblamecommitdiff
path: root/test/test/CompilerTest.scala
blob: 09112be2f7d9ea40843d3c9e16c7bb7ee0bba242 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12




                                          
                                             





                                          






                                                                                           





                                                                                                       


















                                                                                    
 
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 =
    if (args.exists(_.startsWith("#")))
      Bench.main(args ++ defaultOptions)
    else {
      val nerrors = Main.process(args ++ defaultOptions).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 = {
    val dir = Directory(path)
    val fileNames = dir.files.toArray.map(_.toString).filter(_ endsWith ".scala")
    compileArgs(fileNames ++ args, xerrors)
  }

}
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")
}