-
Notifications
You must be signed in to change notification settings - Fork 91
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
Extract diff module #756
Merged
Merged
Extract diff module #756
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f0a004c
Extract munit diff module
majk-p a11ef11
DiffsAssertion -> Diffs
majk-p c8feb48
fix cross build
majk-p 19ca9f4
scalafix
majk-p cbbbd09
refactor: Rename to munit-diff instead of scala-diff
tgodzik c5ce308
chore: Fix mdoc compilation
tgodzik 25ce89f
chore: Ignore mima filters and disable for now for munit-diff
tgodzik 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package munit | ||
|
||
import munit.internal.console.{Lines, Printers, StackTraces} | ||
import munit.internal.difflib.ComparisonFailExceptionHandler | ||
import munit.internal.difflib.Diffs | ||
import munit.internal.console.{Lines, StackTraces} | ||
import munit.internal.console.Printers | ||
import munit.diff.Printer | ||
import munit.Clue | ||
import munit.Clues | ||
import munit.diff.EmptyPrinter | ||
|
||
import scala.reflect.ClassTag | ||
import scala.util.control.NonFatal | ||
import scala.collection.mutable | ||
import munit.internal.console.AnsiColors | ||
import munit.diff.console.AnsiColors | ||
import org.junit.AssumptionViolatedException | ||
import munit.internal.MacroCompat | ||
|
||
|
@@ -54,7 +57,7 @@ trait Assertions extends MacroCompat.CompileErrorMacro { | |
Diffs.assertNoDiff( | ||
obtained, | ||
expected, | ||
ComparisonFailExceptionHandler.fromAssertions(this, Clues.empty), | ||
exceptionHandlerFromAssertions(this, Clues.empty), | ||
munitPrint(clue), | ||
printObtainedAsStripMargin = true | ||
) | ||
|
@@ -291,6 +294,21 @@ trait Assertions extends MacroCompat.CompileErrorMacro { | |
) | ||
} | ||
|
||
private def exceptionHandlerFromAssertions( | ||
assertions: Assertions, | ||
clues: => Clues | ||
): ComparisonFailExceptionHandler = | ||
new ComparisonFailExceptionHandler { | ||
def handle( | ||
message: String, | ||
obtained: String, | ||
expected: String, | ||
loc: Location | ||
): Nothing = { | ||
assertions.failComparison(message, obtained, expected, clues)(loc) | ||
} | ||
} | ||
Comment on lines
+295
to
+308
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. I decided to extract this from |
||
|
||
private val munitCapturedClues: mutable.ListBuffer[Clue[_]] = | ||
mutable.ListBuffer.empty | ||
def munitCaptureClues[T](thunk: => T): (T, Clues) = | ||
|
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
10 changes: 10 additions & 0 deletions
10
munit/shared/src/main/scala/munit/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,10 @@ | ||
package munit | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package munit | ||
|
||
import munit.diff.Diff | ||
|
||
object Diffs { | ||
|
||
def assertNoDiff( | ||
obtained: String, | ||
expected: String, | ||
handler: ComparisonFailExceptionHandler, | ||
title: String, | ||
printObtainedAsStripMargin: Boolean | ||
)(implicit loc: Location): Boolean = { | ||
if (obtained.isEmpty && !expected.isEmpty) { | ||
val msg = | ||
s"""|Obtained empty output! | ||
|=> Expected: | ||
|$expected""".stripMargin | ||
handler.handle(msg, obtained, expected, loc) | ||
} | ||
val diff = new Diff(obtained, expected) | ||
if (diff.isEmpty) true | ||
else { | ||
handler.handle( | ||
diff.createReport(title, printObtainedAsStripMargin), | ||
obtained, | ||
expected, | ||
loc | ||
) | ||
} | ||
} | ||
|
||
} |
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
30 changes: 0 additions & 30 deletions
30
munit/shared/src/main/scala/munit/internal/difflib/ComparisonFailExceptionHandler.scala
This file was deleted.
Oops, something went wrong.
80 changes: 0 additions & 80 deletions
80
munit/shared/src/main/scala/munit/internal/difflib/Diffs.scala
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../scala/munit/internal/difflib/Chunk.scala → ...red/src/main/scala/munit/diff/Chunk.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package munit.internal.difflib | ||
package munit.diff | ||
|
||
import java.util | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
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.
Is this change correct?
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.
That's right, missed it during cleanup