Skip to content

Conversation

zainab-ali
Copy link
Contributor

@zainab-ali zainab-ali commented Jun 27, 2025

Some users would rather skip the extra troubleshooting step of adding clue to failing expectations. This PR adds two scalafix rules:

  • AddClueToExpect wraps the contents of an expect call in clue. It is written to be idempotent, and attempts to only add clue where useful.
  • RenameExpectToExpectSame renames expect(a == b) to expect.same(a, b).

It's up to users whether they'd like to do this or not (peppering code with clue is their preference), so these rules should be applied manually.

Since testing the clue rule required version 0.9.0, I split out the rule tests into different SBT modules, similarly to what's done in cats-effect.

We can add the following docs to the migration guide. This is linked on the website, so should be discoverable:

Example migration guide

The expect function now uses clues to print useful error messages. You can read more about clue in the expectations docs. If you'd prefer to skip the extra troubleshooting step of adding clue to failing expectations, you can add clue to all existing expectations using scalafix.

sbt scalafixAll github:typelevel/weaver-test/AddClueToExpect?sha=main

The expect.same and expect.eql functions don't use clues. If you wish, you can replace expectations of the form expect(a == b) with expect.same(a, b) using scalafix. Do this before adding clues to the expectations.

sbt scalafixAll github:typelevel/weaver-test/RenameExpectToExpectSame?sha=main

@Baccata
Copy link
Collaborator

Baccata commented Jun 28, 2025

Great stuff !

@zainab-ali zainab-ali merged commit 2bc0209 into typelevel:main Jul 1, 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