Skip to content

Commit

Permalink
feat: better "obtained empty" help message (#502)
Browse files Browse the repository at this point in the history
* feat: better "obtained empty" help message

Previously, when one used `assertNoDiff` and obtained string was empty there was no clue what does `expected` looks like. Because of that, sometimes it wasn't clear which comparison fails.
Now, in the case when `obtained` is empty, `expected` is being printed.
  • Loading branch information
kpodsiad authored Apr 4, 2022
1 parent db22e0b commit 535a774
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ object Diffs {
printObtainedAsStripMargin: Boolean
)(implicit loc: Location): Boolean = {
if (obtained.isEmpty && !expected.isEmpty) {
handler.handle("Obtained empty output!", obtained, expected, loc)
val msg =
s"""|Obtained empty output!
|=> Expected:
|$expected""".stripMargin
handler.handle(msg, obtained, expected, loc)
}
val diff = new Diff(obtained, expected)
if (diff.isEmpty) true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,21 @@ class ComparisonFailExceptionSuite extends BaseSuite {
)
}

test("assert-no-diff-obtained-empty") {
val e = intercept[ComparisonFailException] {
assertNoDiff("", "Lorem ipsum")
}
assertNoDiff(
e.getMessage(),
"""|ComparisonFailExceptionSuite.scala:59
|58: val e = intercept[ComparisonFailException] {
|59: assertNoDiff("", "Lorem ipsum")
|60: }
|Obtained empty output!
|=> Expected:
|Lorem ipsum
|""".stripMargin
)
}

}

0 comments on commit 535a774

Please sign in to comment.