summaryrefslogtreecommitdiff
path: root/src/partest
diff options
context:
space:
mode:
authorJosh Suereth <Joshua.Suereth@gmail.com>2012-09-14 09:32:57 -0700
committerJosh Suereth <Joshua.Suereth@gmail.com>2012-09-14 09:32:57 -0700
commite9c01dd1cedf15c946c03ef1e9d23ef6db275f2b (patch)
tree0e78b0e553036c45bdb24049544f3e75a84627e2 /src/partest
parent7bafb210a18f7b73b26a199e13f9f8cbb6f28e96 (diff)
parent21bd081540413a8625247d2e40506112cc1ea218 (diff)
downloadscala-e9c01dd1cedf15c946c03ef1e9d23ef6db275f2b.tar.gz
scala-e9c01dd1cedf15c946c03ef1e9d23ef6db275f2b.tar.bz2
scala-e9c01dd1cedf15c946c03ef1e9d23ef6db275f2b.zip
Merge pull request #1271 from retronym/ticket/6331
SI-6331 deconst If type / refine equality of floating point Constant types.
Diffstat (limited to 'src/partest')
-rw-r--r--src/partest/scala/tools/partest/package.scala27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/partest/scala/tools/partest/package.scala b/src/partest/scala/tools/partest/package.scala
index 08934ef143..49d3ed301c 100644
--- a/src/partest/scala/tools/partest/package.scala
+++ b/src/partest/scala/tools/partest/package.scala
@@ -73,4 +73,31 @@ package object partest {
def isPartestDebug: Boolean =
propOrEmpty("partest.debug") == "true"
+
+
+ import language.experimental.macros
+
+ /**
+ * `trace("".isEmpty)` will return `true` and as a side effect print the following to standard out.
+ * {{{
+ * trace> "".isEmpty
+ * res: Boolean = true
+ *
+ * }}}
+ *
+ * An alternative to [[scala.tools.partest.ReplTest]] that avoids the inconvenience of embedding
+ * test code in a string.
+ */
+ def trace[A](a: A) = macro traceImpl[A]
+
+ import scala.reflect.macros.Context
+ def traceImpl[A: c.AbsTypeTag](c: Context)(a: c.Expr[A]): c.Expr[A] = {
+ import c.universe._
+ val exprCode = c.literal(show(a.tree))
+ val exprType = c.literal(show(a.actualType))
+ reify {
+ println(s"trace> ${exprCode.splice}\nres: ${exprType.splice} = ${a.splice}\n")
+ a.splice
+ }
+ }
}