From 29cf43bca7e478f290e7c39a05ce7e8bcb218d3d Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Thu, 5 May 2016 11:28:51 +0200 Subject: Add JUnit test structure for testing the DocPhase --- .../jvm/src/dotty/tools/dottydoc/DottyDoc.scala | 8 ++-- dottydoc/jvm/test/CompilerTest.scala | 47 ++++++++++++++++++++++ dottydoc/jvm/test/TestCommentParsing.scala | 9 +++++ dottydoc/jvm/test/WhitelistedStdLib.scala | 12 +++--- project/Build.scala | 4 +- project/plugins.sbt | 2 + 6 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 dottydoc/jvm/test/CompilerTest.scala create mode 100644 dottydoc/jvm/test/TestCommentParsing.scala diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala index 428bc17d8..1fb93d961 100644 --- a/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala +++ b/dottydoc/jvm/src/dotty/tools/dottydoc/DottyDoc.scala @@ -31,10 +31,10 @@ class DottyDocCompiler extends Compiler { List(new DocPhase) :: Nil - override def newRun(implicit ctx: Context): Run = { - reset() - new DocRun(this)(rootContext) - } + override def newRun(implicit ctx: Context): Run = { + reset() + new DocRun(this)(rootContext) + } } class DocRun(comp: Compiler)(implicit ctx: Context) extends Run(comp)(ctx) { diff --git a/dottydoc/jvm/test/CompilerTest.scala b/dottydoc/jvm/test/CompilerTest.scala new file mode 100644 index 000000000..4cafc72e0 --- /dev/null +++ b/dottydoc/jvm/test/CompilerTest.scala @@ -0,0 +1,47 @@ +package dotty.tools +package dottydoc + +import dotc.core.Contexts +import Contexts.{ Context, ContextBase } +import dotc.core.Phases.Phase +import dotc.typer.FrontEnd +import dottydoc.core.Phases.DocPhase + +trait DottyTest { + dotty.tools.dotc.parsing.Scanners // initialize keywords + + implicit var ctx: Contexts.Context = { + val base = new ContextBase + import base.settings._ + val ctx = base.initialCtx.fresh + ctx.setSetting(ctx.settings.YkeepComments, true) + base.initialize()(ctx) + ctx + } + + private def compilerWithChecker(assertion: DocPhase => Unit) = new DottyDocCompiler { + val docPhase = new DocPhase + override def phases = + List(new FrontEnd) :: + List(docPhase) :: + List(new Phase { + def phaseName = "assertionPhase" + override def run(implicit ctx: Context): Unit = assertion(docPhase) + }) :: + Nil + } + + def checkCompile(source: String)(assertion: DocPhase => Unit): Unit = { + val c = compilerWithChecker(assertion) + c.rootContext(ctx) + val run = c.newRun + run.compile(source) + } + + def checkCompile(sources:List[String])(assertion: DocPhase => Unit): Unit = { + val c = compilerWithChecker(assertion) + c.rootContext(ctx) + val run = c.newRun + run.compile(sources) + } +} diff --git a/dottydoc/jvm/test/TestCommentParsing.scala b/dottydoc/jvm/test/TestCommentParsing.scala new file mode 100644 index 000000000..16e855957 --- /dev/null +++ b/dottydoc/jvm/test/TestCommentParsing.scala @@ -0,0 +1,9 @@ +package dotty.tools +package dottydoc + +import org.junit.Test +import org.junit.Assert._ + +class TestWhitelistedCollections extends DottyTest { + @Test def test = assert(false) +} diff --git a/dottydoc/jvm/test/WhitelistedStdLib.scala b/dottydoc/jvm/test/WhitelistedStdLib.scala index 8ba8f2b89..2ab832870 100644 --- a/dottydoc/jvm/test/WhitelistedStdLib.scala +++ b/dottydoc/jvm/test/WhitelistedStdLib.scala @@ -3,10 +3,11 @@ package dottydoc import scala.io.Source -object WhitelistedStdLib extends DottyDoc { - override def main(args: Array[String]) = { +object WhitelistedStandardLib extends DottyDoc { + val files: Array[String] = { val whitelist = "../../test/dotc/scala-collections.whitelist" - val stdlibFiles = Source.fromFile(whitelist, "UTF8") + + Source.fromFile(whitelist, "UTF8") .getLines() .map(_.trim) // allow identation .filter(!_.startsWith("#")) // allow comment lines prefixed by # @@ -15,7 +16,8 @@ object WhitelistedStdLib extends DottyDoc { .filterNot(_.endsWith("package.scala")) .map("../." + _) .toArray - - super.main("-language:Scala2" +: stdlibFiles) } + + override def main(args: Array[String]) = + super.main("-language:Scala2" +: files) } diff --git a/project/Build.scala b/project/Build.scala index 6b9939a34..add3ebecb 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -268,7 +268,6 @@ object DottyInjectedPlugin extends AutoPlugin { .jsSettings( libraryDependencies ++= Seq( "org.scala-js" %%% "scalajs-dom" % "0.9.0", - "com.github.benhutchison" %%% "microjson" % "1.3", "com.github.benhutchison" %%% "prickle" % "1.1.10", "com.lihaoyi" %%% "scalatags" % "0.5.5" ) @@ -287,7 +286,8 @@ object DottyInjectedPlugin extends AutoPlugin { libraryDependencies ++= Seq( "org.scala-js" % "scalajs-dom_sjs0.6_2.11" % "0.9.0", "com.github.benhutchison" %% "prickle" % "1.1.10", - "com.lihaoyi" %% "scalatags" % "0.5.5" + "com.lihaoyi" %% "scalatags" % "0.5.5", + "com.novocode" % "junit-interface" % "0.11" % "test" ), // enable improved incremental compilation algorithm diff --git a/project/plugins.sbt b/project/plugins.sbt index 57bd46581..8ac4d69bf 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -8,3 +8,5 @@ addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0") addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.8") + +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5") -- cgit v1.2.3