cider

lread 2025-12-03T18:46:15.414629Z

I really do love cider, so nice! I have a question about running a nested single test. ๐Ÿงต

bozhidar 2025-12-08T14:28:02.387889Z

At the ns level the test runner just runs everything loaded (think vars) with the relevant test metadata, so there's not much granularity to it.

bozhidar 2025-12-08T14:28:37.170479Z

You'll need to reload cleanly the ns to unload previously loaded tests that got conditionally loaded.

lread 2025-12-08T17:46:51.705929Z

Thanks for replying @bozhidar, much appreciated. I'm more wondering about how to run a single test that is not a top-level form.

lread 2025-12-03T18:57:56.061219Z

Given the following:

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

(deftest top-level-test
  (is (= 1 2)))

(when true
  (deftest nested-a-test
    (is (= 1 2)))

  (deftest nested-b-test
    (is (= 1 2)))

  (deftest nested-c-test
    (is (= 1 2))))
(with cider-test-fail-fast nil) Note: In my real-world scenario, my when true is replaced with a check for OS, I want to skip some tests if on Windows, for example. โœ… If I run cider-test-run-ns-test, it runs all tests as expected. โœ… If I cursor down the top-level-test and run cider-test-run-test it runs top-level-test as expected. โœ… If I cursor down to nested-a-test and run cider-test-run-test it runs nested-a-test as expected. โ“ But... if I cursor down to nested-b-test or nested-c-test and run cider-test-run-test it unexpectedly runs nested-a-test. Is this a known thing? Is it unexpected? Is it worth a git issue?

p4v4n 2025-12-14T16:17:38.054359Z

@lee The issue is with 'clojure-find-def' using 'beginning-of-defun' which jumps to top-level sexp always. Here's a temporary solution for your use-case:

(defun clojure-find-def-nested ()
  (save-excursion
    (while (and (not (looking-at clojure-def-type-and-name-regex))
                (not (clojure--looking-at-top-level-form)))
      (backward-up-list))
    (when (search-forward-regexp clojure-def-type-and-name-regex nil t)
      (list (match-string-no-properties 1)
            (match-string-no-properties 2)))))

(defun cider-test-run-nested-test ()
  (interactive)
  (cl-letf (((symbol-function 'clojure-find-def) 
             (symbol-function 'clojure-find-def-nested)))
    (cider-test-run-test)))

p4v4n 2025-12-14T16:20:29.231279Z

Making the same fix upstream to 'clojure-find-def' will require a bit of testing to both clojure-mode and cider to verify no existing desired behavior is broken. Will check it when I get more time.

lread 2025-12-14T17:43:31.426139Z

Thanks so much for looking into this @p4v4n!