Skip to content

Fix "Run current test" matching tests with similar names#3140

Merged
PEZ merged 2 commits intoBetterThanTomorrow:devfrom
kovan:fix/test-name-exact-match
Mar 21, 2026
Merged

Fix "Run current test" matching tests with similar names#3140
PEZ merged 2 commits intoBetterThanTomorrow:devfrom
kovan:fix/test-name-exact-match

Conversation

@kovan
Copy link
Copy Markdown
Contributor

@kovan kovan commented Mar 14, 2026

What has changed?

"Run current test" was running all tests whose names contained the target name as a substring. For example, running a-test would also run b-a-test and a-test-b.

The search regex used \b (word boundaries) to match test names, but hyphens are word boundary characters in regex. So \ba-test\b matches a-test inside b-a-test because - is a boundary.

Replaced \b...\b with /...$ — anchoring on the namespace separator (/) and end-of-string ($). This works because cider-nrepl's orchard uses re-find against namespace-qualified var names like my.ns/a-test. The namespace is already filtered by ns-query, so we only need to match the name portion exactly.

Previous attempts to use ^...$ failed because escapeStringRegexp escapes ^ and $. The fix puts the anchors outside the escape call.

Extracted the pattern into a testable testNameSearchPattern() function with 5 unit tests.

Fixes #2168

My Calva PR Checklist

I have:

  • Read How to Contribute.
  • Directed this pull request at the dev branch. (Or have specific reasons to target some other branch.)
  • Made sure I have changed the PR base branch, so that it is not published. (Sorry for the nagging.)
  • Made sure there is an issue registered with a clear problem statement that this PR addresses, (created the issue if it was not present).
    • Updated the [Unreleased] entry in CHANGELOG.md, linking the issue(s) that the PR is addressing.
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and either tested it there if so, or mentioned it in the PR.
  • [ ] Added to or updated docs in this branch, if appropriate (no docs changes needed)
  • Tests
    • Tested the particular change
    • Figured if the change might have some side effects and tested those as well.
  • Formatted all JavaScript and TypeScript code that was changed. (use the prettier extension or run npm run prettier-format)
  • Confirmed that there are no linter warnings or errors (use the eslint extension, run npm run eslint before creating your PR, or run npm run eslint-watch to eslint as you go).

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 14, 2026

Deploy Preview for calva-docs failed.

Name Link
🔨 Latest commit fdedf4d
🔍 Latest deploy log https://app.netlify.com/projects/calva-docs/deploys/69be92b8a0ce0d00083ac701

The search regex used word boundaries (\b) which don't work correctly
with hyphenated Clojure test names — "a-test" would also match
"b-a-test" and "a-test-b" because hyphens are word boundaries.

Replace with a pattern that anchors on the namespace separator (/)
and end-of-string ($), so only the exact test name matches against
the namespace-qualified var name returned by orchard.

Extract the pattern into a testable testNameSearchPattern() function
and add unit tests.

Fixes BetterThanTomorrow#2168
@kovan kovan force-pushed the fix/test-name-exact-match branch from d72caed to 70dd320 Compare March 14, 2026 20:11
@kovan kovan changed the base branch from published to dev March 14, 2026 20:12
@PEZ PEZ merged commit 80d769d into BetterThanTomorrow:dev Mar 21, 2026
1 of 5 checks passed
@PEZ
Copy link
Copy Markdown
Collaborator

PEZ commented Mar 21, 2026

Thanks again! ❤️

jramosg pushed a commit to jramosg/calva that referenced this pull request Mar 28, 2026
…xact-match

Fix "Run current test" matching tests with similar names

* Fixes BetterThanTomorrow#2168
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.

Running a single test runs all tests containing the single test's name

2 participants