emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/cider 52243cf2d7: Refine `cider-test-run-test` (#3481)


From: ELPA Syncer
Subject: [nongnu] elpa/cider 52243cf2d7: Refine `cider-test-run-test` (#3481)
Date: Tue, 26 Sep 2023 10:00:24 -0400 (EDT)

branch: elpa/cider
commit 52243cf2d7af8a89e4d37430cef1755fcb0f8d6c
Author: vemv <vemv@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Refine `cider-test-run-test` (#3481)
    
    Fixes #2958
    Fixes #3279
    
    Co-authored-by: tvirolai <tvirolai@users.noreply.github.com>
---
 CHANGELOG.md                                      |  2 +
 cider-test.el                                     | 80 +++++++++++++++--------
 doc/modules/ROOT/pages/testing/running_tests.adoc | 10 +--
 doc/modules/ROOT/pages/usage/cider_mode.adoc      |  2 +-
 4 files changed, 57 insertions(+), 37 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9d78490f0..6b7b74dde0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,8 @@
 - [#3354](https://github.com/clojure-emacs/cider/issues/3354): Add new 
customization variable `cider-reuse-dead-repls` to control how dead REPL 
buffers are reused on new connections.
 - [#3364](https://github.com/clojure-emacs/cider/pull/3364): Update 
enrich-classpath, adding Clojure CLI compatibility, and reworking its 
integration into CIDER.
   * It will be progressively refined and documented, please consider this 
alpha software.
+- [#2958](https://github.com/clojure-emacs/cider/issues/2958), 
[#3279](https://github.com/clojure-emacs/cider/issues/3279): 
`cider-test-run-test`: support arbitrary deftest-like forms, defns with :test 
metadata, and search for a `-test` counterpart for a given defn (following 
`cider-test-infer-test-ns` logic).
+  - This also makes obsolete the `cider-test-defining-forms` customization 
variable.
 
 ### Bugs fixed
 
diff --git a/cider-test.el b/cider-test.el
index 8691196ffc..1cf0887519 100644
--- a/cider-test.el
+++ b/cider-test.el
@@ -60,13 +60,7 @@
   :type 'boolean
   :package-version '(cider . "0.9.0"))
 
-(defcustom cider-test-defining-forms '("deftest" "defspec")
-  "Forms that define individual tests.
-CIDER considers the \"top-level\" form around point to define a test if
-the form starts with one of these forms.
-Add to this list to have CIDER recognize additional test defining macros."
-  :type '(repeat string)
-  :package-version '(cider . "0.15.0"))
+(make-obsolete 'cider-test-defining-forms nil "1.8.0")
 
 (defvar cider-test-last-summary nil
   "The summary of the last run test.")
@@ -838,31 +832,61 @@ See `cider-test-rerun-test'."
   (setq cider-test-last-test-ns ns
         cider-test-last-test-var var))
 
+(defun cider--test-var-p (ns var)
+  "Determines if the VAR in NS is a test."
+  (if (cider-nrepl-op-supported-p "cider/get-state")
+      (cider-resolve--get-in ns "interns" var "test")
+    (equal "true"
+           (nrepl-dict-get (cider-sync-tooling-eval
+                            (format "(clojure.core/-> %s var clojure.core/meta 
(clojure.core/contains? :test))"
+                                    var)
+                            ns)
+                           "value"))))
+
+(defun cider--extract-test-var-at-point ()
+  "Find ns and var for 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."
+  (let* ((ns-from-text-property (get-text-property (point) 'ns))
+         (var-from-text-property (when ns-from-text-property
+                                   ;; we're in a `cider-test-report-mode' 
buffer
+                                   ;; or on a highlighted failed/erred test 
definition
+                                   (get-text-property (point) 'var))))
+    (or (when (and var-from-text-property
+                   ;; Slightly redundant check. However querying 
`cider-resolve--get-in` is cheap:
+                   (cider--test-var-p ns-from-text-property 
var-from-text-property))
+          (list ns-from-text-property var-from-text-property))
+        (when-let* ((n (cider-get-ns-name))
+                    (v (cadr (clojure-find-def))))
+          (or (when (cider--test-var-p n v)
+                (list n v))
+              (let ((derived-ns (funcall cider-test-infer-test-ns n))
+                    (derived-var (concat v "-test")))
+                ;; deftest foo-test:
+                (or (when (cider--test-var-p derived-ns derived-var)
+                      (list derived-ns derived-var))
+                    ;; deftest foo (less usual, but quite frequent):
+                    (when (cider--test-var-p derived-ns v)
+                      (list derived-ns v)))))))))
+
 (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
-is searched."
+failed/erred test definitions.
+
+When not found, a test definition at point
+or in a corresponding test namespace is searched."
   (interactive)
-  (let ((ns  (get-text-property (point) 'ns))
-        (var (get-text-property (point) 'var)))
-    (if (and ns var)
-        ;; we're in a `cider-test-report-mode' buffer
-        ;; or on a highlighted failed/erred test definition
-        (progn
-          (cider-test-update-last-test ns var)
-          (cider-test-execute ns (list var)))
-      ;; we're in a `clojure-mode' buffer
-      (or (when-let* ((ns  (cider-get-ns-name))
-                      (def (clojure-find-def)) ; it's a list of the form 
(deftest something)
-                      (deftype (car def))
-                      (var (cadr def)))
-            (if (and ns (member deftype cider-test-defining-forms))
-                (progn
-                  (cider-test-update-last-test ns (list var))
-                  (cider-test-execute ns (list var)))
-              (message "No test at point")))
-          (message "No test at point")))))
+  (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)))))
 
 (defun cider-test-rerun-test ()
   "Re-run the test that was previously ran."
diff --git a/doc/modules/ROOT/pages/testing/running_tests.adoc 
b/doc/modules/ROOT/pages/testing/running_tests.adoc
index da7c225f18..13852bb519 100644
--- a/doc/modules/ROOT/pages/testing/running_tests.adoc
+++ b/doc/modules/ROOT/pages/testing/running_tests.adoc
@@ -85,7 +85,8 @@ command with a prefix (kbd:[C-u C-c C-t C-s]) you can suppress
 the namespace inference logic as for kbd:[C-u C-c C-t C-n]
 
 Finally, you can execute the specific test at the point using
-kbd:[C-c C-t t] or kbd:[C-c C-t C-t].
+kbd:[C-c C-t t] or kbd:[C-c C-t C-t]. It will also work for implementation 
functions,
+by searching for a matching test namespace with a matching deftest name. 
 
 == Configuration
 
@@ -141,13 +142,6 @@ selectors so that tests tagged as "integration" or 
"flakey" don't run.
 
 TIP: You'll generally want to place default selectors in 
xref:config/project_config.adoc[your project configuration], as opposed to your 
global configuration.
 
-=== Macros Used to Define Tests
-
-If your individual tests are not defined by `deftest` or `defspec`, CIDER will
-not recognize them when searching for a test at point in `cider-test-run-test`.
-You can customize the variable `cider-test-defining-forms` to add additional
-forms for CIDER to recognize as individual test definitions.
-
 === Display Test Report on Success
 
 By default the test report is displayed only when there are test failures or
diff --git a/doc/modules/ROOT/pages/usage/cider_mode.adoc 
b/doc/modules/ROOT/pages/usage/cider_mode.adoc
index b109fa42a1..38d5803571 100644
--- a/doc/modules/ROOT/pages/usage/cider_mode.adoc
+++ b/doc/modules/ROOT/pages/usage/cider_mode.adoc
@@ -223,7 +223,7 @@ kbd:[C-c C-d C-e]
 | `cider-test-run-test`
 | kbd:[C-c C-t t] +
 kbd:[C-c C-t C-t]
-| Run test at point.
+| Run test at point. If the form under the point is a function, try to search 
and run a corresponding test.
 
 | `cider-test-rerun-test`
 | kbd:[C-c C-t a] +



reply via email to

[Prev in Thread] Current Thread [Next in Thread]