aboutsummaryrefslogtreecommitdiff
path: root/test/dotty/tools/DottyTest.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-01 18:34:29 +0100
committerGuillaume Martres <smarter@ubuntu.com>2016-11-22 01:35:07 +0100
commit6a455fe6da5ff9c741d91279a2dc6fe2fb1b472f (patch)
treefe7729ddb03a84728687d5a3068f520b0bc1c297 /test/dotty/tools/DottyTest.scala
parentb3855424280a821601f126b6b4c6a731b72540ea (diff)
downloaddotty-6a455fe6da5ff9c741d91279a2dc6fe2fb1b472f.tar.gz
dotty-6a455fe6da5ff9c741d91279a2dc6fe2fb1b472f.tar.bz2
dotty-6a455fe6da5ff9c741d91279a2dc6fe2fb1b472f.zip
Move (most) unit tests to correct locations
Should still perhaps move `test/dotc/tests.scala` and the others in the same directory to a better more cohesive location. Would like to delete the worksheets as well - but maybe they hold sentimental value...
Diffstat (limited to 'test/dotty/tools/DottyTest.scala')
-rw-r--r--test/dotty/tools/DottyTest.scala73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/dotty/tools/DottyTest.scala b/test/dotty/tools/DottyTest.scala
new file mode 100644
index 000000000..9e7b6fccb
--- /dev/null
+++ b/test/dotty/tools/DottyTest.scala
@@ -0,0 +1,73 @@
+package dotty
+package tools
+
+import dotc.core._
+import dotc.core.Contexts._
+import dotc.core.Symbols._
+import dotc.core.Flags._
+import Types._, Symbols._, Decorators._
+import dotc.printing.Texts._
+import dotc.reporting.ConsoleReporter
+import dotc.core.Decorators._
+import dotc.ast.tpd
+import dotc.Compiler
+
+import dotc.core.Phases.Phase
+
+class DottyTest extends ContextEscapeDetection{
+
+ dotc.parsing.Scanners // initialize keywords
+
+ implicit var ctx: Contexts.Context = {
+ val base = new ContextBase {}
+ import base.settings._
+ val ctx = base.initialCtx.fresh
+ ctx.setSetting(ctx.settings.encoding, "UTF8")
+ ctx.setSetting(
+ ctx.settings.classpath,
+ "./library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar"
+ )
+ // when classpath is changed in ctx, we need to re-initialize to get the
+ // correct classpath from PathResolver
+ base.initialize()(ctx)
+ ctx
+ }
+
+ override def getCtx: Context = ctx
+ override def clearCtx() = {
+ ctx = null
+ }
+
+ private def compilerWithChecker(phase: String)(assertion:(tpd.Tree, Context) => Unit) = new Compiler {
+ override def phases = {
+ val allPhases = super.phases
+ val targetPhase = allPhases.flatten.find(p => p.phaseName == phase).get
+ val groupsBefore = allPhases.takeWhile(x => !x.contains(targetPhase))
+ val lastGroup = allPhases.find(x => x.contains(targetPhase)).get.takeWhile(x => !(x eq targetPhase))
+ val checker = new Phase {
+ def phaseName = "assertionChecker"
+ override def run(implicit ctx: Context): Unit = assertion(ctx.compilationUnit.tpdTree, ctx)
+ }
+ val lastGroupAppended = List(lastGroup ::: targetPhase :: Nil)
+
+ groupsBefore ::: lastGroupAppended ::: List(List(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)
+}