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

EitherValues Serialization Fix #2159

Merged
Merged
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
14 changes: 10 additions & 4 deletions jvm/core/src/main/scala/org/scalatest/EitherValues.scala
Expand Up @@ -15,7 +15,7 @@
*/
package org.scalatest

import org.scalactic._
import org.scalactic.{Resources => _, _}
import org.scalatest.exceptions.StackDepthException
import org.scalatest.exceptions.TestFailedException

Expand Down Expand Up @@ -134,7 +134,9 @@ trait EitherValues extends Serializable {
}
catch {
case cause: NoSuchElementException =>
throw new TestFailedException((_: StackDepthException) => Some(Resources.eitherLeftValueNotDefined(leftProj.e)), Some(cause), pos)
val e = leftProj.e
val p = pos
throw new TestFailedException((_: StackDepthException) => Some(Resources.eitherLeftValueNotDefined(e)), Some(cause), p)
}
}
}
Expand Down Expand Up @@ -162,7 +164,9 @@ trait EitherValues extends Serializable {
}
catch {
case cause: NoSuchElementException =>
throw new TestFailedException((_: StackDepthException) => Some(Resources.eitherRightValueNotDefined(rightProj.e)), Some(cause), pos)
val e = rightProj.e
val p = pos
throw new TestFailedException((_: StackDepthException) => Some(Resources.eitherRightValueNotDefined(e)), Some(cause), p)
}
}
}
Expand Down Expand Up @@ -202,7 +206,9 @@ trait EitherValues extends Serializable {
either match {
case Right(r) => r
case _ =>
throw new TestFailedException((_: StackDepthException) => Some(Resources.eitherValueNotDefined(either)), None, pos)
val e = either
val p = pos
throw new TestFailedException((_: StackDepthException) => Some(Resources.eitherValueNotDefined(e)), None, p)
}
}
}
Expand Down
Expand Up @@ -24,7 +24,11 @@ import org.scalatest.OptionValues._
import org.scalatest.SharedHelpers.thisLineNumber
import org.scalatest.exceptions.TestFailedException
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers._
// SKIP-SCALATESTJS,NATIVE-START
import SharedHelpers.serializeRoundtrip
// SKIP-SCALATESTJS,NATIVE-END

class EitherValuesSpec extends AnyFunSpec {
describe("values on Either") {
Expand Down Expand Up @@ -111,5 +115,18 @@ class EitherValuesSpec extends AnyFunSpec {
it("should be able to used with OptionValues") {
class TestSpec extends AnyFunSpec with EitherValues with OptionValues
}

// SKIP-SCALATESTJS,NATIVE-START
it("should throw TestFailedException that is serializable") {
class TestEitherValues extends AnyFunSuite with EitherValues
val spec = new TestEitherValues
val e = Left("error"): Either[String, Int]
val v = spec.convertEitherToValuable(e)
val caught = intercept[TestFailedException] {
v.value
}
serializeRoundtrip(caught)
}
// SKIP-SCALATESTJS,NATIVE-END
}
}