From 652e96911378e9c53a485263425a26ba687f6540 Mon Sep 17 00:00:00 2001 From: Den Shabalin Date: Mon, 2 Sep 2013 16:45:13 +0200 Subject: add toolbox-based utility methods to quasiquotes' tests --- .../quasiquotes/QuasiquoteProperties.scala | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala b/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala index 5e87aa57cc..6a531071bf 100644 --- a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala +++ b/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala @@ -1,7 +1,10 @@ import scala.reflect.runtime.universe._ -import scala.tools.reflect.ToolBox -import scala.tools.reflect.ToolBoxError +import scala.reflect.runtime.universe.definitions._ +import scala.reflect.runtime.universe.Flag._ +import scala.reflect.runtime.currentMirror +import scala.reflect.api.{Liftable, Universe} import scala.reflect.macros.TypecheckException +import scala.tools.reflect.{ToolBox, ToolBoxError} import org.scalacheck._ import Prop._ @@ -57,6 +60,14 @@ trait Helpers { assert(false, "exception wasn't thrown") } + def assertEqAst(tree: Tree, code: String) = assert(eqAst(tree, code)) + def eqAst(tree: Tree, code: String) = tree ≈ parse(code) + + val toolbox = currentMirror.mkToolBox() + val parse = toolbox.parse(_) + val compile = toolbox.compile(_) + val eval = toolbox.eval(_) + def fails(msg: String, block: String) = { def result(ok: Boolean, description: String = "") = { val status = if (ok) Prop.Proof else Prop.False @@ -64,14 +75,12 @@ trait Helpers { Prop { new Prop.Result(status, Nil, Set.empty, labels) } } try { - val tb = rootMirror.mkToolBox() - val tree = tb.parse(s""" + compile(parse(s""" object Wrapper extends Helpers { import scala.reflect.runtime.universe._ $block } - """) - tb.compile(tree) + """)) result(false, "given code doesn't fail to typecheck") } catch { case ToolBoxError(emsg, _) => -- cgit v1.2.3