diff --git a/common/shared/src/main/scala/org/specs2/execute/ResultExecution.scala b/common/shared/src/main/scala/org/specs2/execute/ResultExecution.scala index d83cb95e98..8c3850fef4 100644 --- a/common/shared/src/main/scala/org/specs2/execute/ResultExecution.scala +++ b/common/shared/src/main/scala/org/specs2/execute/ResultExecution.scala @@ -47,8 +47,7 @@ trait ResultExecution: Failure(e.getMessage.notNull, "", e.getStackTrace.toList, details = FromJUnitAssertionError) case e: java.lang.Error if simpleClassName(e) == "ExpectationError" => Failure(e.toString, "", e.getStackTrace.toList, details = FromExpectationError) - case e: TimeoutException => Skipped(e.getMessage) - case NonFatal(t) => Error(t) + case NonFatal(t) => Error(t) /** execute a Result and rethrow any exception or throws an exception if it is not a success */ def effectively(result: =>Result): Result = diff --git a/core/js/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala b/core/js/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala index e01b3a84ce..b08f1b2928 100644 --- a/core/js/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala +++ b/core/js/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala @@ -7,6 +7,7 @@ import scala.scalajs.* import org.scalajs.macrotaskexecutor.MacrotaskExecutor import specification.core.* import runner.* +import main.* class MacrotaskExecutorSpec(env: Env) extends Specification: def is = s2""" @@ -17,7 +18,7 @@ class MacrotaskExecutorSpec(env: Env) extends Specification: def timeoutExample = given ExecutionContext = env.executionContext - TextRunner.runFuture(MacrotaskExecutorSpecification())(env).map { output => + TextRunner.runFuture(MacrotaskExecutorSpecification())(env.setArguments(Arguments())).map { output => output.messages must contain(contain("timeout after")) } diff --git a/core/jvm/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala b/core/jvm/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala index ff38c22adb..6299a539f5 100644 --- a/core/jvm/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala +++ b/core/jvm/src/test/scala/org/specs2/concurrent/MacrotaskExecutorSpec.scala @@ -5,6 +5,7 @@ import scala.concurrent.*, duration.* import LoopingCode.* import specification.core.* import runner.* +import main.* class MacrotaskExecutorSpec(env: Env) extends Specification: def is = s2""" @@ -18,14 +19,14 @@ class MacrotaskExecutorSpec(env: Env) extends Specification: def timeoutExample = given ExecutionContext = env.executionContext - TextRunner.runFuture(MacrotaskExecutorSpecification())(env).map { output => + TextRunner.runFuture(MacrotaskExecutorSpecification())(env.setArguments(Arguments())).map { output => output.messages must contain(contain("timeout after")) } class MacrotaskExecutorSpecification extends Specification: def is = args.execute(timeout = 500.millis) ^ s2""" - An example can be timed-out when using ScalaJS $timeoutExample + An example can be timed-out $timeoutExample """ diff --git a/core/jvm/src/test/scala/org/specs2/specification/ExecutorSpec.scala b/core/jvm/src/test/scala/org/specs2/specification/ExecutorSpec.scala index 4155ac5c8c..680feb6363 100644 --- a/core/jvm/src/test/scala/org/specs2/specification/ExecutorSpec.scala +++ b/core/jvm/src/test/scala/org/specs2/specification/ExecutorSpec.scala @@ -168,7 +168,7 @@ class ExecutorSpec(val env: Env) extends Specification with ThrownExpectations w val fragments = Fragments(example("very slow", verySlow)) val env1 = ownEnv.setTimeout(100.millis * timeFactor.toLong) - execute(fragments, env1) must contain(beFailing[Result]("timeout after " + 100 * timeFactor + " milliseconds")) + execute(fragments, env1) must contain(beSkipped[Result]("timeout after " + 100 * timeFactor + " milliseconds")) def userEnv = val fragments = diff --git a/core/jvm/src/test/scala/org/specs2/specification/process/TimeoutSpec.scala b/core/jvm/src/test/scala/org/specs2/specification/process/TimeoutSpec.scala index b8cd3d67f8..64bff9d6c0 100644 --- a/core/jvm/src/test/scala/org/specs2/specification/process/TimeoutSpec.scala +++ b/core/jvm/src/test/scala/org/specs2/specification/process/TimeoutSpec.scala @@ -6,6 +6,7 @@ import execute.* import concurrent.* import matcher.* import specification.core.* +import main.* class TimeoutSpec(env: Env) extends Specification with ResultMatchers: def is = section("ci") ^ s2""" @@ -17,12 +18,15 @@ class TimeoutSpec(env: Env) extends Specification with ResultMatchers: def executionTimeout = val execution = Execution.result { Thread.sleep(1000); ok }.setTimeout(100.millis) - execution.startExecution(env).executionResult.runOption(env.executionEnv) must beSome(beFailing[Result]) + execution.startExecution(env).executionResult.runOption(env.executionEnv) must beSome(beSkipped[Result]) def timeout = - val messages = TextRunner.run(TimeoutSpecExample)(env).messages + val messages = TextRunner.run(TimeoutSpecExample)(env.setArguments(Arguments())).messages messages must contain( - "[error] timeout after 100 milliseconds (TimeoutSpec.scala:31)" + allOf( + "[info] o timeout this example", + "[info] timeout after 100 milliseconds" + ) ) object TimeoutSpecExample extends Specification: diff --git a/core/shared/src/main/scala/org/specs2/specification/core/Execution.scala b/core/shared/src/main/scala/org/specs2/specification/core/Execution.scala index 95e9995046..1445fb4ebe 100644 --- a/core/shared/src/main/scala/org/specs2/specification/core/Execution.scala +++ b/core/shared/src/main/scala/org/specs2/specification/core/Execution.scala @@ -142,6 +142,11 @@ case class Execution( else Future.failed(FatalExecution(e.getCause)) + // we catch timeout exceptions here when they are caused by the timeout argument + // and the skip the corresponding example + case e: TimeoutException => + Future.successful((Skipped(e.getMessage), timer.stop)) + case NonFatal(e) => // Future execution could still throw FailureExceptions or TimeoutExceptions // which can only be recovered here