Skip to content

More test leaning: a temp-file macro and a match matcher#2085

Merged
bbatsov merged 1 commit into
masterfrom
test/temp-file-macro-and-match-matcher
Jul 8, 2026
Merged

More test leaning: a temp-file macro and a match matcher#2085
bbatsov merged 1 commit into
masterfrom
test/temp-file-macro-and-match-matcher

Conversation

@bbatsov

@bbatsov bbatsov commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Continues the test-readability pass (items #1 and #2 from the audit).

  • projectile-test-with-temp-files - binds vars to fresh temp files or :dir temp directories and removes them on exit (normally or via error), replacing the make-temp-file + unwind-protect + delete-file dance. Applied where it's a clean win (file-only session specs). Most temp-file specs also open buffers and keep their own unwind-protect, so the macro only marginally helps there - I left those rather than risk their cleanup semantics.

  • :to-be-a-match-with - a custom matcher checking a projectile-replace--match's fields against a plist in a single expect, naming every field that didn't match; plus projectile-test-find-match. Collapses the multi-expect match-assertion blocks, e.g.

    ;; before: find + 5 separate expects
    (let ((mb (cl-find-if ... projectile-replace--matches)))
      (expect mb :not :to-be nil)
      (expect (projectile-replace--match-line mb) :to-equal 1)
      ... )
    ;; after
    (expect (projectile-test-find-match projectile-replace--matches "mb.txt")
            :to-be-a-match-with '(:line 1 :column 5 :string "foo" :context "café foo bar"))

889 specs green, clean --warnings-as-errors, relint clean.

On the other two audit items: #4 (:to-be-truthy sweep) turns out not to be a safe blanket change - many :to-be t assertions are genuine exact-t checks (e.g. a file-kind marker that is the symbol t), and swapping them to :to-be-truthy would weaken them; I'd only do it case by case. #3 (cl-letf -> spy-on) is a large, delicate churn (relation-test alone has 45) for a readability-only gain, and some cl-letf overrides can't be expressed as spies; I'd do it selectively as its own PR rather than a blanket rewrite. Happy to proceed on either if you'd like.

- projectile-test-with-temp-files: bind vars to fresh temp files (or
  directories) and clean them up on exit, replacing the manual
  make-temp-file + unwind-protect + delete-file dance.  Applied where
  it's a clean win (the file-only session specs); most temp-file specs
  also manage buffers and keep their own unwind-protect.
- :to-be-a-match-with: a custom matcher that checks a
  projectile-replace--match's fields against a plist in one expect
  (naming every field that didn't match), plus projectile-test-find-match.
  Collapses the multi-expect match-assertion blocks in the search specs.
@bbatsov bbatsov merged commit e4d212b into master Jul 8, 2026
10 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.

1 participant