Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use munit diff logic #25

Merged
merged 10 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,31 @@ jobs:
modules-ignore: rootjs_2.12 rootjs_2.13 rootjs_3 docs-output_2.12 docs-output_2.13 docs-output_3 weaver-docs_2.12 weaver-docs_2.13 weaver-docs_3 rootjvm_2.12 rootjvm_2.13 rootjvm_3 rootnative_2.12 rootnative_2.13 rootnative_3
configs-ignore: test scala-tool scala-doc-tool test-internal

validate-steward:
name: Validate Steward Config
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (fast)
uses: actions/checkout@v4

- name: Setup Java (temurin@11)
id: setup-java-temurin-11
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11

- uses: coursier/setup-action@v1
with:
apps: scala-steward

- run: scala-steward validate-repo-config .scala-steward.conf

site:
name: Generate Site
strategy:
Expand Down
1 change: 1 addition & 0 deletions .scala-steward.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
updates.ignore = [ { groupId = "org.scalameta", artifactId="scala-diff" } ]
13 changes: 10 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ val Version = new {
val testInterface = "1.0"
val scalacCompatAnnotation = "0.1.4"
val http4s = "0.23.26"
val munitDiff = "1.0.0-RC1"
}

lazy val root = tlCrossRootProject.aggregate(core,
Expand All @@ -71,9 +72,15 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
"com.eed3si9n.expecty" %%% "expecty" % Version.expecty,
// https://github.com/portable-scala/portable-scala-reflect/issues/23
"org.portable-scala" %%% "portable-scala-reflect" % Version.portableReflect cross CrossVersion.for3Use2_13,
"org.typelevel" %% "scalac-compat-annotation" % Version.scalacCompatAnnotation
)
)
"org.typelevel" %% "scalac-compat-annotation" % Version.scalacCompatAnnotation,
"org.scalameta" %%% "munit-diff" % Version.munitDiff
),
// Shades the scala-diff dependency.
shadedDependencies += "org.scalameta" %%% "munit-diff" % "<ignored>",
shadingRules += ShadingRule.moveUnder("munit.diff",
"weaver.internal.shaded"),
validNamespaces ++= Set("weaver", "org")
).enablePlugins(ShadingPlugin)

lazy val coreJVM = core.jvm
.settings(
Expand Down
12 changes: 3 additions & 9 deletions modules/core/shared/src/main/scala/weaver/Comparison.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package weaver

import cats.Eq
import cats.Show
import com.eed3si9n.expecty._
import scala.annotation.implicitNotFound
import munit.diff.Diffs

/**
* A type class used to compare two instances of the same type and construct an
Expand Down Expand Up @@ -44,14 +44,8 @@ object Comparison {
if (eqv.eqv(found, expected)) {
Result.Success
} else {
val expectedLines = showA.show(expected).linesIterator.toSeq
val foundLines = showA.show(found).linesIterator.toSeq
val report = DiffUtil
.mkColoredLineDiff(expectedLines, foundLines)
.linesIterator
.toSeq
.map(str => Console.RESET.toString + str)
.mkString("\n")
val report =
Diffs.createDiffOnlyReport(showA.show(found), showA.show(expected))
Result.Failure(report)
}
}
Expand Down
22 changes: 10 additions & 12 deletions modules/framework-cats/shared/src/test/scala/DogFoodTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,11 @@ object DogFoodTests extends IOSuite {
|- (eql Comparison) 0ms
| Values not equal: (src/main/DogFoodTests.scala:5)
|
| Foo { | Foo {
| s: foo | s: foo
| i: [1] | i: [2]
| } | }
""".stripMargin.trim

| => Diff (- obtained, + expected)
| s: foo
| - i: 2
| + i: 1
| }""".stripMargin.trim
expect.same(actual, expected)
}
}
Expand All @@ -292,12 +291,11 @@ object DogFoodTests extends IOSuite {
|- (same Comparison) 0ms
| Values not equal: (src/main/DogFoodTests.scala:5)
|
| Foo { | Foo {
| s: foo | s: foo
| i: [1] | i: [2]
| } | }
""".stripMargin.trim

| => Diff (- obtained, + expected)
| s: foo
| - i: 2
| + i: 1
| }""".stripMargin.trim
expect.same(actual, expected)
}
}
Expand Down
4 changes: 3 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// format: off
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.0")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.15.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")

addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.16")

Expand All @@ -12,3 +12,5 @@ addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.6.7")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.2")

addSbtPlugin("io.get-coursier" % "sbt-shading" % "2.1.4")