aboutsummaryrefslogtreecommitdiff
path: root/test/test
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-03 16:41:45 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-03 16:44:17 +0100
commitb2dd56c2b5f049f84635e62fc41197ec84c8d3e4 (patch)
treed3186c58a504f4b1d7c2cdcb28e72855e0738fc7 /test/test
parent92a4fefe58cfe4c1bcccc8f98183079a553d477a (diff)
downloaddotty-b2dd56c2b5f049f84635e62fc41197ec84c8d3e4.tar.gz
dotty-b2dd56c2b5f049f84635e62fc41197ec84c8d3e4.tar.bz2
dotty-b2dd56c2b5f049f84635e62fc41197ec84c8d3e4.zip
For some tests context is required, it should be passed to checker phase.
Diffstat (limited to 'test/test')
-rw-r--r--test/test/DottyTest.scala45
-rw-r--r--test/test/SamplePhaseTest.scala3
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()))))"
)