Skip to content

Improve font-lock test failure messages with a :to-have-face matcher#146

Merged
bbatsov merged 2 commits into
mainfrom
test-buttercup-idioms
Jul 8, 2026
Merged

Improve font-lock test failure messages with a :to-have-face matcher#146
bbatsov merged 2 commits into
mainfrom
test-buttercup-idioms

Conversation

@bbatsov

@bbatsov bbatsov commented Jul 8, 2026

Copy link
Copy Markdown
Member

The font-lock helpers assert faces with a bare (expect actual :to-equal expected) inside clojure-ts--check-faces / expect-face-at, so a failure just says "Expected font-lock-string-face to equal font-lock-keyword-face" - with no hint of which token was wrong.

This adds a :to-have-face matcher that takes a substring (searched from point, as the helpers already did), a position, or a (START END) range, and reports things like:

Expected "def" to have face font-lock-string-face, but it had font-lock-keyword-face

expect-face-at and clojure-ts--check-faces (so when-fontifying-it) route through it, so the whole font-lock suite gets the better messages with no call-site changes.

Second commit swaps the three cl-letf project stubs for spy-on (auto-restores per spec). One of them was a bare expect directly under describe, so it never actually ran as a spec - it's now wrapped in an it.

Test-only; 252 specs, unchanged behavior.

bbatsov added 2 commits July 8, 2026 11:29
The face helpers asserted with a bare (expect ACTUAL :to-equal EXPECTED),
so a failure read "Expected face-a to equal face-b" with no hint of which
token was wrong. Add a :to-have-face matcher that resolves a substring
(searched from point), a position, or a (START END) range and reports
e.g. "Expected \"def\" to have face font-lock-string-face, but it had
font-lock-keyword-face". Route expect-face-at and clojure-ts--check-faces
(hence when-fontifying-it) through it, so the whole font-lock suite gains
the better messages.
Replace (cl-letf ((symbol-function ...))) with buttercup's spy-on, which
auto-restores after each spec. The clojure-ts-project-relative-path check
was a bare expect directly under describe (so it never ran as a spec);
wrap it in an it, which both fixes that and lets it use spy-on.
@bbatsov
bbatsov merged commit 2f2da7e into main Jul 8, 2026
10 checks passed
@bbatsov
bbatsov deleted the test-buttercup-idioms branch July 8, 2026 08:34
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.

1 participant