Skip to content

Commit

Permalink
Merge pull request #30 from gregorath/weaver-integration
Browse files Browse the repository at this point in the history
Add integration for Weaver test framework
  • Loading branch information
jatcwang authored Aug 7, 2023
2 parents dd40247 + 0d1a59a commit ee39e6e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8, 3.1.1]
scala: [2.13.8, 3.3.0]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
run: sbt ++${{ matrix.scala }} test makeMicrosite publishLocal

- name: Compress target directories
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
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

- name: Upload target directories
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -119,12 +119,12 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.1)
- name: Download target directories (3.3.0)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-3.1.1-${{ matrix.java }}
name: target-${{ matrix.os }}-3.3.0-${{ matrix.java }}

- name: Inflate target directories (3.1.1)
- name: Inflate target directories (3.3.0)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
17 changes: 14 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import sbtghactions.JavaSpec
val munitVersion = "0.7.29"
val catsVersion = "2.7.0"
val scalatestVersion = "3.2.11"
val weaverVersion = "0.8.3"

val scala213 = "2.13.8"
val scala3 = "3.1.1"
val scala3 = "3.3.0"

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

lazy val difflicious = Project("difflicious", file("."))
.aggregate(core, coretest, benchmarks, cats, docs, munit, scalatest)
.aggregate(core, coretest, benchmarks, cats, docs, munit, scalatest, weaver)
.settings(commonSettings, noPublishSettings)

lazy val core = Project("difflicious-core", file("modules/core"))
Expand Down Expand Up @@ -72,6 +73,15 @@ lazy val scalatest = Project("difflicious-scalatest", file("modules/scalatest"))
),
)

lazy val weaver = Project("difflicious-weaver", file("modules/weaver"))
.dependsOn(core)
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(
"com.disneystreaming" %% "weaver-core" % weaverVersion,
),
)

lazy val cats = Project("difflicious-cats", file("modules/cats"))
.dependsOn(core, coretest % "test->test")
.settings(commonSettings)
Expand Down Expand Up @@ -99,7 +109,7 @@ lazy val coretest = Project("coretest", file("modules/coretest"))
)

lazy val docs: Project = project
.dependsOn(core, coretest, cats, munit, scalatest)
.dependsOn(core, coretest, cats, munit, scalatest, weaver)
.enablePlugins(MicrositesPlugin)
.settings(
commonSettings,
Expand All @@ -108,6 +118,7 @@ lazy val docs: Project = project
.settings(
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalatestVersion,
"com.disneystreaming" %% "weaver-cats" % weaverVersion,
),
makeMicrosite := Def.taskDyn {
val orig = (ThisProject / makeMicrosite).taskValue
Expand Down
21 changes: 21 additions & 0 deletions docs/docs/docs/LibraryIntegrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ class MyTest extends AnyFunSuite {
}
```

## Weaver

Add this to your SBT build
```
"com.github.jatcwang" %% "difflicious-weaver" % "{{ site.version }}" % Test
```

and then in your test suites you can call `assertNoDiff` on any `Differ`.

```scala mdoc:nest
import weaver.SimpleIOSuite
import difflicious.weaver.WeaverDiff._
import difflicious.Differ

object MyTest extends SimpleIOSuite {
pureTest("a == b") {
Differ[Int].assertNoDiff(1, 2)
}
}
```

## Cats

Differ instances for cats data structures like `NonEmptyList` and `Chain` can be found in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DifferAutoDerivationSpec extends ScalaCheckSuite {
assertNoDiff(
result,
"""error:
|no implicit argument of type difflicious.Differ[P1] was found for parameter differ of method apply in object Differ
|No given instance of type difflicious.Differ[P1] was found for parameter differ of method apply in object Differ
|
|The following import might fix the problem:
|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package difflicious.weaver

import difflicious.{Differ, DiffResultPrinter}
import weaver.{Expectations, SourceLocation}
import weaver.Expectations.Helpers.{failure, success}

trait WeaverDiff {
implicit class DifferExtensions[A](differ: Differ[A]) {
def assertNoDiff(obtained: A, expected: A)(implicit pos: SourceLocation): Expectations = {
val result = differ.diff(obtained, expected)
if (!result.isOk) failure(DiffResultPrinter.consoleOutput(result, 0).render)
else success
}
}
}

object WeaverDiff extends WeaverDiff
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package difflicious.weaver

import difflicious.{Differ, DiffResultPrinter}
import weaver.Expectations
import weaver.Expectations.Helpers.{failure, success}

trait WeaverDiff {
extension [A](differ: Differ[A])
inline def assertNoDiff(obtained: A, expected: A): Expectations = {
val result = differ.diff(obtained, expected)
if (!result.isOk) failure(DiffResultPrinter.consoleOutput(result, 0).render)
else success
}
}

object WeaverDiff extends WeaverDiff

0 comments on commit ee39e6e

Please sign in to comment.