cider

Macroz 2024-10-28T13:32:38.779969Z

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.

Macroz 2024-10-28T13:33:24.624979Z

I'm using CIDER 1.15.1 (Cogne)

oyakushev 2024-10-28T13:34:36.161479Z

I remember fixing some nREPL-related regressions in the past. Please update to 1.16 first just to be sure it's not it.

Macroz 2024-10-28T13:37:07.899069Z

Ok I updated to CIDER 1.16.0 (Kherson) but same behavior.

Macroz 2024-10-28T13:37:34.587559Z

It doesn't seem to pick the test up on the first eval 🤷

Macroz 2024-10-28T13:37:53.167929Z

It's a plain simple deftest

Macroz 2024-10-28T13:38:23.189019Z

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.

oyakushev 2024-10-28T13:39:17.887139Z

What's the name of your test namespace?

Macroz 2024-10-28T13:39:36.578889Z

rems.api.test-users

Macroz 2024-10-28T13:39:48.563359Z

(deftest test-users-api ...)

oyakushev 2024-10-28T13:40:09.127499Z

And it says No test namespace: rems.api.test-users-test in the minibuffer, I assume?

Macroz 2024-10-28T13:40:26.575179Z

No it says No test found at point

oyakushev 2024-10-28T13:41:02.177549Z

Right. I've just run into other confusing behavior with C-c C-t C-n

Macroz 2024-10-28T13:42:12.236699Z

Seems like in my case C-c C-t C-n works as expected.

oyakushev 2024-10-28T13:42:53.247909Z

The issue that you describe does not surface in my projects. I would greatly appreciate a small reproducer.

Macroz 2024-10-28T13:43:37.933169Z

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.

👍 1
Macroz 2024-10-28T13:43:52.262309Z

Thanks for trying!

oyakushev 2024-10-28T13:44:04.912489Z

No problem

oyakushev 2024-10-28T13:44:21.577699Z

Are you connected to a single REPL or perhaps multiple?

Macroz 2024-10-28T13:44:27.937559Z

Just one

✅ 1
Macroz 2024-10-28T13:45:12.108359Z

Yeah, can't immediately replicate with lein new foo and a test.

Macroz 2024-10-28T13:57:06.474709Z

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-apiC-c C-k to eval buffer • C-c C-t C-t to run test • Boom ... No test found at point

Macroz 2024-10-28T13:57:53.606909Z

At least I can reproduce with the master there.

Macroz 2024-10-28T13:59:05.704849Z

(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)

vemv 2024-10-28T14:11:09.740649Z

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)

Macroz 2024-10-28T14:12:31.549849Z

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.

vemv 2024-10-28T14:14:19.756659Z

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?

Macroz 2024-10-28T14:19:44.094949Z

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.

vemv 2024-10-28T14:21:16.870179Z

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

vemv 2024-10-28T14:22:08.400099Z

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

Macroz 2024-10-28T14:22:23.580779Z

I agree, looking at the internals of CIDER and calling the functions to triage a bit better is what I should do.

🙌 1
Macroz 2024-10-28T14:22:56.915859Z

In this case I'm just evaling the very first file after the REPL opens and trying to run its first test.

Macroz 2024-10-28T14:23:38.921429Z

I thought that eval buffer returning would mean the namespace (and tests) are loaded.

Macroz 2024-10-28T14:23:45.890809Z

Thanks for the help!

vemv 2024-10-28T14:52:51.582779Z

In general yes, loading the buffer is equivalent. But then "it takes for a while for the tests to be found" makes less sense