Skip to content

Commit ee39e6e

Browse files
authored
Merge pull request #30 from gregorath/weaver-integration
Add integration for Weaver test framework
2 parents dd40247 + 0d1a59a commit ee39e6e

File tree

6 files changed

+74
-9
lines changed

6 files changed

+74
-9
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
matrix:
2525
os: [ubuntu-latest]
26-
scala: [2.13.8, 3.1.1]
26+
scala: [2.13.8, 3.3.0]
2727
java: [temurin@11]
2828
runs-on: ${{ matrix.os }}
2929
steps:
@@ -66,7 +66,7 @@ jobs:
6666
run: sbt ++${{ matrix.scala }} test makeMicrosite publishLocal
6767

6868
- name: Compress target directories
69-
run: tar cf targets.tar modules/benchmarks/target target modules/munit/target docs/target modules/scalatest/target modules/core/target modules/cats/target modules/coretest/target project/target
69+
run: tar cf targets.tar modules/benchmarks/target target modules/munit/target docs/target modules/weaver/target modules/scalatest/target modules/core/target modules/cats/target modules/coretest/target project/target
7070

7171
- name: Upload target directories
7272
uses: actions/upload-artifact@v2
@@ -119,12 +119,12 @@ jobs:
119119
tar xf targets.tar
120120
rm targets.tar
121121
122-
- name: Download target directories (3.1.1)
122+
- name: Download target directories (3.3.0)
123123
uses: actions/download-artifact@v2
124124
with:
125-
name: target-${{ matrix.os }}-3.1.1-${{ matrix.java }}
125+
name: target-${{ matrix.os }}-3.3.0-${{ matrix.java }}
126126

127-
- name: Inflate target directories (3.1.1)
127+
- name: Inflate target directories (3.3.0)
128128
run: |
129129
tar xf targets.tar
130130
rm targets.tar

build.sbt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import sbtghactions.JavaSpec
33
val munitVersion = "0.7.29"
44
val catsVersion = "2.7.0"
55
val scalatestVersion = "3.2.11"
6+
val weaverVersion = "0.8.3"
67

78
val scala213 = "2.13.8"
8-
val scala3 = "3.1.1"
9+
val scala3 = "3.3.0"
910

1011
val isScala3 = Def.setting {
1112
// doesn't work well with >= 3.0.0 for `3.0.0-M1`
@@ -31,7 +32,7 @@ inThisBuild(
3132
)
3233

3334
lazy val difflicious = Project("difflicious", file("."))
34-
.aggregate(core, coretest, benchmarks, cats, docs, munit, scalatest)
35+
.aggregate(core, coretest, benchmarks, cats, docs, munit, scalatest, weaver)
3536
.settings(commonSettings, noPublishSettings)
3637

3738
lazy val core = Project("difflicious-core", file("modules/core"))
@@ -72,6 +73,15 @@ lazy val scalatest = Project("difflicious-scalatest", file("modules/scalatest"))
7273
),
7374
)
7475

76+
lazy val weaver = Project("difflicious-weaver", file("modules/weaver"))
77+
.dependsOn(core)
78+
.settings(commonSettings)
79+
.settings(
80+
libraryDependencies ++= Seq(
81+
"com.disneystreaming" %% "weaver-core" % weaverVersion,
82+
),
83+
)
84+
7585
lazy val cats = Project("difflicious-cats", file("modules/cats"))
7686
.dependsOn(core, coretest % "test->test")
7787
.settings(commonSettings)
@@ -99,7 +109,7 @@ lazy val coretest = Project("coretest", file("modules/coretest"))
99109
)
100110

101111
lazy val docs: Project = project
102-
.dependsOn(core, coretest, cats, munit, scalatest)
112+
.dependsOn(core, coretest, cats, munit, scalatest, weaver)
103113
.enablePlugins(MicrositesPlugin)
104114
.settings(
105115
commonSettings,
@@ -108,6 +118,7 @@ lazy val docs: Project = project
108118
.settings(
109119
libraryDependencies ++= Seq(
110120
"org.scalatest" %% "scalatest" % scalatestVersion,
121+
"com.disneystreaming" %% "weaver-cats" % weaverVersion,
111122
),
112123
makeMicrosite := Def.taskDyn {
113124
val orig = (ThisProject / makeMicrosite).taskValue

docs/docs/docs/LibraryIntegrations.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ class MyTest extends AnyFunSuite {
5555
}
5656
```
5757

58+
## Weaver
59+
60+
Add this to your SBT build
61+
```
62+
"com.github.jatcwang" %% "difflicious-weaver" % "{{ site.version }}" % Test
63+
```
64+
65+
and then in your test suites you can call `assertNoDiff` on any `Differ`.
66+
67+
```scala mdoc:nest
68+
import weaver.SimpleIOSuite
69+
import difflicious.weaver.WeaverDiff._
70+
import difflicious.Differ
71+
72+
object MyTest extends SimpleIOSuite {
73+
pureTest("a == b") {
74+
Differ[Int].assertNoDiff(1, 2)
75+
}
76+
}
77+
```
78+
5879
## Cats
5980

6081
Differ instances for cats data structures like `NonEmptyList` and `Chain` can be found in

modules/coretest/src/test/scala-3/difflicious/DifferAutoDerivationSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DifferAutoDerivationSpec extends ScalaCheckSuite {
1515
assertNoDiff(
1616
result,
1717
"""error:
18-
|no implicit argument of type difflicious.Differ[P1] was found for parameter differ of method apply in object Differ
18+
|No given instance of type difflicious.Differ[P1] was found for parameter differ of method apply in object Differ
1919
|
2020
|The following import might fix the problem:
2121
|
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package difflicious.weaver
2+
3+
import difflicious.{Differ, DiffResultPrinter}
4+
import weaver.{Expectations, SourceLocation}
5+
import weaver.Expectations.Helpers.{failure, success}
6+
7+
trait WeaverDiff {
8+
implicit class DifferExtensions[A](differ: Differ[A]) {
9+
def assertNoDiff(obtained: A, expected: A)(implicit pos: SourceLocation): Expectations = {
10+
val result = differ.diff(obtained, expected)
11+
if (!result.isOk) failure(DiffResultPrinter.consoleOutput(result, 0).render)
12+
else success
13+
}
14+
}
15+
}
16+
17+
object WeaverDiff extends WeaverDiff
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package difflicious.weaver
2+
3+
import difflicious.{Differ, DiffResultPrinter}
4+
import weaver.Expectations
5+
import weaver.Expectations.Helpers.{failure, success}
6+
7+
trait WeaverDiff {
8+
extension [A](differ: Differ[A])
9+
inline def assertNoDiff(obtained: A, expected: A): Expectations = {
10+
val result = differ.diff(obtained, expected)
11+
if (!result.isOk) failure(DiffResultPrinter.consoleOutput(result, 0).render)
12+
else success
13+
}
14+
}
15+
16+
object WeaverDiff extends WeaverDiff

0 commit comments

Comments
 (0)