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

Commit 4612801

Browse files
Merge pull request #446 from dabd/master
Add support for weaver-test
2 parents cbdb01c + 684cf7d commit 4612801

File tree

8 files changed

+174
-12
lines changed

8 files changed

+174
-12
lines changed

build.sbt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,23 @@ lazy val munit = (projectMatrix in file("munit"))
209209
settings = commonSettings ++ Seq(scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) })
210210
)
211211

212+
lazy val weaver = (projectMatrix in file("weaver"))
213+
.settings(commonSettings)
214+
.settings(
215+
name := "diffx-weaver",
216+
libraryDependencies ++= Seq(
217+
"com.disneystreaming" %%% "weaver-cats" % "0.8.3"
218+
),
219+
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
220+
)
221+
.dependsOn(core)
222+
.jvmPlatform(
223+
scalaVersions = List(scala212, scala213, scala3)
224+
)
225+
.jsPlatform(
226+
scalaVersions = List(scala212, scala213, scala3)
227+
)
228+
212229
lazy val tagging = (projectMatrix in file("tagging"))
213230
.settings(commonSettings)
214231
.settings(
@@ -280,7 +297,7 @@ lazy val docs = (projectMatrix in file("generated-docs")) // important: it must
280297
),
281298
mdocOut := file("generated-docs/out")
282299
)
283-
.dependsOn(core, scalatestShould, specs2, utest, refined, tagging, cats, munit)
300+
.dependsOn(core, scalatestShould, specs2, utest, refined, tagging, cats, munit, weaver)
284301
.jvmPlatform(scalaVersions = List(scala213))
285302

286303
val testJVM = taskKey[Unit]("Test JVM projects")
@@ -289,7 +306,7 @@ val testJS = taskKey[Unit]("Test JS projects")
289306
val allAggregates =
290307
core.projectRefs ++ scalatestMust.projectRefs ++ scalatestShould.projectRefs ++ scalatestLegacy.projectRefs ++
291308
specs2.projectRefs ++ utest.projectRefs ++ cats.projectRefs ++
292-
refined.projectRefs ++ tagging.projectRefs ++ docs.projectRefs ++ munit.projectRefs
309+
refined.projectRefs ++ tagging.projectRefs ++ docs.projectRefs ++ munit.projectRefs ++ weaver.projectRefs
293310

294311
def filterProject(p: String => Boolean) =
295312
ScopeFilter(inProjects(allAggregates.filter(pr => p(display(pr.project))): _*))
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# weaver
2+
3+
To use with weaver, add the following dependency:
4+
5+
## sbt
6+
7+
```scala
8+
"com.softwaremill.weaver" %% "diffx-weaver" % "@VERSION@" % Test
9+
```
10+
11+
## mill
12+
13+
```scala
14+
ivy"com.softwaremill.diffx::diffx-weaver::@VERSION@"
15+
```
16+
17+
## Usage
18+
19+
Then, mixin `DiffxExpectations` trait or add `import com.softwaremill.diffx.weaver.DiffxExpectations._` to your test code.
20+
To assert using diffx use `expectEqual` as follows:
21+
22+
```scala mdoc:compile-only
23+
import com.softwaremill.diffx.weaver.DiffxExpectations._
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+
expectEqual(left, right)
43+
```
44+
45+
## Versions matrix
46+
47+
Below table shows past Diffx releases with the corresponding weaver version they were build with.
48+
For newer versions checkout the release changelog.
49+
50+
| Diffx | weaver |
51+
|-------|:------:|
52+
| 0.8.4 | 0.8.3 |
53+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# weaver
2+
3+
To use with weaver, add the following dependency:
4+
5+
## sbt
6+
7+
```scala
8+
"com.softwaremill.weaver" %% "diffx-weaver" % "0.8.3" % Test
9+
```
10+
11+
## mill
12+
13+
```scala
14+
ivy"com.softwaremill.diffx::diffx-weaver::0.8.3"
15+
```
16+
17+
## Usage
18+
19+
Then, mixin `DiffxExpectations` trait or add `import com.softwaremill.diffx.weaver.DiffxExpectations._` to your test code.
20+
To assert using diffx use `expectEqual` as follows:
21+
22+
```scala
23+
import com.softwaremill.diffx.weaver.DiffxExpectations._
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+
expectEqual(left, right)
43+
```
44+
45+
## Versions matrix
46+
47+
Below table shows past Diffx releases with the corresponding weaver version they were build with.
48+
For newer versions checkout the release changelog.
49+
50+
| Diffx | weaver |
51+
|-------|:------:|
52+
| 0.8.4 | 0.8.3 |
53+

