Skip to content

For some tests context is required, it should be passed to checker phase... #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions test/test/DottyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion test/test/SamplePhaseTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()))))"
)
Expand Down