From e6afb18850dead42400ea82d81839185cf122a09 Mon Sep 17 00:00:00 2001 From: Emilis Panovas Date: Tue, 4 Aug 2020 18:12:09 +0200 Subject: [PATCH 1/3] Allow pendingUntilFixed to catch Throwables --- dotty/core/src/main/scala/org/scalatest/Assertions.scala | 5 ++--- jvm/core/src/main/scala/org/scalatest/Assertions.scala | 5 ++--- .../src/test/scala/org/scalatest/SuiteSpec.scala | 7 +++++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dotty/core/src/main/scala/org/scalatest/Assertions.scala b/dotty/core/src/main/scala/org/scalatest/Assertions.scala index 5f861fcea6..5e360fad0e 100644 --- a/dotty/core/src/main/scala/org/scalatest/Assertions.scala +++ b/dotty/core/src/main/scala/org/scalatest/Assertions.scala @@ -1263,7 +1263,7 @@ trait Assertions extends TripleEquals { *

* * @param f a block of code, which if it completes abruptly, should trigger a TestPendingException - * @throws TestPendingException if the passed block of code completes abruptly with an Exception or AssertionError + * @throws TestPendingException if the passed block of code completes abruptly with a Throwable */ def pendingUntilFixed(f: => Unit)(implicit pos: source.Position): Assertion with PendingStatement = { val isPending = @@ -1272,8 +1272,7 @@ trait Assertions extends TripleEquals { false } catch { - case _: Exception => true - case _: AssertionError => true + case _: Throwable => true } if (isPending) throw new TestPendingException diff --git a/jvm/core/src/main/scala/org/scalatest/Assertions.scala b/jvm/core/src/main/scala/org/scalatest/Assertions.scala index 98820735d6..8db4904802 100644 --- a/jvm/core/src/main/scala/org/scalatest/Assertions.scala +++ b/jvm/core/src/main/scala/org/scalatest/Assertions.scala @@ -1153,7 +1153,7 @@ trait Assertions extends TripleEquals { *

* * @param f a block of code, which if it completes abruptly, should trigger a TestPendingException - * @throws TestPendingException if the passed block of code completes abruptly with an Exception or AssertionError + * @throws TestPendingException if the passed block of code completes abruptly with a Throwable */ def pendingUntilFixed(f: => Unit)(implicit pos: source.Position): Assertion with PendingStatement = { val isPending = @@ -1162,8 +1162,7 @@ trait Assertions extends TripleEquals { false } catch { - case _: Exception => true - case _: AssertionError => true + case _: Throwable => true } if (isPending) throw new TestPendingException diff --git a/jvm/scalatest-test/src/test/scala/org/scalatest/SuiteSpec.scala b/jvm/scalatest-test/src/test/scala/org/scalatest/SuiteSpec.scala index d2a328dbaf..9a09c1451a 100644 --- a/jvm/scalatest-test/src/test/scala/org/scalatest/SuiteSpec.scala +++ b/jvm/scalatest-test/src/test/scala/org/scalatest/SuiteSpec.scala @@ -259,6 +259,13 @@ class SuiteSpec extends AnyFunSpec { describe("A Suite") { describe("(when its pendingUntilFixed method is invoked)") { it("should throw TestPendingException if the code block throws an exception") { + intercept[TestPendingException] { + pendingUntilFixed { + throw new Throwable("Testing pendingUntilFixed") + } + } + } + it("should throw TestPendingException if the code block throws a throwable") { intercept[TestPendingException] { pendingUntilFixed { assert(1 + 1 === 3) From 74fc6f42a6afcb83941569064a35d3c2332e6453 Mon Sep 17 00:00:00 2001 From: Emilis Panovas Date: Wed, 5 Aug 2020 10:15:01 +0200 Subject: [PATCH 2/3] Fixed mixed up test names --- .../src/test/scala/org/scalatest/SuiteSpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jvm/scalatest-test/src/test/scala/org/scalatest/SuiteSpec.scala b/jvm/scalatest-test/src/test/scala/org/scalatest/SuiteSpec.scala index 9a09c1451a..75c6d9749b 100644 --- a/jvm/scalatest-test/src/test/scala/org/scalatest/SuiteSpec.scala +++ b/jvm/scalatest-test/src/test/scala/org/scalatest/SuiteSpec.scala @@ -258,14 +258,14 @@ class SuiteSpec extends AnyFunSpec { describe("A Suite") { describe("(when its pendingUntilFixed method is invoked)") { - it("should throw TestPendingException if the code block throws an exception") { + it("should throw TestPendingException if the code block throws a throwable") { intercept[TestPendingException] { pendingUntilFixed { throw new Throwable("Testing pendingUntilFixed") } } } - it("should throw TestPendingException if the code block throws a throwable") { + it("should throw TestPendingException if the code block throws an exception") { intercept[TestPendingException] { pendingUntilFixed { assert(1 + 1 === 3) From 46eb2b870fc06e08093589f0393ac328d5ee913b Mon Sep 17 00:00:00 2001 From: Emilis Panovas Date: Wed, 5 Aug 2020 11:09:15 +0200 Subject: [PATCH 3/3] Switched to scala.util.control.NonFatal --- dotty/core/src/main/scala/org/scalatest/Assertions.scala | 3 ++- jvm/core/src/main/scala/org/scalatest/Assertions.scala | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dotty/core/src/main/scala/org/scalatest/Assertions.scala b/dotty/core/src/main/scala/org/scalatest/Assertions.scala index 5e360fad0e..2fff601c28 100644 --- a/dotty/core/src/main/scala/org/scalatest/Assertions.scala +++ b/dotty/core/src/main/scala/org/scalatest/Assertions.scala @@ -19,6 +19,7 @@ import org.scalactic._ import Requirements._ import scala.reflect.ClassTag +import scala.util.control.NonFatal import Assertions.NormalResult import DefaultEquality.areEqualComparingArraysStructurally import org.scalatest.exceptions.StackDepthException @@ -1272,7 +1273,7 @@ trait Assertions extends TripleEquals { false } catch { - case _: Throwable => true + case NonFatal(_) => true } if (isPending) throw new TestPendingException diff --git a/jvm/core/src/main/scala/org/scalatest/Assertions.scala b/jvm/core/src/main/scala/org/scalatest/Assertions.scala index 8db4904802..c4f26d3319 100644 --- a/jvm/core/src/main/scala/org/scalatest/Assertions.scala +++ b/jvm/core/src/main/scala/org/scalatest/Assertions.scala @@ -19,6 +19,7 @@ import org.scalactic.{Resources => _, FailureMessages => _, _} import Requirements._ import scala.reflect.ClassTag +import scala.util.control.NonFatal import Assertions.areEqualComparingArraysStructurally import org.scalatest.exceptions.StackDepthException import org.scalatest.exceptions.StackDepthException.toExceptionFunction @@ -1162,7 +1163,7 @@ trait Assertions extends TripleEquals { false } catch { - case _: Throwable => true + case NonFatal(_) => true } if (isPending) throw new TestPendingException