forked from scalameta/munit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scalameta#222 from olafurpg/comparison-failure
Introduce a new "failComparison()" helper
- Loading branch information
Showing
14 changed files
with
234 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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
11 changes: 11 additions & 0 deletions
11
munit/native/src/main/scala/org/junit/ComparisonFailure.scala
This file contains 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,11 @@ | ||
package org.junit | ||
|
||
class ComparisonFailure(message: String, fExpected: String, fActual: String) | ||
extends AssertionError(message) { | ||
|
||
override def getMessage(): String = message | ||
|
||
def getActual(): String = fActual | ||
|
||
def getExpected(): String = fExpected | ||
} |
This file contains 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
32 changes: 32 additions & 0 deletions
32
munit/shared/src/main/scala/munit/ComparisonFailException.scala
This file contains 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,32 @@ | ||
package munit | ||
|
||
import org.junit.ComparisonFailure | ||
|
||
/** | ||
* The base exception for all comparison failures. | ||
* | ||
* This class exists so that it can extend `org.junit.ComparisonFailure`, | ||
* which is recognised by IntelliJ so that users can optionally compare the | ||
* obtained/expected values in a GUI diff explorer. | ||
* | ||
* @param message the exception message. | ||
* @param obtained the obtained value from this comparison. | ||
* @param expected the expected value from this comparison. | ||
* @param location the source location where this exception was thrown. | ||
*/ | ||
class ComparisonFailException( | ||
val message: String, | ||
val obtained: Any, | ||
val expected: Any, | ||
val location: Location | ||
) extends ComparisonFailure(message, s"$expected", s"$obtained") | ||
with FailExceptionLike[ComparisonFailException] { | ||
override def getMessage: String = message | ||
def withMessage(newMessage: String): ComparisonFailException = | ||
new ComparisonFailException( | ||
newMessage, | ||
obtained, | ||
expected, | ||
location | ||
) | ||
} |
This file contains 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 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,19 @@ | ||
package munit | ||
|
||
/** | ||
* The base class for all MUnit FailExceptions. | ||
* | ||
* Implementation note: this class exists so that we could fix the issue | ||
* https://youtrack.jetbrains.com/issue/SCL-18255 In order to support the JUnit | ||
* comparison GUI in IntelliJ we need to extend org.junit.ComparisonFailure, | ||
* which is a class and not an interface. We can't make `munit.FailException` | ||
* extend `org.junit.ComparisonFailure` since not all "fail exceptions" are | ||
* "comparison failures". Instead, we introduced | ||
* `munit.ComparisionFailException`, which extends | ||
* `org.junit.ComparisonFailure` and this base trait. Internally, MUnit should | ||
* match against `FailExceptionLike[_]` instead of `munit.FailException` directly. | ||
*/ | ||
trait FailExceptionLike[T <: AssertionError] { self: AssertionError => | ||
def withMessage(message: String): T | ||
def location: Location | ||
} |
This file contains 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
12 changes: 12 additions & 0 deletions
12
munit/shared/src/main/scala/munit/internal/difflib/ComparisonFailExceptionHandler.scala
This file contains 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,12 @@ | ||
package munit.internal.difflib | ||
|
||
import munit.Location | ||
|
||
trait ComparisonFailExceptionHandler { | ||
def handle( | ||
message: String, | ||
obtained: String, | ||
expected: String, | ||
location: Location | ||
): Nothing | ||
} |
This file contains 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 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 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
Oops, something went wrong.