generated-docs/out/usage/ignoring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ implicit val conf: DiffConfiguration = DiffConfiguration(makeIgnored =
4444
)
4545
// conf: DiffConfiguration = DiffConfiguration(makeIgnored = <function1>)
4646
val d = Diff[Person].ignore(_.age)
47-
// d: Diff[Person] = com.softwaremill.diffx.Diff$$anon$1@3c4f66a2
47+
// d: Diff[Person] = com.softwaremill.diffx.Diff$$anon$1@2b53172e
4848
d(Person("bob", 25), Person("bob", 30))
4949
// res2: DiffResult = DiffResultObject(
5050
// name = "Person",

generated-docs/out/usage/modifying.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ with the `Diff.ignore` instance.
4242
## collection support
4343

4444
Specify how objects within particular collection within particular diff instance should be matched.
45-
We distinguish free main types of collections:
45+
We distinguish three main types of collections:
4646
- seqLike collections where elements are indexed collections
4747
- setLike collections where elements aren't indexed
4848
- mapLike collections where elements(values) are indexed by some keys
@@ -61,4 +61,4 @@ implicit val diffOrg: Diff[Organization] = Diff.summon[Organization]
6161
// mapLike methods:
6262
.modify(_.peopleMap).matchByValue(_.age)
6363
.modify(_.peopleMap).matchByKey(_.weight)
64-
```
64+
```

generated-docs/out/usage/output.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ By default, it is set to an identical function.
4747
```scala
4848
implicit val showConfig = ShowConfig.default.copy(transformer = DiffResultTransformer.skipIdentical)
4949
// showConfig: ShowConfig = ShowConfig(
50-
// left = com.softwaremill.diffx.ShowConfig$$$Lambda$10463/0x0000000802afe890@2988c7f6,
51-
// right = com.softwaremill.diffx.ShowConfig$$$Lambda$10463/0x0000000802afe890@5f94affc,
52-
// missing = com.softwaremill.diffx.ShowConfig$$$Lambda$10463/0x0000000802afe890@2b1e794e,
53-
// additional = com.softwaremill.diffx.ShowConfig$$$Lambda$10463/0x0000000802afe890@65ca52ad,
54-
// default = com.softwaremill.diffx.ShowConfig$$$Lambda$10466/0x0000000802aff058@a929e95,
55-
// arrow = com.softwaremill.diffx.ShowConfig$$$Lambda$10463/0x0000000802afe890@70032b74,
56-
// transformer = com.softwaremill.diffx.DiffResultTransformer$$$Lambda$10455/0x0000000802afc958@280fe833
50+
// left = com.softwaremill.diffx.ShowConfig$$$Lambda$12994/0x0000000802fcd840@44247db5,
51+
// right = com.softwaremill.diffx.ShowConfig$$$Lambda$12994/0x0000000802fcd840@66c2460c,
52+
// missing = com.softwaremill.diffx.ShowConfig$$$Lambda$12994/0x0000000802fcd840@4f023172,
53+
// additional = com.softwaremill.diffx.ShowConfig$$$Lambda$12994/0x0000000802fcd840@3b0ad140,
54+
// default = com.softwaremill.diffx.ShowConfig$$$Lambda$12997/0x0000000802fca040@5c24da41,
55+
// arrow = com.softwaremill.diffx.ShowConfig$$$Lambda$12994/0x0000000802fcd840@28a205ef,
56+
// transformer = com.softwaremill.diffx.DiffResultTransformer$$$Lambda$12986/0x0000000802d76840@76752828
5757
// )
5858
case class Person(name:String, age:Int)
5959

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.softwaremill.diffx.weaver
2+
3+
import com.softwaremill.diffx.{Diff, ShowConfig}
4+
import weaver.Expectations.Helpers.{failure, success}
5+
import weaver.{Expectations, SourceLocation}
6+
7+
trait DiffxExpectations {
8+
def expectEqual[T: Diff](t1: T, t2: T)(implicit c: ShowConfig, loc: SourceLocation): Expectations = {
9+
val result = Diff.compare(t1, t2)
10+
if (result.isIdentical)
11+
success
12+
else
13+
failure(result.show())(loc)
14+
}
15+
}
16+
17+
object DiffxExpectations extends DiffxExpectations
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.softwaremill.diffx.weaver
2+
3+
import cats.data.Validated
4+
import com.softwaremill.diffx.generic.AutoDerivation
5+
import weaver.FunSuite
6+
7+
object DiffxExpectationsTest extends FunSuite with DiffxExpectations with AutoDerivation {
8+
test("expectEqual should fail when there are differences") {
9+
val n = Person("n1", 11)
10+
expectEqual(n, Person("n2", 12)).run match {
11+
case Validated.Valid(_) => failure(s"Expected a failure but succeeded")
12+
case Validated.Invalid(_) => success
13+
}
14+
}
15+
16+
test("expectEqual should succeed when there are no differences") {
17+
val n = Person("n1", 11)
18+
expectEqual(n, Person("n1", 11))
19+
}
20+
}
21+
22+
case class Person(name: String, age: Int)

0 commit comments

Comments
 (0)