This repository was archived by the owner on Jan 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Add support for weaver-test #446
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# weaver | ||
|
||
To use with weaver, add the following dependency: | ||
|
||
## sbt | ||
|
||
```scala | ||
"com.softwaremill.weaver" %% "diffx-weaver" % "@VERSION@" % Test | ||
``` | ||
|
||
## mill | ||
|
||
```scala | ||
ivy"com.softwaremill.diffx::diffx-weaver::@VERSION@" | ||
``` | ||
|
||
## Usage | ||
|
||
Then, mixin `DiffxExpectations` trait or add `import com.softwaremill.diffx.weaver.DiffxExpectations._` to your test code. | ||
To assert using diffx use `expectEqual` as follows: | ||
|
||
```scala mdoc:compile-only | ||
import com.softwaremill.diffx.weaver.DiffxExpectations._ | ||
import com.softwaremill.diffx.generic.auto._ | ||
|
||
sealed trait Parent | ||
case class Bar(s: String, i: Int) extends Parent | ||
case class Foo(bar: Bar, b: List[Int], parent: Option[Parent]) extends Parent | ||
|
||
val right: Foo = Foo( | ||
Bar("asdf", 5), | ||
List(123, 1234), | ||
Some(Bar("asdf", 5)) | ||
) | ||
|
||
val left: Foo = Foo( | ||
Bar("asdf", 66), | ||
List(1234), | ||
Some(right) | ||
) | ||
|
||
expectEqual(left, right) | ||
``` | ||
|
||
## Versions matrix | ||
|
||
Below table shows past Diffx releases with the corresponding weaver version they were build with. | ||
For newer versions checkout the release changelog. | ||
|
||
| Diffx | weaver | | ||
|-------|:------:| | ||
| 0.8.4 | 0.8.3 | | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# weaver | ||
|
||
To use with weaver, add the following dependency: | ||
|
||
## sbt | ||
|
||
```scala | ||
"com.softwaremill.weaver" %% "diffx-weaver" % "0.8.3" % Test | ||
``` | ||
|
||
## mill | ||
|
||
```scala | ||
ivy"com.softwaremill.diffx::diffx-weaver::0.8.3" | ||
``` | ||
|
||
## Usage | ||
|
||
Then, mixin `DiffxExpectations` trait or add `import com.softwaremill.diffx.weaver.DiffxExpectations._` to your test code. | ||
To assert using diffx use `expectEqual` as follows: | ||
|
||
```scala | ||
import com.softwaremill.diffx.weaver.DiffxExpectations._ | ||
import com.softwaremill.diffx.generic.auto._ | ||
|
||
sealed trait Parent | ||
case class Bar(s: String, i: Int) extends Parent | ||
case class Foo(bar: Bar, b: List[Int], parent: Option[Parent]) extends Parent | ||
|
||
val right: Foo = Foo( | ||
Bar("asdf", 5), | ||
List(123, 1234), | ||
Some(Bar("asdf", 5)) | ||
) | ||
|
||
val left: Foo = Foo( | ||
Bar("asdf", 66), | ||
List(1234), | ||
Some(right) | ||
) | ||
|
||
expectEqual(left, right) | ||
``` | ||
|
||
## Versions matrix | ||
|
||
Below table shows past Diffx releases with the corresponding weaver version they were build with. | ||
For newer versions checkout the release changelog. | ||
|
||
| Diffx | weaver | | ||
|-------|:------:| | ||
| 0.8.4 | 0.8.3 | | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ with the `Diff.ignore` instance. | |
## collection support | ||
|
||
Specify how objects within particular collection within particular diff instance should be matched. | ||
We distinguish free main types of collections: | ||
We distinguish three main types of collections: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks 😅 |
||
- seqLike collections where elements are indexed collections | ||
- setLike collections where elements aren't indexed | ||
- mapLike collections where elements(values) are indexed by some keys | ||
|
@@ -61,4 +61,4 @@ implicit val diffOrg: Diff[Organization] = Diff.summon[Organization] | |
// mapLike methods: | ||
.modify(_.peopleMap).matchByValue(_.age) | ||
.modify(_.peopleMap).matchByKey(_.weight) | ||
``` | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
weaver/src/main/scala/com/softwaremill/diffx/weaver/DiffxExpectations.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.softwaremill.diffx.weaver | ||
|
||
import com.softwaremill.diffx.{Diff, ShowConfig} | ||
import weaver.Expectations.Helpers.{failure, success} | ||
import weaver.{Expectations, SourceLocation} | ||
|
||
trait DiffxExpectations { | ||
def expectEqual[T: Diff](t1: T, t2: T)(implicit c: ShowConfig, loc: SourceLocation): Expectations = { | ||
val result = Diff.compare(t1, t2) | ||
if (result.isIdentical) | ||
success | ||
else | ||
failure(result.show())(loc) | ||
} | ||
} | ||
|
||
object DiffxExpectations extends DiffxExpectations |
22 changes: 22 additions & 0 deletions
22
weaver/src/test/scala/com/softwaremill/diffx/weaver/DiffxExpectationsTest.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.softwaremill.diffx.weaver | ||
|
||
import cats.data.Validated | ||
import com.softwaremill.diffx.generic.AutoDerivation | ||
import weaver.FunSuite | ||
|
||
object DiffxExpectationsTest extends FunSuite with DiffxExpectations with AutoDerivation { | ||
test("expectEqual should fail when there are differences") { | ||
val n = Person("n1", 11) | ||
expectEqual(n, Person("n2", 12)).run match { | ||
case Validated.Valid(_) => failure(s"Expected a failure but succeeded") | ||
case Validated.Invalid(_) => success | ||
} | ||
} | ||
|
||
test("expectEqual should succeed when there are no differences") { | ||
val n = Person("n1", 11) | ||
expectEqual(n, Person("n1", 11)) | ||
} | ||
} | ||
|
||
case class Person(name: String, age: Int) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scalafmt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should've added it as a CI check.