diff options
author | Paul Phillips <paulp@improving.org> | 2011-03-23 22:35:09 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-03-23 22:35:09 +0000 |
commit | a45be8b2851b8bc76ffa40deb9810568ed5b69f1 (patch) | |
tree | e7337ff79c949d9390eda8aeb11f984c423f8af2 /src/partest | |
parent | 3491672e8667a7e5b8d9bd3d23239757cf1b7a85 (diff) | |
download | scala-a45be8b2851b8bc76ffa40deb9810568ed5b69f1.tar.gz scala-a45be8b2851b8bc76ffa40deb9810568ed5b69f1.tar.bz2 scala-a45be8b2851b8bc76ffa40deb9810568ed5b69f1.zip |
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.
Diffstat (limited to 'src/partest')
-rw-r--r-- | src/partest/scala/tools/partest/ReplTest.scala | 42 |
1 files changed, 36 insertions, 6 deletions
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 + } } |