aboutsummaryrefslogtreecommitdiff
path: root/test/test/DottyTest.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/test/DottyTest.scala')
-rw-r--r--test/test/DottyTest.scala25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/test/DottyTest.scala b/test/test/DottyTest.scala
index f2d3ef92e..07b29a5f0 100644
--- a/test/test/DottyTest.scala
+++ b/test/test/DottyTest.scala
@@ -8,6 +8,11 @@ import Types._, Symbols._, Decorators._
import dotty.tools.dotc.printing.Texts._
import dotty.tools.dotc.reporting.ConsoleReporter
import dotty.tools.dotc.core.Decorators._
+import dotty.tools.dotc.ast.tpd
+import dotty.tools.dotc.Compiler
+
+import dotty.tools.dotc
+import dotty.tools.dotc.core.Phases.Phase
class DottyTest {
@@ -33,6 +38,26 @@ class DottyTest {
ctx
}
+ def checkCompile(checkAfterPhase: String, source:String)(assertion:tpd.Tree =>Unit): Unit = {
+ val c = new Compiler {
+ override def phases = {
+ val allPhases = super.phases
+ val targetPhase = allPhases.find{p=> p.name == checkAfterPhase}
+ assert(targetPhase isDefined)
+ val phasesBefore = allPhases.takeWhile(x=> ! (x eq targetPhase.get))
+
+ val checker = new Phase{
+ def name = "assertionChecker"
+ override def run(implicit ctx: Context): Unit = assertion(ctx.compilationUnit.tpdTree)
+ }
+ phasesBefore:::List(targetPhase.get, checker)
+ }
+ }
+ c.rootContext(ctx)
+ val run = c.newRun
+ run.compile(source)
+ }
+
def methType(names: String*)(paramTypes: Type*)(resultType: Type = defn.UnitType) =
MethodType(names.toList map (_.toTermName), paramTypes.toList, resultType)
}