Skip to content

Instantly share code, notes, and snippets.

@retronym
Created June 17, 2012 08:03
Show Gist options
  • Select an option

  • Save retronym/2943865 to your computer and use it in GitHub Desktop.

Select an option

Save retronym/2943865 to your computer and use it in GitHub Desktop.
scalatest-2.10
Index: src/main/scala/org/scalatest/junit/JUnit3ComfortSuite.scala
===================================================================
--- src/main/scala/org/scalatest/junit/JUnit3ComfortSuite.scala (revision 3919)
+++ src/main/scala/org/scalatest/junit/JUnit3ComfortSuite.scala (working copy)
@@ -134,22 +134,16 @@
super.runTest(testName, reporter, stopper, configMap, tracker)
}
catch {
- case e: Exception => thrownException = Some(e)
+ case e: Exception => thrownException = Some(e); throw e
}
finally {
try {
tearDown() // Make sure that afterEach is called even if runTest completes abruptly.
- thrownException match {
- case Some(e) => throw e
- case None =>
- }
}
catch {
case laterException: Exception =>
- thrownException match { // If both run and afterAll throw an exception, report the test exception
- case Some(earlierException) => throw earlierException
- case None => throw laterException
- }
+ // If both run and afterAll throw an exception, report the test exception
+ throw thrownException.getOrElse(laterException)
}
}
}
Index: src/main/scala/org/scalatest/BeforeAndAfterAllFunctions.scala
===================================================================
--- src/main/scala/org/scalatest/BeforeAndAfterAllFunctions.scala (revision 3919)
+++ src/main/scala/org/scalatest/BeforeAndAfterAllFunctions.scala (working copy)
@@ -107,35 +107,23 @@
var thrownException: Option[Throwable] = None
- beforeFunctionAtomic.get match {
- case Some(fun) => fun()
- case None =>
- }
+ beforeFunctionAtomic.get.foreach(fun => fun())
try {
super.run(testName, reporter, stopper, filter, configMap, distributor, tracker)
}
catch {
- case e: Exception => thrownException = Some(e)
+ case e: Exception => thrownException = Some(e); throw e;
}
finally {
try {
// Make sure that code passed to afterAll, if any, is called even if run completes abruptly.
- afterFunctionAtomic.get match {
- case Some(fun) => fun()
- case None =>
- }
- thrownException match {
- case Some(e) => throw e
- case None =>
- }
+ afterFunctionAtomic.get.foreach(fun => fun())
}
catch {
case laterException: Exception =>
- thrownException match { // If both run and afterAll throw an exception, report the test exception
- case Some(earlierException) => throw earlierException
- case None => throw laterException
- }
+ // If both run and afterAll throw an exception, report the test exception
+ throw thrownException.getOrElse(laterException)
}
}
}
Index: src/main/scala/org/scalatest/BeforeAndAfterEachFunctions.scala
===================================================================
--- src/main/scala/org/scalatest/BeforeAndAfterEachFunctions.scala (revision 3919)
+++ src/main/scala/org/scalatest/BeforeAndAfterEachFunctions.scala (working copy)
@@ -105,36 +105,23 @@
var thrownException: Option[Throwable] = None
- beforeFunctionAtomic.get match {
- case Some(fun) => fun()
- case None =>
- }
+ beforeFunctionAtomic.get.foreach(fun => fun())
try {
super.runTest(testName, reporter, stopper, configMap, tracker)
}
catch {
- case e: Exception => thrownException = Some(e)
+ case e: Exception => thrownException = Some(e); throw e
}
finally {
try {
// Make sure that afterEach is called even if runTest completes abruptly.
- afterFunctionAtomic.get match {
- case Some(fun) => fun()
- case None =>
- }
-
- thrownException match {
- case Some(e) => throw e
- case None =>
- }
+ afterFunctionAtomic.get.foreach(fun => fun())
}
catch {
case laterException: Exception =>
- thrownException match { // If both run and afterAll throw an exception, report the test exception
- case Some(earlierException) => throw earlierException
- case None => throw laterException
- }
+ // If both run and afterAll throw an exception, report the test exception
+ throw thrownException.getOrElse(laterException)
}
}
}
Index: src/main/scala/org/scalatest/BeforeAndAfter.scala
===================================================================
--- src/main/scala/org/scalatest/BeforeAndAfter.scala (revision 3919)
+++ src/main/scala/org/scalatest/BeforeAndAfter.scala (working copy)
@@ -162,36 +162,23 @@
var thrownException: Option[Throwable] = None
- beforeFunctionAtomic.get match {
- case Some(fun) => fun()
- case None =>
- }
+ beforeFunctionAtomic.get.foreach(fun => fun())
try {
super.runTest(testName, reporter, stopper, configMap, tracker)
}
catch {
- case e: Exception => thrownException = Some(e)
+ case e: Exception => thrownException = Some(e); throw e
}
finally {
try {
// Make sure that afterEach is called even if runTest completes abruptly.
- afterFunctionAtomic.get match {
- case Some(fun) => fun()
- case None =>
- }
-
- thrownException match {
- case Some(e) => throw e
- case None =>
- }
+ afterFunctionAtomic.get.foreach(fun => fun())
}
catch {
case laterException: Exception =>
- thrownException match { // If both run and afterAll throw an exception, report the test exception
- case Some(earlierException) => throw earlierException
- case None => throw laterException
- }
+ // If both run and afterAll throw an exception, report the test exception
+ throw thrownException.getOrElse(laterException)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment