Skip to content

Conversation

zainab-ali
Copy link
Contributor

@zainab-ali zainab-ali commented Jul 1, 2025

Problem

As described in #163 , expect.all currently displays a general assertion failed message when any assertion fails:

assertion failed (Meta.scala:18)

  Use the `clue` function to troubleshoot

It doesn't indicate which of the assertions in expect.all failed.

Improvement

This PR adds the source code and index of the assertion into the failure message.

In addition, the collection of clues is assertion-specific.

Example failure message

The failing test:

    pureTest("(all)") {
      val x = 1
      val y = 2
      val z = 3
      expect.all(x == x, clue(x) == clue(y), y == y, clue(y) == clue(z), z == z)
    }

Has the message:

(all) 0ms
[0] assertion 2 of 5 failed: clue(x) == clue(y) (modules/framework-cats/shared/src/test/scala/Meta.scala:102)
[0] 
[0] Clues {
[0]   x: Int = 1
[0]   y: Int = 2
[0] }

[1] assertion 4 of 5 failed: clue(y) == clue(z) (modules/framework-cats/shared/src/test/scala/Meta.scala:102)
[1] 
[1] Clues {
[1]   y: Int = 2
[1]   z: Int = 3
[1] }

Binary compatibility

The Clues.toExpectations signature has changed from accepting a Boolean* to a Boolean. This is source compatible, since no one should be calling it directly. It's not binary compatible, as libraries with expect compiled against 0.9.1 will refer to the old Clues.toExpectations signature.

@zainab-ali zainab-ali marked this pull request as ready for review July 2, 2025 13:26
Comment on lines 378 to 391
|- (all) 0ms
| [0] assertion 2 of 5 failed: clue(x) == clue(y) (modules/framework-cats/shared/src/test/scala/Meta.scala:102)
| [0]
| [0] Clues {
| [0] x: Int = 1
| [0] y: Int = 2
| [0] }
|
| [1] assertion 4 of 5 failed: clue(y) == clue(z) (modules/framework-cats/shared/src/test/scala/Meta.scala:102)
| [1]
| [1] Clues {
| [1] y: Int = 2
| [1] z: Int = 3
| [1] }
Copy link

Choose a reason for hiding this comment

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

I wonder how useful the 2 out of 5 and 4 out of 5 are. Should we have an extra log line like:

assertions:
1: x == x
2: clue(x) == clue(y)
3: y == y
4: clue(y) == clue(z)
5: z == z

Or maybe get rid of the numbering altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting rid of the numbering is easiest to maintain. I added the numbering at first, thinking the source code would be challenging.

We can work on formatting source code in error messages in future PRs.

build.sbt Outdated
@@ -12,7 +12,7 @@ import laika.config.LinkValidation
import org.typelevel.sbt.site.TypelevelSiteSettings
import sbt.librarymanagement.Configurations.ScalaDocTool
// https://typelevel.org/sbt-typelevel/faq.html#what-is-a-base-version-anyway
ThisBuild / tlBaseVersion := "0.9" // your current series x.y
ThisBuild / tlBaseVersion := "0.10" // your current series x.y
Copy link
Collaborator

Choose a reason for hiding this comment

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

why the bump ?

Copy link
Contributor Author

@zainab-ali zainab-ali Jul 3, 2025

Choose a reason for hiding this comment

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

The Clues.toExpectations signature has changed from accepting a Boolean* to a Boolean. This is source compatible, since no one should be calling it directly. It's not binary compatible, as libraries with expect compiled against 0.9.1 will refer to the old Clues.toExpectations signature.

Since we're breaking binary compatibility and using early semver, we need to bump the minor version.

An alternative approach (just to keep the same minor version) is to keep the Boolean* signature as is, and only pass in one argument. We could move it to Boolean when we next need to bump the minor version.

Copy link
Contributor Author

@zainab-ali zainab-ali Jul 3, 2025

Choose a reason for hiding this comment

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

I decided on keeping Boolean* for the moment to preserve compatibility.

@zainab-ali zainab-ali merged commit 5f66c7b into typelevel:main Jul 3, 2025
13 checks passed
@zainab-ali zainab-ali deleted the expect-all-clue branch July 3, 2025 20:26
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.

3 participants