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

[3.2] Backport Macro Short-Circuit Fix #2261

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private[org] class BooleanMacro[C <: Context](val context: C) {
case argTypeApply: TypeApply => transformAst(argTypeApply.duplicate, prettifierTree)
case _ => simpleMacroBool(rightExpr.duplicate, getText(rightExpr), prettifierTree)
}
if (operator == "&&" || operator == "&") {// generate if (left.value) {...} else false
if (operator == "&&") {// generate if (left.value) {...} else false
If(
Select(
Ident(newTermName("$org_scalatest_assert_macro_left")),
Expand All @@ -469,7 +469,7 @@ private[org] class BooleanMacro[C <: Context](val context: C) {
simpleMacroBool(context.literal(false).tree, "", prettifierTree)
)
}
else if (operator == "||" || operator == "|") // || and |, generate if (left.value) true else {...}
else if (operator == "||") // || and |, generate if (left.value) true else {...}
If(
Select(
Ident(newTermName("$org_scalatest_assert_macro_left")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,14 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
val e = intercept[IllegalArgumentException] {
org.scalactic.Requirements.require(a == 2 & b == 5)
}
assert(e.getMessage == didNotEqual(3, 2))
assert(e.getMessage == commaBut(didNotEqual(3, 2), equaled(5, 5)))
}

it("should throw IllegalArgumentException with correct message and stack depth when is used to check a == 2 & b == 6") {
val e = intercept[IllegalArgumentException] {
org.scalactic.Requirements.require(a == 2 & b == 6)
}
assert(e.getMessage == didNotEqual(3, 2))
assert(e.getMessage == commaAnd(didNotEqual(3, 2), didNotEqual(5, 6)))
}

it("should do nothing when is used to check a == 3 || b == 5") {
Expand Down Expand Up @@ -497,12 +497,12 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
assert(s.state == false)
}

it("should short-circuit & when first condition was false") {
it("should not short-circuit & when first condition was false") {
val s = new Stateful
intercept[IllegalArgumentException] {
org.scalactic.Requirements.require(a == 5 & s.changeState)
}
assert(s.state == false)
assert(s.state == true)
}

it("should short-circuit || when first condition was true") {
Expand All @@ -511,10 +511,10 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
assert(s.state == false)
}

it("should short-circuit | when first condition was true") {
it("should not short-circuit | when first condition was true") {
val s = new Stateful
org.scalactic.Requirements.require(a == 3 | s.changeState)
assert(s.state == false)
assert(s.state == true)
}

it("should do nothing when it is used to check a == 3 && { println(\"hi\"); b == 5}") {
Expand Down Expand Up @@ -1564,14 +1564,14 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
val e = intercept[IllegalArgumentException] {
org.scalactic.Requirements.require(a == 2 & b == 5, ", dude")
}
assert(e.getMessage == didNotEqual(3, 2) + ", dude")
assert(e.getMessage == commaBut(didNotEqual(3, 2), equaled(5, 5)) + ", dude")
}

it("should throw IllegalArgumentException with correct message and stack depth when is used to check a == 2 & b == 6") {
val e = intercept[IllegalArgumentException] {
org.scalactic.Requirements.require(a == 2 & b == 6, ", dude")
}
assert(e.getMessage == didNotEqual(3, 2) + ", dude")
assert(e.getMessage == commaAnd(didNotEqual(3, 2), didNotEqual(5, 6)) + ", dude")
}

it("should do nothing when is used to check a == 3 || b == 5") {
Expand Down Expand Up @@ -1660,12 +1660,12 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
assert(s.state == false)
}

it("should short-circuit & when first condition was false") {
it("should not short-circuit & when first condition was false") {
val s = new Stateful
intercept[IllegalArgumentException] {
org.scalactic.Requirements.require(a == 5 & s.changeState, ", dude")
}
assert(s.state == false)
assert(s.state == true)
}

it("should short-circuit || when first condition was true") {
Expand All @@ -1674,10 +1674,10 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
assert(s.state == false)
}

it("should short-circuit | when first condition was true") {
it("should not short-circuit | when first condition was true") {
val s = new Stateful
org.scalactic.Requirements.require(a == 3 | s.changeState, ", dude")
assert(s.state == false)
assert(s.state == true)
}

it("should do nothing when it is used to check a == 3 && { println(\"hi\"); b == 5}") {
Expand Down Expand Up @@ -2687,14 +2687,14 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
val e = intercept[IllegalStateException] {
org.scalactic.Requirements.requireState(a == 2 & b == 5)
}
assert(e.getMessage == didNotEqual(3, 2))
assert(e.getMessage == commaBut(didNotEqual(3, 2), equaled(5, 5)))
}

it("should throw IllegalStateException with correct message and stack depth when is used to check a == 2 & b == 6") {
val e = intercept[IllegalStateException] {
org.scalactic.Requirements.requireState(a == 2 & b == 6)
}
assert(e.getMessage == didNotEqual(3, 2))
assert(e.getMessage == commaAnd(didNotEqual(3, 2), didNotEqual(5, 6)))
}

it("should do nothing when is used to check a == 3 || b == 5") {
Expand Down Expand Up @@ -2783,12 +2783,12 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
assert(s.state == false)
}

it("should short-circuit & when first condition was false") {
it("should not short-circuit & when first condition was false") {
val s = new Stateful
intercept[IllegalStateException] {
org.scalactic.Requirements.requireState(a == 5 & s.changeState)
}
assert(s.state == false)
assert(s.state == true)
}

it("should short-circuit || when first condition was true") {
Expand All @@ -2797,10 +2797,10 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
assert(s.state == false)
}

it("should short-circuit | when first condition was true") {
it("should not short-circuit | when first condition was true") {
val s = new Stateful
org.scalactic.Requirements.requireState(a == 3 | s.changeState)
assert(s.state == false)
assert(s.state == true)
}

it("should do nothing when it is used to check a == 3 && { println(\"hi\"); b == 5}") {
Expand Down Expand Up @@ -3850,14 +3850,14 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
val e = intercept[IllegalStateException] {
org.scalactic.Requirements.requireState(a == 2 & b == 5, ", dude")
}
assert(e.getMessage == didNotEqual(3, 2) + ", dude")
assert(e.getMessage == commaBut(didNotEqual(3, 2), equaled(5, 5)) + ", dude")
}

it("should throw IllegalStateException with correct message and stack depth when is used to check a == 2 & b == 6") {
val e = intercept[IllegalStateException] {
org.scalactic.Requirements.requireState(a == 2 & b == 6, ", dude")
}
assert(e.getMessage == didNotEqual(3, 2) + ", dude")
assert(e.getMessage == commaAnd(didNotEqual(3, 2), didNotEqual(5, 6)) + ", dude")
}

it("should do nothing when is used to check a == 3 || b == 5") {
Expand Down Expand Up @@ -3946,12 +3946,12 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
assert(s.state == false)
}

it("should short-circuit & when first condition was false") {
it("should not short-circuit & when first condition was false") {
val s = new Stateful
intercept[IllegalStateException] {
org.scalactic.Requirements.requireState(a == 5 & s.changeState, ", dude")
}
assert(s.state == false)
assert(s.state == true)
}

it("should short-circuit || when first condition was true") {
Expand All @@ -3960,10 +3960,10 @@ class DirectRequirementsSpec extends funspec.AnyFunSpec with OptionValues {
assert(s.state == false)
}

it("should short-circuit | when first condition was true") {
it("should not short-circuit | when first condition was true") {
val s = new Stateful
org.scalactic.Requirements.requireState(a == 3 | s.changeState, ", dude")
assert(s.state == false)
assert(s.state == true)
}

it("should do nothing when it is used to check a == 3 && { println(\"hi\"); b == 5}") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,14 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
val e = intercept[IllegalArgumentException] {
require(a == 2 & b == 5)
}
assert(e.getMessage == didNotEqual(3, 2))
assert(e.getMessage == commaBut(didNotEqual(3, 2), equaled(5, 5)))
}

it("should throw IllegalArgumentException with correct message and stack depth when is used to check a == 2 & b == 6") {
val e = intercept[IllegalArgumentException] {
require(a == 2 & b == 6)
}
assert(e.getMessage == didNotEqual(3, 2))
assert(e.getMessage == commaAnd(didNotEqual(3, 2), didNotEqual(5, 6)))
}

it("should do nothing when is used to check a == 3 || b == 5") {
Expand Down Expand Up @@ -497,12 +497,12 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
assert(s.state == false)
}

it("should short-circuit & when first condition was false") {
it("should not short-circuit & when first condition was false") {
val s = new Stateful
intercept[IllegalArgumentException] {
require(a == 5 & s.changeState)
}
assert(s.state == false)
assert(s.state == true)
}

it("should short-circuit || when first condition was true") {
Expand All @@ -511,10 +511,10 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
assert(s.state == false)
}

it("should short-circuit | when first condition was true") {
it("should not short-circuit | when first condition was true") {
val s = new Stateful
require(a == 3 | s.changeState)
assert(s.state == false)
assert(s.state == true)
}

it("should do nothing when it is used to check a == 3 && { println(\"hi\"); b == 5}") {
Expand Down Expand Up @@ -1564,14 +1564,14 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
val e = intercept[IllegalArgumentException] {
require(a == 2 & b == 5, ", dude")
}
assert(e.getMessage == didNotEqual(3, 2) + ", dude")
assert(e.getMessage == commaBut(didNotEqual(3, 2), equaled(5, 5)) + ", dude")
}

it("should throw IllegalArgumentException with correct message and stack depth when is used to check a == 2 & b == 6") {
val e = intercept[IllegalArgumentException] {
require(a == 2 & b == 6, ", dude")
}
assert(e.getMessage == didNotEqual(3, 2) + ", dude")
assert(e.getMessage == commaAnd(didNotEqual(3, 2), didNotEqual(5, 6)) + ", dude")
}

it("should do nothing when is used to check a == 3 || b == 5") {
Expand Down Expand Up @@ -1660,12 +1660,12 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
assert(s.state == false)
}

it("should short-circuit & when first condition was false") {
it("should not short-circuit & when first condition was false") {
val s = new Stateful
intercept[IllegalArgumentException] {
require(a == 5 & s.changeState, ", dude")
}
assert(s.state == false)
assert(s.state == true)
}

it("should short-circuit || when first condition was true") {
Expand All @@ -1674,10 +1674,10 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
assert(s.state == false)
}

it("should short-circuit | when first condition was true") {
it("should not short-circuit | when first condition was true") {
val s = new Stateful
require(a == 3 | s.changeState, ", dude")
assert(s.state == false)
assert(s.state == true)
}

it("should do nothing when it is used to check a == 3 && { println(\"hi\"); b == 5}") {
Expand Down Expand Up @@ -2687,14 +2687,14 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
val e = intercept[IllegalStateException] {
requireState(a == 2 & b == 5)
}
assert(e.getMessage == didNotEqual(3, 2))
assert(e.getMessage == commaBut(didNotEqual(3, 2), equaled(5, 5)))
}

it("should throw IllegalStateException with correct message and stack depth when is used to check a == 2 & b == 6") {
val e = intercept[IllegalStateException] {
requireState(a == 2 & b == 6)
}
assert(e.getMessage == didNotEqual(3, 2))
assert(e.getMessage == commaAnd(didNotEqual(3, 2), didNotEqual(5, 6)))
}

it("should do nothing when is used to check a == 3 || b == 5") {
Expand Down Expand Up @@ -2783,12 +2783,12 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
assert(s.state == false)
}

it("should short-circuit & when first condition was false") {
it("should not short-circuit & when first condition was false") {
val s = new Stateful
intercept[IllegalStateException] {
requireState(a == 5 & s.changeState)
}
assert(s.state == false)
assert(s.state == true)
}

it("should short-circuit || when first condition was true") {
Expand All @@ -2797,10 +2797,10 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
assert(s.state == false)
}

it("should short-circuit | when first condition was true") {
it("should not short-circuit | when first condition was true") {
val s = new Stateful
requireState(a == 3 | s.changeState)
assert(s.state == false)
assert(s.state == true)
}

it("should do nothing when it is used to check a == 3 && { println(\"hi\"); b == 5}") {
Expand Down Expand Up @@ -3850,14 +3850,14 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
val e = intercept[IllegalStateException] {
requireState(a == 2 & b == 5, ", dude")
}
assert(e.getMessage == didNotEqual(3, 2) + ", dude")
assert(e.getMessage == commaBut(didNotEqual(3, 2), equaled(5, 5)) + ", dude")
}

it("should throw IllegalStateException with correct message and stack depth when is used to check a == 2 & b == 6") {
val e = intercept[IllegalStateException] {
requireState(a == 2 & b == 6, ", dude")
}
assert(e.getMessage == didNotEqual(3, 2) + ", dude")
assert(e.getMessage == commaAnd(didNotEqual(3, 2), didNotEqual(5, 6)) + ", dude")
}

it("should do nothing when is used to check a == 3 || b == 5") {
Expand Down Expand Up @@ -3946,12 +3946,12 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
assert(s.state == false)
}

it("should short-circuit & when first condition was false") {
it("should not short-circuit & when first condition was false") {
val s = new Stateful
intercept[IllegalStateException] {
requireState(a == 5 & s.changeState, ", dude")
}
assert(s.state == false)
assert(s.state == true)
}

it("should short-circuit || when first condition was true") {
Expand All @@ -3960,10 +3960,10 @@ class RequirementsSpec extends funspec.AnyFunSpec with Requirements with OptionV
assert(s.state == false)
}

it("should short-circuit | when first condition was true") {
it("should not short-circuit | when first condition was true") {
val s = new Stateful
requireState(a == 3 | s.changeState, ", dude")
assert(s.state == false)
assert(s.state == true)
}

it("should do nothing when it is used to check a == 3 && { println(\"hi\"); b == 5}") {
Expand Down
Loading
Loading