Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pendingUntilFixed to catch Throwables #1869

Open
wants to merge 3 commits into
base: 3.2.x-new
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions dotty/core/src/main/scala/org/scalatest/Assertions.scala
Expand Up @@ -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
Expand Down Expand Up @@ -1263,7 +1264,7 @@ trait Assertions extends TripleEquals {
* </p>
*
* @param f a block of code, which if it completes abruptly, should trigger a <code>TestPendingException</code>
* @throws TestPendingException if the passed block of code completes abruptly with an <code>Exception</code> or <code>AssertionError</code>
* @throws TestPendingException if the passed block of code completes abruptly with a <code>Throwable</code>
*/
def pendingUntilFixed(f: => Unit)(implicit pos: source.Position): Assertion with PendingStatement = {
val isPending =
Expand All @@ -1272,8 +1273,7 @@ trait Assertions extends TripleEquals {
false
}
catch {
case _: Exception => true
case _: AssertionError => true
case NonFatal(_) => true
}
if (isPending)
throw new TestPendingException
Expand Down
6 changes: 3 additions & 3 deletions jvm/core/src/main/scala/org/scalatest/Assertions.scala
Expand Up @@ -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
Expand Down Expand Up @@ -1153,7 +1154,7 @@ trait Assertions extends TripleEquals {
* </p>
*
* @param f a block of code, which if it completes abruptly, should trigger a <code>TestPendingException</code>
* @throws TestPendingException if the passed block of code completes abruptly with an <code>Exception</code> or <code>AssertionError</code>
* @throws TestPendingException if the passed block of code completes abruptly with a <code>Throwable</code>
*/
def pendingUntilFixed(f: => Unit)(implicit pos: source.Position): Assertion with PendingStatement = {
val isPending =
Expand All @@ -1162,8 +1163,7 @@ trait Assertions extends TripleEquals {
false
}
catch {
case _: Exception => true
case _: AssertionError => true
case NonFatal(_) => true
}
if (isPending)
throw new TestPendingException
Expand Down
Expand Up @@ -258,6 +258,13 @@ class SuiteSpec extends AnyFunSpec {

describe("A Suite") {
describe("(when its pendingUntilFixed method is invoked)") {
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 an exception") {
intercept[TestPendingException] {
pendingUntilFixed {
Expand Down