Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ComparisonFailExceptionHandler: instantiate w/ SAM
Browse files Browse the repository at this point in the history
kitbellew committed Jan 20, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 3125eeb commit 721ae80
Showing 3 changed files with 5 additions and 18 deletions.
11 changes: 2 additions & 9 deletions munit/shared/src/main/scala/munit/Assertions.scala
Original file line number Diff line number Diff line change
@@ -252,15 +252,8 @@ trait Assertions extends MacroCompat.CompileErrorMacro {
private def exceptionHandlerFromAssertions(
assertions: Assertions,
clues: => Clues,
): ComparisonFailExceptionHandler = new ComparisonFailExceptionHandler {
def handle(
message: String,
obtained: String,
expected: String,
loc: Location,
): Nothing = assertions
.failComparison(message, obtained, expected, clues)(loc)
}
): ComparisonFailExceptionHandler =
assertions.failComparison(_, _, _, clues)(_)

private val munitCapturedClues: mutable.ListBuffer[Clue[_]] =
mutable.ListBuffer.empty
10 changes: 2 additions & 8 deletions munit/shared/src/main/scala/munit/Compare.scala
Original file line number Diff line number Diff line change
@@ -56,16 +56,10 @@ trait Compare[A, B] {
title: Any,
assertions: Assertions,
)(implicit loc: Location): Nothing = {
val diffHandler = new ComparisonFailExceptionHandler {
override def handle(
message: String,
_obtained: String,
_expected: String,
_loc: Location,
): Nothing = {
val diffHandler: ComparisonFailExceptionHandler = {
(message: String, _obtained: String, _expected: String, _loc: Location) =>
implicit val loc: Location = _loc
assertions.failComparison(message, obtained, expected)
}
}
// Attempt 1: custom pretty-printer that produces multiline output, which is
// optimized for line-by-line diffing.
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ object FullStackTraceFrameworkSuite
"""|at munit.Assertions:failComparison
| at munit.Assertions:failComparison$
| at munit.FunSuite:failComparison
| at munit.Assertions$$anon$1:handle
| at munit.Assertions:$anonfun$exceptionHandlerFromAssertions$1
|==> failure munit.StackTraceFrameworkSuite.fail - tests/shared/src/main/scala/munit/StackTraceFrameworkSuite.scala:4
|3:class StackTraceFrameworkSuite extends FunSuite {
|4: test("fail")(assertNoDiff("a", "b"))

0 comments on commit 721ae80

Please sign in to comment.