Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 34ce1fc

Browse files
committed
Fix testFrameworks integrations
1 parent 57cf2d8 commit 34ce1fc

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

munit/src/main/scala/com/softwaremill/diffx/munit/DiffxAssertions.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.softwaremill.diffx.munit
22

3-
import com.softwaremill.diffx.{ConsoleColorConfig, Diff, DiffResultDifferent}
3+
import com.softwaremill.diffx.{ConsoleColorConfig, Diff}
44
import munit.Assertions._
55
import munit.Location
66

77
trait DiffxAssertions {
88
def assertEqual[T: Diff](t1: T, t2: T)(implicit c: ConsoleColorConfig, loc: Location): Unit = {
99
val result = Diff.compare(t1, t2)
10-
result match {
11-
case different: DiffResultDifferent => fail(different.show())(loc)
12-
case _ => // do nothing
10+
if (!result.isIdentical) {
11+
fail(result.show())(loc)
1312
}
1413
}
1514
}

scalatest/src/main/scala/com/softwaremill/diffx/scalatest/DiffMatcher.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.softwaremill.diffx.scalatest
22

3-
import com.softwaremill.diffx.{ConsoleColorConfig, Diff, DiffResultDifferent}
3+
import com.softwaremill.diffx.{ConsoleColorConfig, Diff}
44
import org.scalatest.matchers.{MatchResult, Matcher}
55

66
trait DiffMatcher {
77
def matchTo[A: Diff](right: A)(implicit c: ConsoleColorConfig): Matcher[A] = { left =>
8-
Diff[A].apply(left, right) match {
9-
case c: DiffResultDifferent =>
10-
val diff = c.show().split('\n').mkString(Console.RESET, s"${Console.RESET}\n${Console.RESET}", Console.RESET)
11-
MatchResult(matches = false, s"Matching error:\n$diff", "")
12-
case _ => MatchResult(matches = true, "", "")
8+
val result = Diff[A].apply(left, right)
9+
if (!result.isIdentical) {
10+
val diff = result.show().split('\n').mkString(Console.RESET, s"${Console.RESET}\n${Console.RESET}", Console.RESET)
11+
MatchResult(matches = false, s"Matching error:\n$diff", "")
12+
} else {
13+
MatchResult(matches = true, "", "")
1314
}
1415
}
1516
}

specs2/src/main/scala/com/softwaremill/diffx/specs2/DiffMatcher.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.softwaremill.diffx.specs2
22

3-
import com.softwaremill.diffx.{ConsoleColorConfig, Diff, DiffResultDifferent}
3+
import com.softwaremill.diffx.{ConsoleColorConfig, Diff}
44
import org.specs2.matcher.{Expectable, MatchResult, Matcher}
55

66
trait DiffMatcher {
@@ -14,11 +14,13 @@ trait DiffMatcher {
1414
diff.apply(left.value, right).isIdentical
1515
},
1616
okMessage = "",
17-
koMessage = diff.apply(left.value, right) match {
18-
case c: DiffResultDifferent =>
19-
c.show()
20-
case _ =>
17+
koMessage = {
18+
val diffResult = diff.apply(left.value, right)
19+
if (!diffResult.isIdentical) {
20+
diffResult.show()
21+
} else {
2122
""
23+
}
2224
},
2325
left
2426
)

utest/src/main/scala/com/softwaremill/diffx/utest/DiffxAssertions.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.softwaremill.diffx.utest
22

3-
import com.softwaremill.diffx.{ConsoleColorConfig, Diff, DiffResultDifferent}
3+
import com.softwaremill.diffx.{ConsoleColorConfig, Diff}
44
import utest.AssertionError
55

66
trait DiffxAssertions {
77

88
def assertEqual[T: Diff](t1: T, t2: T)(implicit c: ConsoleColorConfig): Unit = {
99
val result = Diff.compare(t1, t2)
10-
result match {
11-
case different: DiffResultDifferent => throw AssertionError(different.show(), Seq.empty, null)
12-
case _ => // do nothing
10+
if (!result.isIdentical) {
11+
throw AssertionError(result.show(), Seq.empty, null)
1312
}
1413
}
1514
}

0 commit comments

Comments
 (0)