Skip to content

Commit

Permalink
ComparisonFailExceptionHandler: instantiate w/ SAM
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 20, 2025
1 parent 3125eeb commit 2589fcc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 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
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions munit/shared/src/main/scala/munit/Compare.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2589fcc

Please sign in to comment.