Skip to content

Commit 356dd4b

Browse files
committed
Merge pull request #35 from DarkDimius/tests-2
For some tests context is required, it should be passed to checker phase.
2 parents 9c73c96 + b2dd56c commit 356dd4b

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

test/test/DottyTest.scala

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,50 @@ class DottyTest {
2323
import base.settings._
2424
val ctx = base.initialCtx.fresh
2525
.withSetting(verbose, true)
26-
// .withSetting(debug, true)
27-
// .withSetting(debugTrace, true)
28-
// .withSetting(prompt, true)
26+
// .withSetting(debug, true)
27+
// .withSetting(debugTrace, true)
28+
// .withSetting(prompt, true)
2929
.withSetting(Ylogcp, true)
3030
.withSetting(printtypes, true)
3131
.withSetting(pageWidth, 90)
3232
.withSetting(log, List("<some"))
33-
// .withTyperState(new TyperState(new ConsoleReporter()(base.initialCtx)))
33+
// .withTyperState(new TyperState(new ConsoleReporter()(base.initialCtx)))
3434

35-
// .withSetting(uniqid, true)
35+
// .withSetting(uniqid, true)
3636
println(ctx.settings)
3737
base.definitions.init(ctx)
3838
ctx
3939
}
4040

41-
def checkCompile(checkAfterPhase: String, source:String)(assertion:tpd.Tree =>Unit): Unit = {
42-
val c = new Compiler {
43-
override def phases = {
44-
val allPhases = super.phases
45-
val targetPhase = allPhases.find{p=> p.name == checkAfterPhase}
46-
assert(targetPhase isDefined)
47-
val phasesBefore = allPhases.takeWhile(x=> ! (x eq targetPhase.get))
48-
49-
val checker = new Phase{
50-
def name = "assertionChecker"
51-
override def run(implicit ctx: Context): Unit = assertion(ctx.compilationUnit.tpdTree)
52-
}
53-
phasesBefore:::List(targetPhase.get, checker)
41+
private def compilerWithChecker(phase: String)(assertion:(tpd.Tree, Context) => Unit) = new Compiler {
42+
override def phases = {
43+
val allPhases = super.phases
44+
val targetPhase = allPhases.find{p=> p.name == phase}
45+
assert(targetPhase isDefined)
46+
val phasesBefore = allPhases.takeWhile(x=> ! (x eq targetPhase.get))
47+
48+
val checker = new Phase{
49+
def name = "assertionChecker"
50+
override def run(implicit ctx: Context): Unit = assertion(ctx.compilationUnit.tpdTree, ctx)
5451
}
52+
phasesBefore:::List(targetPhase.get, checker)
5553
}
54+
}
55+
56+
def checkCompile(checkAfterPhase: String, source:String)(assertion:(tpd.Tree, Context) => Unit): Unit = {
57+
val c = compilerWithChecker(checkAfterPhase)(assertion)
5658
c.rootContext(ctx)
5759
val run = c.newRun
5860
run.compile(source)
5961
}
6062

63+
def checkCompile(checkAfterPhase: String, sources:List[String])(assertion:(tpd.Tree, Context) => Unit): Unit = {
64+
val c = compilerWithChecker(checkAfterPhase)(assertion)
65+
c.rootContext(ctx)
66+
val run = c.newRun
67+
run.compile(sources)
68+
}
69+
6170
def methType(names: String*)(paramTypes: Type*)(resultType: Type = defn.UnitType) =
6271
MethodType(names.toList map (_.toTermName), paramTypes.toList, resultType)
6372
}

test/test/SamplePhaseTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class SamplePhaseTest extends DottyTest {
66

77
@Test
88
def testTypechekingSimpleClass = checkCompile("frontend", "class A{}") {
9-
tree =>
9+
(tree, context) =>
10+
implicit val ctx = context
1011
Assert.assertTrue("can typecheck simple class",
1112
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()))))"
1213
)

0 commit comments

Comments
 (0)