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

Commit a88246a

Browse files
committed
Add integration with munit
1 parent 637bb6e commit a88246a

File tree

9 files changed

+145
-2
lines changed

9 files changed

+145
-2
lines changed

build.sbt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ lazy val utest = (projectMatrix in file("utest"))
117117
scalaVersions = List(scala212, scala213)
118118
)
119119

120+
lazy val munit = (projectMatrix in file("munit"))
121+
.settings(commonSettings)
122+
.settings(
123+
name := "diffx-munit",
124+
libraryDependencies ++= Seq(
125+
"org.scalameta" %%% "munit" % "0.7.26"
126+
)
127+
)
128+
.dependsOn(core)
129+
.jvmPlatform(
130+
scalaVersions = List(scala212, scala213)
131+
)
132+
.jsPlatform(
133+
scalaVersions = List(scala212, scala213)
134+
)
135+
120136
lazy val tagging = (projectMatrix in file("tagging"))
121137
.settings(commonSettings)
122138
.settings(
@@ -189,7 +205,7 @@ lazy val docs = (projectMatrix in file("generated-docs")) // important: it must
189205
),
190206
mdocOut := file("generated-docs/out")
191207
)
192-
.dependsOn(core, scalatest, specs2, utest, refined, tagging, cats)
208+
.dependsOn(core, scalatest, specs2, utest, refined, tagging, cats, munit)
193209
.jvmPlatform(scalaVersions = List(scala213))
194210

195211
val testJVM = taskKey[Unit]("Test JVM projects")
@@ -198,7 +214,7 @@ val testJS = taskKey[Unit]("Test JS projects")
198214
val allAggregates =
199215
core.projectRefs ++ scalatest.projectRefs ++
200216
specs2.projectRefs ++ utest.projectRefs ++ cats.projectRefs ++
201-
refined.projectRefs ++ tagging.projectRefs ++ docs.projectRefs
217+
refined.projectRefs ++ tagging.projectRefs ++ docs.projectRefs ++ munit.projectRefs
202218

203219
def filterProject(p: String => Boolean) =
204220
ScopeFilter(inProjects(allAggregates.filter(pr => p(display(pr.project))): _*))

docs-sources/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ a software development and consulting company. We help clients scale their busin
7676
test-frameworks/scalatest
7777
test-frameworks/specs2
7878
test-frameworks/utest
79+
test-frameworks/munit
7980
test-frameworks/summary
8081
8182
.. toctree::

docs-sources/test-frameworks/munit.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# munit
2+
3+
To use with munit, add following dependency:
4+
5+
## sbt
6+
7+
```scala
8+
"com.softwaremill.diffx" %% "diffx-munit" % "@VERSION@" % Test
9+
```
10+
11+
## mill
12+
13+
```scala
14+
ivy"com.softwaremill.diffx::diffx-munit::@VERSION@"
15+
```
16+
17+
## Usage
18+
19+
Then, mixin `DiffxAssertions` trait or add `import com.softwaremill.diffx.munit.DiffxAssertions._` to your test code.
20+
To assert using diffx use `assertEquals` as follows:
21+
22+
```scala mdoc:compile-only
23+
import com.softwaremill.diffx.munit.DiffxAssertions._
24+
import com.softwaremill.diffx.generic.auto._
25+
26+
sealed trait Parent
27+
case class Bar(s: String, i: Int) extends Parent
28+
case class Foo(bar: Bar, b: List[Int], parent: Option[Parent]) extends Parent
29+
30+
val right: Foo = Foo(
31+
Bar("asdf", 5),
32+
List(123, 1234),
33+
Some(Bar("asdf", 5))
34+
)
35+
36+
val left: Foo = Foo(
37+
Bar("asdf", 66),
38+
List(1234),
39+
Some(right)
40+
)
41+
42+
assertEqual(left, right)
43+
```
44+

docs-sources/test-frameworks/summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Following test frameworks are supported by diffx:
44
- [scalatest](scalatest.md)
55
- [specs2](specs2.md)
66
- [utest](utest.md)
7+
- [munit](munit.md)
78

89
Didn't find your favourite testing library? Don't hesitate and let us know, or you can add it on your own ,
910
as all that needs to be done is to call `compare` function.

generated-docs/out/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ a software development and consulting company. We help clients scale their busin
115115
test-frameworks/scalatest
116116
test-frameworks/specs2
117117
test-frameworks/utest
118+
test-frameworks/munit
118119
test-frameworks/summary
119120
120121
.. toctree::
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# munit
2+
3+
To use with munit, add following dependency:
4+
5+
## sbt
6+
7+
```scala
8+
"com.softwaremill.diffx" %% "diffx-munit" % "0.5.1" % Test
9+
```
10+
11+
## mill
12+
13+
```scala
14+
ivy"com.softwaremill.diffx::diffx-munit::0.5.1"
15+
```
16+
17+
## Usage
18+
19+
Then, mixin `DiffxAssertions` trait or add `import com.softwaremill.diffx.munit.DiffxAssertions._` to your test code.
20+
To assert using diffx use `assertEquals` as follows:
21+
22+
```scala
23+
import com.softwaremill.diffx.munit.DiffxAssertions._
24+
import com.softwaremill.diffx.generic.auto._
25+
26+
sealed trait Parent
27+
case class Bar(s: String, i: Int) extends Parent
28+
case class Foo(bar: Bar, b: List[Int], parent: Option[Parent]) extends Parent
29+
30+
val right: Foo = Foo(
31+
Bar("asdf", 5),
32+
List(123, 1234),
33+
Some(Bar("asdf", 5))
34+
)
35+
36+
val left: Foo = Foo(
37+
Bar("asdf", 66),
38+
List(1234),
39+
Some(right)
40+
)
41+
42+
assertEqual(left, right)
43+
```
44+

generated-docs/out/test-frameworks/summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Following test frameworks are supported by diffx:
44
- [scalatest](scalatest.md)
55
- [specs2](specs2.md)
66
- [utest](utest.md)
7+
- [munit](munit.md)
78

89
Didn't find your favourite testing library? Don't hesitate and let us know, or you can add it on your own ,
910
as all that needs to be done is to call `compare` function.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.softwaremill.diffx.munit
2+
3+
import com.softwaremill.diffx.{ConsoleColorConfig, Diff, DiffResultDifferent}
4+
import munit.Assertions._
5+
import munit.Location
6+
7+
trait DiffxAssertions {
8+
def assertEqual[T: Diff](t1: T, t2: T)(implicit c: ConsoleColorConfig, loc: Location): Unit = {
9+
val result = Diff.compare(t1, t2)
10+
result match {
11+
case different: DiffResultDifferent => fail(different.show())(loc)
12+
case _ => // do nothing
13+
}
14+
}
15+
}
16+
17+
object DiffxAssertions extends DiffxAssertions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.softwaremill.diffx.munit
2+
3+
import com.softwaremill.diffx.generic.auto._
4+
5+
class MunitAssertTest extends munit.FunSuite with DiffxAssertions {
6+
// uncomment to run
7+
// test("failing test") {
8+
// val n = Person("n1", 11)
9+
// assertEqual(n, Person("n2", 12))
10+
// }
11+
12+
test("hello") {
13+
val n = Person("n1", 11)
14+
assertEqual(n, Person("n1", 11))
15+
}
16+
}
17+
18+
case class Person(name: String, age: Int)

0 commit comments

Comments
 (0)