diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-05-05 11:28:51 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-08-19 15:37:22 +0200 |
commit | 29cf43bca7e478f290e7c39a05ce7e8bcb218d3d (patch) | |
tree | 700e755e13f296728094831d6ab204df12d017df /dottydoc/jvm/test/CompilerTest.scala | |
parent | b4622aabd0ebd6929639c9cfcd3c7845a250598f (diff) | |
download | dotty-29cf43bca7e478f290e7c39a05ce7e8bcb218d3d.tar.gz dotty-29cf43bca7e478f290e7c39a05ce7e8bcb218d3d.tar.bz2 dotty-29cf43bca7e478f290e7c39a05ce7e8bcb218d3d.zip |
Add JUnit test structure for testing the DocPhase
Diffstat (limited to 'dottydoc/jvm/test/CompilerTest.scala')
-rw-r--r-- | dottydoc/jvm/test/CompilerTest.scala | 47 |
1 files changed, 47 insertions, 0 deletions
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) + } +} |