summaryrefslogtreecommitdiff
path: root/test/files/jvm/future-spec/FutureTests.scala
diff options
context:
space:
mode:
authorViktor Klang <viktor.klang@gmail.com>2013-01-30 17:08:42 +0100
committerPhilipp Haller <hallerp@gmail.com>2013-01-31 21:54:34 +0100
commit3f78bee128bd6a478bef6a66c5574f77a2d6dd74 (patch)
treec1472e1835eb6593d5ee3bdd5cf017dce3ae9bbd /test/files/jvm/future-spec/FutureTests.scala
parent42c4cc7a1eed222a1593c6ac2652cd5357c2897a (diff)
downloadscala-3f78bee128bd6a478bef6a66c5574f77a2d6dd74.tar.gz
scala-3f78bee128bd6a478bef6a66c5574f77a2d6dd74.tar.bz2
scala-3f78bee128bd6a478bef6a66c5574f77a2d6dd74.zip
SI-7029 - Makes sure that uncaught exceptions are propagated to the UEH for the global ExecutionContext
Diffstat (limited to 'test/files/jvm/future-spec/FutureTests.scala')
-rw-r--r--test/files/jvm/future-spec/FutureTests.scala24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/files/jvm/future-spec/FutureTests.scala b/test/files/jvm/future-spec/FutureTests.scala
index 8674be168c..ae2e72bf96 100644
--- a/test/files/jvm/future-spec/FutureTests.scala
+++ b/test/files/jvm/future-spec/FutureTests.scala
@@ -74,6 +74,30 @@ object FutureTests extends MinimalScalaTest {
"A future with global ExecutionContext" should {
import ExecutionContext.Implicits._
+ "output uncaught exceptions" in {
+ import java.io.{ ByteArrayOutputStream, PrintStream }
+
+ val baos = new ByteArrayOutputStream(1 << 16) { def isEmpty: Boolean = count == 0 }
+ val tmpErr = new PrintStream(baos)
+
+ def assertPrintedToErr(t: Throwable): Unit = {
+ t.printStackTrace(tmpErr)
+ tmpErr.flush()
+ val expected = baos.toByteArray.toIndexedSeq
+ baos.reset()
+ val f = Future(throw t)
+ val d = Deadline.now + 5.seconds
+ while(d.hasTimeLeft && baos.isEmpty) Thread.sleep(10)
+ baos.toByteArray.toIndexedSeq mustBe (expected)
+ }
+
+ val oldErr = System.err
+ System.setErr(tmpErr)
+ try {
+ assertPrintedToErr(new NotImplementedError("foo"))
+ } finally System.setErr(oldErr)
+ }
+
"compose with for-comprehensions" in {
def async(x: Int) = future { (x * 2).toString }
val future0 = future[Any] {