From a45be8b2851b8bc76ffa40deb9810568ed5b69f1 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 23 Mar 2011 22:35:09 +0000 Subject: Spiced up the signature test infrastructure a b... Spiced up the signature test infrastructure a bunch, wrote some more tests, restored the tests in pending. No review. --- src/partest/scala/tools/partest/ReplTest.scala | 42 ++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'src/partest') diff --git a/src/partest/scala/tools/partest/ReplTest.scala b/src/partest/scala/tools/partest/ReplTest.scala index b7bd8efcf4..2f6bcea78b 100644 --- a/src/partest/scala/tools/partest/ReplTest.scala +++ b/src/partest/scala/tools/partest/ReplTest.scala @@ -6,6 +6,7 @@ package scala.tools.partest import scala.tools.nsc.interpreter.ILoop +import java.lang.reflect.{ Method => JMethod, Field => JField } /** A trait for testing repl code. It drops the first line * of output because the real repl prints a version number. @@ -19,11 +20,40 @@ abstract class ReplTest extends App { } trait SigTest { - def returnType[T: Manifest](methodName: String) = ( - classManifest[T].erasure.getMethods - . filter (x => !x.isBridge && x.getName == methodName) - . map (_.getGenericReturnType.toString) + def mstr(m: JMethod) = " (m) %s%s".format( + m.toGenericString, + if (m.isBridge) " (bridge)" else "" ) - def show[T: Manifest](methodName: String) = - println(manifest[T].erasure.getName +: returnType[T](methodName).distinct mkString " ") + def fstr(f: JField) = " (f) %s".format(f.toGenericString) + + def isObjectMethodName(name: String) = classOf[Object].getMethods exists (_.getName == name) + + def fields[T: ClassManifest](p: JField => Boolean) = { + val cl = classManifest[T].erasure + val fs = (cl.getFields ++ cl.getDeclaredFields).distinct sortBy (_.getName) + + fs filter p + } + def methods[T: ClassManifest](p: JMethod => Boolean) = { + val cl = classManifest[T].erasure + val ms = (cl.getMethods ++ cl.getDeclaredMethods).distinct sortBy (x => (x.getName, x.isBridge)) + + ms filter p + } + def allFields[T: ClassManifest]() = fields[T](_ => true) + def allMethods[T: ClassManifest]() = methods[T](m => !isObjectMethodName(m.getName)) + def fieldsNamed[T: ClassManifest](name: String) = fields[T](_.getName == name) + def methodsNamed[T: ClassManifest](name: String) = methods[T](_.getName == name) + + def allGenericStrings[T: ClassManifest]() = + (allMethods[T]() map mstr) ++ (allFields[T]() map fstr) + + def genericStrings[T: ClassManifest](name: String) = + (methodsNamed[T](name) map mstr) ++ (fieldsNamed[T](name) map fstr) + + def show[T: ClassManifest](name: String = "") = { + println(classManifest[T].erasure.getName) + if (name == "") allGenericStrings[T]() foreach println + else genericStrings[T](name) foreach println + } } -- cgit v1.2.3