From 4a476e775fe7d3a126a42a5127c31e09b9117393 Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 11 Sep 2012 20:37:43 +0200 Subject: two more minor cleanups to Duration - copy partest TestUtil.intercept change from PR 1279 branch - add comment on non-obvious match cases --- src/library/scala/concurrent/util/Duration.scala | 4 ++-- src/partest/scala/tools/partest/TestUtil.scala | 12 +++++++++++- test/files/jvm/duration-tck.scala | 7 +------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/library/scala/concurrent/util/Duration.scala b/src/library/scala/concurrent/util/Duration.scala index 6d44c93bc2..8fd47630cb 100644 --- a/src/library/scala/concurrent/util/Duration.scala +++ b/src/library/scala/concurrent/util/Duration.scala @@ -306,8 +306,8 @@ object Duration { val Inf: Infinite = new Infinite { override def toString = "Duration.Inf" def compare(other: Duration) = other match { - case x if x eq Undefined => -1 - case x if x eq this => 0 + case x if x eq Undefined => -1 // Undefined != Undefined + case x if x eq this => 0 // `case Inf` will include null checks in the byte code case _ => 1 } def unary_- : Duration = MinusInf diff --git a/src/partest/scala/tools/partest/TestUtil.scala b/src/partest/scala/tools/partest/TestUtil.scala index b86a8e2c7f..146e6fc69f 100644 --- a/src/partest/scala/tools/partest/TestUtil.scala +++ b/src/partest/scala/tools/partest/TestUtil.scala @@ -1,5 +1,7 @@ package scala.tools.partest +import reflect.{ classTag, ClassTag } + trait TestUtil { /** Given function and block of code, evaluates code block, * calls function with nanoseconds elapsed, and returns block result. @@ -29,8 +31,16 @@ trait TestUtil { assert(mult <= acceptableMultiple, "Performance difference too great: multiple = " + mult) } + + def intercept[T <: Exception : ClassTag](code: => Unit): Unit = + try { + code + assert(false, "did not throw " + classTag[T]) + } catch { + case ex: Exception if classTag[T].runtimeClass isInstance ex => + } } object TestUtil extends TestUtil { -} \ No newline at end of file +} diff --git a/test/files/jvm/duration-tck.scala b/test/files/jvm/duration-tck.scala index 87ffa196ca..0947e84004 100644 --- a/test/files/jvm/duration-tck.scala +++ b/test/files/jvm/duration-tck.scala @@ -6,6 +6,7 @@ import scala.concurrent.util._ import duration._ import scala.reflect._ import java.util.concurrent.TimeUnit._ +import scala.tools.partest.TestUtil.intercept object Test extends App { @@ -19,12 +20,6 @@ object Test extends App { } } - def intercept[T <: Exception : ClassTag](code: => Unit) = - try { code; assert(false, "did not throw expected exception " + classTag[T]) } - catch { - case ex: Exception => if (classTag[T].runtimeClass isAssignableFrom ex.getClass) () else throw ex - } - val zero = 0 seconds val one = 1 second val two = one + one -- cgit v1.2.3