Skip to content

Commit

Permalink
Merge branch 'cheeseng-feature-backport-3.2-macro-short-circuit-fix' …
Browse files Browse the repository at this point in the history
…into 3.2.x-new
  • Loading branch information
bvenners committed Aug 30, 2023
2 parents a0dbb13 + 5b81f61 commit 67fa487
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 118 deletions.
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

0 comments on commit 67fa487

Please sign in to comment.