I have been restarting my project today and noticed something weird. So if I eval my test file with cider-load-buffer (e.g. C-c C-k), all seems well, and then try to run a test under point cider-test-run-test or C-c C-t C-t I will get a "No test found at point". If I re-eval the buffer a second time. Then the test is recognized and starts running. Feels like a regression but I'm not sure.
I'm using CIDER 1.15.1 (Cogne)
I remember fixing some nREPL-related regressions in the past. Please update to 1.16 first just to be sure it's not it.
Ok I updated to CIDER 1.16.0 (Kherson) but same behavior.
It doesn't seem to pick the test up on the first eval 🤷
It's a plain simple deftest
If this is broken for someone else too then I can do a repro and an issue. Just wondering if it could be something in my setup.
What's the name of your test namespace?
rems.api.test-users
(deftest test-users-api ...)
And it says No test namespace: rems.api.test-users-test in the minibuffer, I assume?
No it says No test found at point
Right. I've just run into other confusing behavior with C-c C-t C-n
Seems like in my case C-c C-t C-n works as expected.
The issue that you describe does not surface in my projects. I would greatly appreciate a small reproducer.
I'll see what happens in a trivial project. This is not a small project, although it's rather simple in the way of tooling.
Thanks for trying!
No problem
Are you connected to a single REPL or perhaps multiple?
Just one
Yeah, can't immediately replicate with lein new foo and a test.
Ok you could try this with the actual project:
• Assuming you have leiningen.
• Clone the repo from https://github.com/CSCfi/rems/
• In Emacs, open file test/clj/rems/api/test_users.clj
• (setq cider-lein-parameters "with-profile +dev repl :headless")
• cider-jack-in
• Go to first deftest e.g. test-users-api
• C-c C-k to eval buffer
• C-c C-t C-t to run test
• Boom ... No test found at point
At least I can reproduce with the master there.
(The test should fail as the database is not running, that's OK, the problem is just that CIDER doesn't pick up the test to run without second eval)
A good chunk of times this happens because the test/ dir is not in your classpath because one didn't activate the :test profile (or any similar ones you may be using)
In this case I get the same with with-profile +test repl :headless too. There are indeed times where our tests don't work with one or the other and it makes interactive development more difficult.
Got it 👍 A good way to debug this is going step by step "simulating" what the relevant Elisp defun would do:
(defun cider-test-run-test ()
"Run the test at point.
The test ns/var exist as text properties on report items and on highlighted
failed/erred test definitions.
When not found, a test definition at point
or in a corresponding test namespace is searched."
(interactive)
(let* ((found (cider--extract-test-var-at-point))
(found-ns (car found))
(found-var (cadr found)))
(if (not found-var)
(message "No test found at point")
(cider-test-update-last-test found-ns (list found-var))
(cider-test-execute found-ns (list found-var)))))
e.g. run M-: (cider--extract-test-var-at-point) - what does it say?Ok now I think I understand. The project is altogether so big that it takes for a while for the tests to be found. If I wait for a while it does work.
Alright It also depends on how the tests are loaded, personally I trust in tools.namespace (and/or cider-refresh), that is a sync operation, so I don't have to wait an indefinite time
Being more precise, the tests don't have to be found, they have to be require d - if nothing requires them, they'll never get loaded
I agree, looking at the internals of CIDER and calling the functions to triage a bit better is what I should do.
In this case I'm just evaling the very first file after the REPL opens and trying to run its first test.
I thought that eval buffer returning would mean the namespace (and tests) are loaded.
Thanks for the help!
In general yes, loading the buffer is equivalent. But then "it takes for a while for the tests to be found" makes less sense