diff options
-rw-r--r-- | test/test/DottyTest.scala | 45 | ||||
-rw-r--r-- | test/test/SamplePhaseTest.scala | 3 |
2 files changed, 29 insertions, 19 deletions
diff --git a/test/test/DottyTest.scala b/test/test/DottyTest.scala index 07b29a5f0..ba67f14ce 100644 --- a/test/test/DottyTest.scala +++ b/test/test/DottyTest.scala @@ -23,41 +23,50 @@ class DottyTest { import base.settings._ val ctx = base.initialCtx.fresh .withSetting(verbose, true) -// .withSetting(debug, true) -// .withSetting(debugTrace, true) -// .withSetting(prompt, true) + // .withSetting(debug, true) + // .withSetting(debugTrace, true) + // .withSetting(prompt, true) .withSetting(Ylogcp, true) .withSetting(printtypes, true) .withSetting(pageWidth, 90) .withSetting(log, List("<some")) - // .withTyperState(new TyperState(new ConsoleReporter()(base.initialCtx))) + // .withTyperState(new TyperState(new ConsoleReporter()(base.initialCtx))) -// .withSetting(uniqid, true) + // .withSetting(uniqid, true) println(ctx.settings) base.definitions.init(ctx) 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) + private def compilerWithChecker(phase: String)(assertion:(tpd.Tree, Context) => Unit) = new Compiler { + override def phases = { + val allPhases = super.phases + val targetPhase = allPhases.find{p=> p.name == phase} + 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, ctx) } + phasesBefore:::List(targetPhase.get, checker) } + } + + def checkCompile(checkAfterPhase: String, source:String)(assertion:(tpd.Tree, Context) => Unit): Unit = { + val c = compilerWithChecker(checkAfterPhase)(assertion) c.rootContext(ctx) val run = c.newRun run.compile(source) } + def checkCompile(checkAfterPhase: String, sources:List[String])(assertion:(tpd.Tree, Context) => Unit): Unit = { + val c = compilerWithChecker(checkAfterPhase)(assertion) + c.rootContext(ctx) + val run = c.newRun + run.compile(sources) + } + def methType(names: String*)(paramTypes: Type*)(resultType: Type = defn.UnitType) = MethodType(names.toList map (_.toTermName), paramTypes.toList, resultType) } diff --git a/test/test/SamplePhaseTest.scala b/test/test/SamplePhaseTest.scala index e86f4459b..432d95d5a 100644 --- a/test/test/SamplePhaseTest.scala +++ b/test/test/SamplePhaseTest.scala @@ -6,7 +6,8 @@ class SamplePhaseTest extends DottyTest { @Test def testTypechekingSimpleClass = checkCompile("frontend", "class A{}") { - tree => + (tree, context) => + implicit val ctx = context Assert.assertTrue("can typecheck simple class", tree.toString == "PackageDef(Ident(<empty>),List(TypeDef(Modifiers(,,List()),A,Template(DefDef(Modifiers(,,List()),<init>,List(),List(List()),TypeTree[TypeRef(ThisType(module class scala),Unit)],EmptyTree),List(Apply(Select(New(TypeTree[TypeRef(ThisType(module class lang),Object)]),<init>),List())),ValDef(Modifiers(private,,List()),_,EmptyTree,EmptyTree),List()))))" ) |