Skip to content

Commit 9228edd

Browse files
committed
Extend the test filtering functionality
Now we support multiple include and exclude filter selectors, similar to what most build tools and the test-runner do.
1 parent fdb0b91 commit 9228edd

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Add support for shadow-cljs to `cider-jack-in`.
2121
* [#2244](https://github.com/clojure-emacs/cider/issues/2244): Display the REPL type in the modeline.
2222
* [#2238](https://github.com/clojure-emacs/cider/pull/2238): Allow specifying predicates for entries in `cider-jack-in-lein-plugins` and `cider-jack-in-nrepl-middlewares`.
23-
* Add support for test selectors. If test all or all loaded is called with a prefix ask for a selector in the minibuffer and only run those tests in the project which are marked with the selector. Add variation of test namespace which asks for a selector the same way and only runs a subset of the namespace tests.
23+
* Add support for test selectors. If test all or all loaded is called with a prefix ask for filter test selectors in the minibuffer and only run those tests in the project which match the filters. Add variation of test namespace which asks for filter selectors the same way and only runs a subset of the namespace tests.
2424

2525
### Bugs Fixed
2626

cider-repl.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,9 +1427,9 @@ constructs."
14271427
(cider-repl-add-shortcut "test-ns" #'cider-test-run-ns-tests)
14281428
(cider-repl-add-shortcut "test-all" #'cider-test-run-loaded-tests)
14291429
(cider-repl-add-shortcut "test-project" #'cider-test-run-project-tests)
1430-
(cider-repl-add-shortcut "test-ns-with-selector" #'cider-test-run-ns-tests-with-selector)
1431-
(cider-repl-add-shortcut "test-all-with-selector" (lambda () (interactive) (cider-test-run-loaded-tests 'prompt-for-selector)))
1432-
(cider-repl-add-shortcut "test-project-with-selector" (lambda () (interactive) (cider-test-run-project-tests 'prompt-for-selector)))
1430+
(cider-repl-add-shortcut "test-ns-with-filters" #'cider-test-run-ns-tests-with-filters)
1431+
(cider-repl-add-shortcut "test-all-with-filters" (lambda () (interactive) (cider-test-run-loaded-tests 'prompt-for-filters)))
1432+
(cider-repl-add-shortcut "test-project-with-filters" (lambda () (interactive) (cider-test-run-project-tests 'prompt-for-filters)))
14331433
(cider-repl-add-shortcut "test-report" #'cider-test-show-report)
14341434
(cider-repl-add-shortcut "run" #'cider-run)
14351435
(cider-repl-add-shortcut "conn-info" #'cider-display-connection-info)

cider-test.el

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Add to this list to have CIDER recognize additional test defining macros."
141141
(define-key map (kbd "C-t") #'cider-test-run-test)
142142
(define-key map (kbd "C-g") #'cider-test-rerun-test)
143143
(define-key map (kbd "C-n") #'cider-test-run-ns-tests)
144-
(define-key map (kbd "C-s") #'cider-test-run-ns-tests-with-selector)
144+
(define-key map (kbd "C-s") #'cider-test-run-ns-tests-with-filters)
145145
(define-key map (kbd "C-l") #'cider-test-run-loaded-tests)
146146
(define-key map (kbd "C-p") #'cider-test-run-project-tests)
147147
(define-key map (kbd "C-b") #'cider-test-show-report)
@@ -150,7 +150,7 @@ Add to this list to have CIDER recognize additional test defining macros."
150150
(define-key map (kbd "t") #'cider-test-run-test)
151151
(define-key map (kbd "g") #'cider-test-rerun-test)
152152
(define-key map (kbd "n") #'cider-test-run-ns-tests)
153-
(define-key map (kbd "s") #'cider-test-run-ns-tests-with-selector)
153+
(define-key map (kbd "s") #'cider-test-run-ns-tests-with-filters)
154154
(define-key map (kbd "l") #'cider-test-run-loaded-tests)
155155
(define-key map (kbd "p") #'cider-test-run-project-tests)
156156
(define-key map (kbd "b") #'cider-test-show-report)
@@ -160,11 +160,11 @@ Add to this list to have CIDER recognize additional test defining macros."
160160
'("Test"
161161
["Run test" cider-test-run-test]
162162
["Run namespace tests" cider-test-run-ns-tests]
163-
["Run namespace tests with selector" cider-test-run-ns-tests-with-selector]
163+
["Run namespace tests with filters" cider-test-run-ns-tests-with-filters]
164164
["Run all loaded tests" cider-test-run-loaded-tests]
165-
["Run all loaded tests with selector" (apply-partially cider-test-run-loaded-tests 'prompt-for-selector)]
165+
["Run all loaded tests with filters" (apply-partially cider-test-run-loaded-tests 'prompt-for-filters)]
166166
["Run all project tests" cider-test-run-project-tests]
167-
["Run all project tests with selector" (apply-partially cider-test-run-project-tests 'prompt-for-selector)]
167+
["Run all project tests with filters" (apply-partially cider-test-run-project-tests 'prompt-for-filters)]
168168
["Run tests after load-file" cider-auto-test-mode
169169
:style toggle :selected cider-auto-test-mode]
170170
"--"
@@ -191,7 +191,7 @@ Add to this list to have CIDER recognize additional test defining macros."
191191
;; `f' for "run failed".
192192
(define-key map "f" #'cider-test-rerun-failed-tests)
193193
(define-key map "n" #'cider-test-run-ns-tests)
194-
(define-key map "s" #'cider-test-run-ns-tests-with-selector)
194+
(define-key map "s" #'cider-test-run-ns-tests-with-filters)
195195
(define-key map "l" #'cider-test-run-loaded-tests)
196196
(define-key map "p" #'cider-test-run-project-tests)
197197
;; `g' generally reloads the buffer. The closest thing we have to that is
@@ -208,11 +208,11 @@ Add to this list to have CIDER recognize additional test defining macros."
208208
["Rerun current test" cider-test-run-test]
209209
["Rerun failed/erring tests" cider-test-rerun-failed-tests]
210210
["Run all ns tests" cider-test-run-ns-tests]
211-
["Run all ns tests with selector" cider-test-run-ns-tests-with-selector]
211+
["Run all ns tests with filters" cider-test-run-ns-tests-with-filters]
212212
["Run all loaded tests" cider-test-run-loaded-tests]
213-
["Run all loaded tests with selector" (apply-partially cider-test-run-loaded-tests 'prompt-for-selector)]
213+
["Run all loaded tests with filters" (apply-partially cider-test-run-loaded-tests 'prompt-for-filters)]
214214
["Run all project tests" cider-test-run-project-tests]
215-
["Run all project tests with selector" (apply-partially cider-test-run-project-tests 'prompt-for-selector)]
215+
["Run all project tests with filters" (apply-partially cider-test-run-project-tests 'prompt-for-filters)]
216216
"--"
217217
["Jump to test definition" cider-test-jump]
218218
["Display test error" cider-test-stacktrace]
@@ -620,7 +620,7 @@ This uses the Leiningen convention of appending '-test' to the namespace name."
620620
(declare-function cider-emit-interactive-eval-output "cider-interaction")
621621
(declare-function cider-emit-interactive-eval-err-output "cider-interaction")
622622

623-
(defun cider-test-execute (ns &optional tests silent prompt-for-selector)
623+
(defun cider-test-execute (ns &optional tests silent prompt-for-filters)
624624
"Run tests for NS, which may be a keyword, optionally specifying TESTS.
625625
626626
This tests a single NS, or multiple namespaces when using keywords `:project',
@@ -629,10 +629,18 @@ namespace is specified. Upon test completion, results are echoed and a test
629629
report is optionally displayed. When test failures/errors occur, their sources
630630
are highlighted.
631631
If SILENT is non-nil, suppress all messages other then test results.
632-
If PROMPT-FOR-SELECTOR is non-nil, prompt the user for a test selector.
633-
The selector will be used to filter the tests before running them."
632+
If PROMPT-FOR-FILTERS is non-nil, prompt the user for a test selector filters.
633+
The include/exclude selectors will be used to filter the tests before
634+
running them."
634635
(cider-test-clear-highlights)
635-
(let ((selector (when prompt-for-selector (cider-read-from-minibuffer "Test selector (as string): "))))
636+
(let ((include-selectors
637+
(when prompt-for-filters
638+
(split-string
639+
(cider-read-from-minibuffer "Test selectors to include (space separated): "))))
640+
(exclude-selectors
641+
(when prompt-for-filters
642+
(split-string
643+
(cider-read-from-minibuffer "Test selectors to exclude (space separated): ")))))
636644
(cider-map-connections
637645
(lambda (conn)
638646
(unless silent
@@ -641,16 +649,15 @@ The selector will be used to filter the tests before running them."
641649
(cider-test-echo-running ns (car tests))
642650
(cider-test-echo-running ns)))
643651
(cider-nrepl-send-request
644-
`("op" ,(cond ((stringp ns) "test")
645-
((eq :project ns) "test-all")
646-
((eq :loaded ns) "test-all")
647-
((eq :non-passing ns) "retest"))
648-
"selector" ,(when (stringp selector) selector)
649-
"ns" ,(when (stringp ns) ns)
650-
"tests" ,(when (stringp ns) tests)
651-
"load?" ,(when (or (stringp ns)
652-
(eq :project ns))
653-
"true"))
652+
`("op" ,(cond ((stringp ns) "test")
653+
((eq :project ns) "test-all")
654+
((eq :loaded ns) "test-all")
655+
((eq :non-passing ns) "retest"))
656+
"includes" ,(when (listp include-selectors) include-selectors)
657+
"excludes" ,(when (listp exclude-selectors) exclude-selectors)
658+
"ns" ,(when (stringp ns) ns)
659+
"tests" ,(when (stringp ns) tests)
660+
"load?" ,(when (or (stringp ns) (eq :project ns)) "true"))
654661
(lambda (response)
655662
(nrepl-dbind-response response (summary results status out err)
656663
(cond ((member "namespace-not-found" status)
@@ -692,40 +699,40 @@ The selector will be used to filter the tests before running them."
692699
(message "No prior failures to retest")))
693700
(message "No prior results to retest")))
694701

695-
(defun cider-test-run-loaded-tests (prompt-for-selector)
702+
(defun cider-test-run-loaded-tests (prompt-for-filters)
696703
"Run all tests defined in currently loaded namespaces.
697704
698-
If PROMPT-FOR-SELECTOR is non-nil, prompt the user for a test selector to filter the tests with."
705+
If PROMPT-FOR-FILTERS is non-nil, prompt the user for a test selectors to filter the tests with."
699706
(interactive "P")
700-
(cider-test-execute :loaded nil nil prompt-for-selector))
707+
(cider-test-execute :loaded nil nil prompt-for-filters))
701708

702-
(defun cider-test-run-project-tests (prompt-for-selector)
709+
(defun cider-test-run-project-tests (prompt-for-filters)
703710
"Run all tests defined in all project namespaces, loading these as needed.
704711
705-
If PROMPT-FOR-SELECTOR is non-nil, prompt the user for a test selector to filter the tests with."
712+
If PROMPT-FOR-FILTERS is non-nil, prompt the user for a test selectors to filter the tests with."
706713
(interactive "P")
707-
(cider-test-execute :project nil nil prompt-for-selector))
714+
(cider-test-execute :project nil nil prompt-for-filters))
708715

709-
(defun cider-test-run-ns-tests-with-selector (suppress-inference)
710-
"Run tests filtered by a selector for the current Clojure namespace context.
716+
(defun cider-test-run-ns-tests-with-filters (suppress-inference)
717+
"Run tests filtered by selectors for the current Clojure namespace context.
711718
712719
With a prefix arg SUPPRESS-INFERENCE it will try to run the tests in the
713720
current ns."
714721
(interactive "P")
715722
(cider-test-run-ns-tests suppress-inference nil 't))
716723

717-
(defun cider-test-run-ns-tests (suppress-inference &optional silent prompt-for-selector)
724+
(defun cider-test-run-ns-tests (suppress-inference &optional silent prompt-for-filters)
718725
"Run all tests for the current Clojure namespace context.
719726
720727
If SILENT is non-nil, suppress all messages other then test results.
721728
With a prefix arg SUPPRESS-INFERENCE it will try to run the tests in the
722-
current ns. If PROMPT-FOR-SELECTOR is non-nil, prompt the user for
723-
a test selector to filter the tests with."
729+
current ns. If PROMPT-FOR-FILTERS is non-nil, prompt the user for
730+
test selectors to filter the tests with."
724731
(interactive "P")
725732
(if-let* ((ns (if suppress-inference
726733
(cider-current-ns t)
727734
(funcall cider-test-infer-test-ns (cider-current-ns t)))))
728-
(cider-test-execute ns nil silent prompt-for-selector)
735+
(cider-test-execute ns nil silent prompt-for-filters)
729736
(if (eq major-mode 'cider-test-report-mode)
730737
(when (y-or-n-p (concat "Test report does not define a namespace. "
731738
"Rerun failed/erring tests?"))

0 commit comments

Comments
 (0)