Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An extra form before the ns form, on the same line as the ns form, breaks test detection. #656

Closed
enaeher opened this issue Nov 5, 2022 · 2 comments · Fixed by #664
Closed
Assignees

Comments

@enaeher
Copy link

enaeher commented Nov 5, 2022

Expected behavior

cider-test-run-test runs a test when the point is inside that test.

Actual behavior

cider-test-run-test gives the error "No test at point."

Steps to reproduce the problem

In a Clojure file containing an ns form and one of the forms in cider-test-defining-forms (e.g.: deftest), add a form before the ns form, on the same line. Then navigate the point to one of the test forms and run cider-test-run-test.

Here is an example of a namespace which will exhibit the problem:

1 (ns some-test
    (:require [clojure.test :refer [deftest is]]))

(deftest unrecognized-test
  (is (= 1 1)))

Environment & Version information

CIDER version information

;; CIDER 1.5.0-snapshot (package: 20220731.522), nREPL 0.9.0
;; Clojure 1.11.1, Java 17.0.3

Lein / Clojure CLI version

Clojure CLI version 1.11.1.1165

Emacs version

GNU Emacs 28.2 (build 1, aarch64-apple-darwin21.6.0) of 2022-09-13

Operating system

MacOS Monterey 12.5.1

JDK distribution

openjdk version "17.0.3" 2022-04-19 LTS
OpenJDK Runtime Environment Corretto-17.0.3.6.1 (build 17.0.3+6-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.3.6.1 (build 17.0.3+6-LTS, mixed mode, sharing)

@vemv vemv self-assigned this Jul 27, 2023
@vemv vemv pinned this issue Aug 23, 2023
@vemv
Copy link
Member

vemv commented Aug 23, 2023

This boils down to

1 (ns some-test
    (:require [clojure.test :refer [deftest is]]))

being non-parseable by clojure-mode's (clojure-find-ns).

Funnily enough, the following does get detected properly:

1
(ns some-test
    (:require [clojure.test :refer [deftest is]]))

I'll transfer this issue to clojure-mode and see if we can get it fixed.

@vemv vemv transferred this issue from clojure-emacs/cider Aug 23, 2023
@vemv
Copy link
Member

vemv commented Aug 24, 2023

I gave this a fair shot, but I don't think there's a reasonable fix

Our clojure-namespace-regexp is defined as follows:

https://github.com/clojure-emacs/clojure-mode/blob/192a46653fdc27601905f97a044d47764fee1f4e/clojure-mode.el#L2112C1-L2113

It only matches (ns if that's how a given line begins (line-start). I could remove that, but then other edge cases would begin failing.

It's simpler to recommend users to avoid writing incorrect / dubious code. Formatters and linters can help with that - it can be a good a idea to run them before running tests.

Cheers - V

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 a pull request may close this issue.

2 participants