Skip to content

Conversation

@zainab-ali
Copy link
Contributor

The current implementation of Comparison for expect.same and expect.eql uses a default Show.fromToString instance.

This prints the obtained or expected values on a single line. The Myers diff algorithm works on multi-line strings, not one-line strings, so the diff is hard to read.

This PR adapts munit's multi-line string printing logic to create a better default show instance.

Before

Running the test in:

scala-cli https://gist.github.com/zainab-ali/97456a9054a7eb35a8dd6499a81d6c19
image

After

Screenshot 2025-11-06 at 15 41 49

@@ -0,0 +1,6 @@
package weaver

object ScalaCompat {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are only used in tests. We could move them to the test folder and define a test -> test relationship in SBT, but this would be best left to a different PR.

private val comma: String = ","
private val indentStep = 1

private[weaver] def show[A]: Show[A] = (a: A) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code uses explicit recursion and string builders, so is non-idiomatic for the weaver codebase.

However, I don't think we'll need to modify it much going forwards. If users have edge cases, they can support them with their own Show instances.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm perfectly happy with String builders to be honest.

"""- (same with default show) 0ms
Values not equal: (src/main/DogFoodTests.scala:5)
=> Diff (- obtained, + expected)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scala 2.12 doesn't support field names, hence this test is different for different Scala versions.

private[weaver] def productElementNames(p: Product): Iterator[String] =
p.productElementNames
private[weaver] def collectionClassName(i: Iterable[_]): String = i
.asInstanceOf[{ def collectionClassName: String }].collectionClassName
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :D

Copy link
Collaborator

@Baccata Baccata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic !

@zainab-ali zainab-ali merged commit eccc6e7 into typelevel:main Nov 7, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants