aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-11-18 19:27:18 +0100
committerMartin Odersky <odersky@gmail.com>2013-11-18 19:27:36 +0100
commitacc9d750d1776d8d1c864fb3ddaadbaec34d286e (patch)
treec5129664583164aef17f0c42a634ae9e6dbf8e62 /src
parentb6d7b28403c34f61c5317c37acce1b4118a4181c (diff)
downloaddotty-acc9d750d1776d8d1c864fb3ddaadbaec34d286e.tar.gz
dotty-acc9d750d1776d8d1c864fb3ddaadbaec34d286e.tar.bz2
dotty-acc9d750d1776d8d1c864fb3ddaadbaec34d286e.zip
Added unit testing support
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/Driver.scala19
-rw-r--r--src/dotty/tools/dotc/Main.scala11
-rw-r--r--src/dotty/tools/dotc/Run.scala8
3 files changed, 25 insertions, 13 deletions
diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala
index 13604d9cc..e5e031e79 100644
--- a/src/dotty/tools/dotc/Driver.scala
+++ b/src/dotty/tools/dotc/Driver.scala
@@ -3,6 +3,7 @@ package dotty.tools.dotc
import config.CompilerCommand
import core.Contexts.{Context, ContextBase}
import core.DotClass
+import reporting._
abstract class Driver extends DotClass {
@@ -10,33 +11,37 @@ abstract class Driver extends DotClass {
protected def newCompiler(): Compiler
- protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context) =
+ protected def emptyReporter = new StoreReporter
+
+ protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
if (fileNames.nonEmpty) {
val run = compiler.newRun
run.compile(fileNames)
run.printSummary()
- }
+ } else emptyReporter
protected def initCtx = (new ContextBase).initialCtx
- def process(args: Array[String]): Boolean = {
+ def process(args: Array[String]): Reporter = {
val summary = CompilerCommand.distill(args)(initCtx)
implicit val ctx = initCtx.fresh.withSettings(summary.sstate)
val fileNames = CompilerCommand.checkUsage(summary)
try {
doCompile(newCompiler(), fileNames)
- !ctx.reporter.hasErrors
} catch {
case ex: Throwable =>
ex match {
- case ex: FatalError => ctx.error(ex.getMessage); false // signals that we should fail compilation.
- case _ => throw ex // unexpected error, tell the outside world.
+ case ex: FatalError =>
+ ctx.error(ex.getMessage) // signals that we should fail compilation.
+ ctx.typerState.reporter
+ case _ =>
+ throw ex // unexpected error, tell the outside world.
}
}
}
def main(args: Array[String]): Unit =
- sys.exit(if (process(args)) 1 else 0)
+ sys.exit(if (process(args).hasErrors) 1 else 0)
}
class FatalError(msg: String) extends Exception
diff --git a/src/dotty/tools/dotc/Main.scala b/src/dotty/tools/dotc/Main.scala
index 627fc0cfa..ddb422a0d 100644
--- a/src/dotty/tools/dotc/Main.scala
+++ b/src/dotty/tools/dotc/Main.scala
@@ -6,9 +6,10 @@ package dotty.tools
package dotc
import core.Contexts.Context
+import reporting.Reporter
object Main extends Driver {
- def resident(compiler: Compiler): Unit = unsupported("resident") /*loop { line =>
+ def resident(compiler: Compiler): Reporter = unsupported("resident") /*loop { line =>
val command = new CompilerCommand(line split "\\s+" toList, new Settings(scalacError))
compiler.reporter.reset()
new compiler.Run() compile command.files
@@ -16,8 +17,10 @@ object Main extends Driver {
override def newCompiler(): Compiler = new Compiler
- override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Unit = {
- if (new config.Settings.Setting.SettingDecorator[Boolean](ctx.base.settings.resident).value(ctx)) resident(compiler)
- else super.doCompile(compiler, fileNames)
+ override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = {
+ if (new config.Settings.Setting.SettingDecorator[Boolean](ctx.base.settings.resident).value(ctx))
+ resident(compiler)
+ else
+ super.doCompile(compiler, fileNames)
}
}
diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala
index b12511478..c662aabfa 100644
--- a/src/dotty/tools/dotc/Run.scala
+++ b/src/dotty/tools/dotc/Run.scala
@@ -5,6 +5,7 @@ import core._
import Contexts._, Periods._, Symbols._
import io.PlainFile
import util.{SourceFile, NoSource, Stats, SimpleMap}
+import reporting.Reporter
class Run(comp: Compiler)(implicit ctx: Context) {
@@ -28,8 +29,11 @@ class Run(comp: Compiler)(implicit ctx: Context) {
}
}
- def printSummary(): Unit = {
- ctx.typerState.reporter.printSummary
+ /** Print summary; return # of errors encountered */
+ def printSummary(): Reporter = {
Constraint.printMax()
+ val r = ctx.typerState.reporter
+ r.printSummary
+ r
}
} \ No newline at end of file