From acc9d750d1776d8d1c864fb3ddaadbaec34d286e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 18 Nov 2013 19:27:18 +0100 Subject: Added unit testing support --- src/dotty/tools/dotc/Driver.scala | 19 ++++++++++++------- src/dotty/tools/dotc/Main.scala | 11 +++++++---- src/dotty/tools/dotc/Run.scala | 8 ++++++-- 3 files changed, 25 insertions(+), 13 deletions(-) (limited to 'src/dotty/tools/dotc') 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 -- cgit v1.2.3