I really do love cider, so nice! I have a question about running a nested single test. ๐งต
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.
You'll need to reload cleanly the ns to unload previously loaded tests that got conditionally loaded.
Thanks for replying @bozhidar, much appreciated. I'm more wondering about how to run a single test that is not a top-level form.
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?@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)))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.
Thanks so much for looking into this @p4v4n!