Skip to content

Commit

Permalink
Refactor error message checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Sep 11, 2023
1 parent 9d14600 commit 996b0db
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class TotalTransformerEnumSpec extends ChimneySpec {
"Consult https://chimney.readthedocs.io for usage examples."
)

assert(
!error.contains("coproduct instance Circle of io.scalaland.chimney.fixtures.shapes5enums.Shape is ambiguous")
error.checkNot(
"coproduct instance Circle of io.scalaland.chimney.fixtures.shapes5enums.Shape is ambiguous"
)
}

Expand Down
34 changes: 25 additions & 9 deletions chimney/src/test/scala/io/scalaland/chimney/ChimneySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,31 @@ trait ChimneySpec extends munit.BaseFunSuite with VersionCompat { self =>

implicit class CompileErrorsCheck(msg: String) {

def check(msgs: String*): Unit = for (msg <- msgs)
Predef.assert(
ChimneySpec.AnsiControlCode.replaceAllIn(this.msg, "").contains(msg),
"Error message did not contain expected snippet\n" +
"Error message\n" +
this.msg + "\n" +
"Expected Snippet\n" +
msg
)
def check(msgs: String*): Unit = {
val msgNoColors = ChimneySpec.AnsiControlCode.replaceAllIn(this.msg, "")
for (msg <- msgs)
Predef.assert(
msgNoColors.contains(msg),
s"""Error message did not contain expected snippet
|Error message
|${this.msg}
|Expected Snippet
|$msg""".stripMargin
)
}

def checkNot(msgs: String*): Unit = {
val msgNoColors = ChimneySpec.AnsiControlCode.replaceAllIn(this.msg, "")
for (msg <- msgs)
Predef.assert(
!msgNoColors.contains(msg),
s"""Error message contain snippet that was expected to be not there
|Error message
|${this.msg}
|Not Expected Snippet
|$msg""".stripMargin
)
}

def arePresent(): Unit = Predef.assert(msg.nonEmpty, "Expected compilation errors")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class TotalTransformerSealedHierarchySpec extends ChimneySpec {
"Consult https://chimney.readthedocs.io for usage examples."
)

assert(
!error.contains("coproduct instance Circle of io.scalaland.chimney.fixtures.shapes5.Shape is ambiguous")
error.checkNot(
"coproduct instance Circle of io.scalaland.chimney.fixtures.shapes5.Shape is ambiguous"
)
}

Expand Down

0 comments on commit 996b0db

Please sign in to comment.