@@ -141,6 +141,7 @@ Add to this list to have CIDER recognize additional test defining macros."
141
141
(define-key map (kbd " C-t" ) #'cider-test-run-test )
142
142
(define-key map (kbd " C-g" ) #'cider-test-rerun-test )
143
143
(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
145
(define-key map (kbd " C-l" ) #'cider-test-run-loaded-tests )
145
146
(define-key map (kbd " C-p" ) #'cider-test-run-project-tests )
146
147
(define-key map (kbd " C-b" ) #'cider-test-show-report )
@@ -149,6 +150,7 @@ Add to this list to have CIDER recognize additional test defining macros."
149
150
(define-key map (kbd " t" ) #'cider-test-run-test )
150
151
(define-key map (kbd " g" ) #'cider-test-rerun-test )
151
152
(define-key map (kbd " n" ) #'cider-test-run-ns-tests )
153
+ (define-key map (kbd " s" ) #'cider-test-run-ns-tests-with-selector )
152
154
(define-key map (kbd " l" ) #'cider-test-run-loaded-tests )
153
155
(define-key map (kbd " p" ) #'cider-test-run-project-tests )
154
156
(define-key map (kbd " b" ) #'cider-test-show-report )
@@ -158,8 +160,11 @@ Add to this list to have CIDER recognize additional test defining macros."
158
160
'(" Test"
159
161
[" Run test" cider-test-run-test]
160
162
[" Run namespace tests" cider-test-run-ns-tests]
163
+ [" Run namespace tests with selector" cider-test-run-ns-tests-with-selector]
161
164
[" 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 )]
162
166
[" 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 )]
163
168
[" Run tests after load-file" cider-auto-test-mode
164
169
:style toggle :selected cider-auto-test-mode]
165
170
" --"
@@ -186,6 +191,7 @@ Add to this list to have CIDER recognize additional test defining macros."
186
191
; ; `f' for "run failed".
187
192
(define-key map " f" #'cider-test-rerun-failed-tests )
188
193
(define-key map " n" #'cider-test-run-ns-tests )
194
+ (define-key map " s" #'cider-test-run-ns-tests-with-selector )
189
195
(define-key map " l" #'cider-test-run-loaded-tests )
190
196
(define-key map " p" #'cider-test-run-project-tests )
191
197
; ; `g' generally reloads the buffer. The closest thing we have to that is
@@ -202,8 +208,11 @@ Add to this list to have CIDER recognize additional test defining macros."
202
208
[" Rerun current test" cider-test-run-test]
203
209
[" Rerun failed/erring tests" cider-test-rerun-failed-tests]
204
210
[" Run all ns tests" cider-test-run-ns-tests]
211
+ [" Run all ns tests with selector" cider-test-run-ns-tests-with-selector]
205
212
[" 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 )]
206
214
[" 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 )]
207
216
" --"
208
217
[" Jump to test definition" cider-test-jump]
209
218
[" Display test error" cider-test-stacktrace]
@@ -611,61 +620,67 @@ This uses the Leiningen convention of appending '-test' to the namespace name."
611
620
(declare-function cider-emit-interactive-eval-output " cider-interaction" )
612
621
(declare-function cider-emit-interactive-eval-err-output " cider-interaction" )
613
622
614
- (defun cider-test-execute (ns &optional tests silent )
623
+ (defun cider-test-execute (ns &optional tests silent prompt-for-selector )
615
624
" Run tests for NS, which may be a keyword, optionally specifying TESTS.
616
625
617
626
This tests a single NS, or multiple namespaces when using keywords `:project' ,
618
627
`:loaded' or `:non-passing' . Optional TESTS are only honored when a single
619
628
namespace is specified. Upon test completion, results are echoed and a test
620
629
report is optionally displayed. When test failures/errors occur, their sources
621
630
are highlighted.
622
- If SILENT is non-nil, suppress all messages other then test results."
631
+ 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."
623
634
(cider-test-clear-highlights)
624
- (cider-map-connections
625
- (lambda (conn )
626
- (unless silent
627
- (if (and tests (= (length tests) 1 ))
628
- ; ; we generate a different message when running individual tests
629
- (cider-test-echo-running ns (car tests))
630
- (cider-test-echo-running ns)))
631
- (cider-nrepl-send-request
632
- `(" op" ,(cond ((stringp ns) " test" )
633
- ((eq :project ns) " test-all" )
634
- ((eq :loaded ns) " test-all" )
635
- ((eq :non-passing ns) " retest" ))
636
- " ns" ,(when (stringp ns) ns)
637
- " tests" ,(when (stringp ns) tests)
638
- " load?" ,(when (or (stringp ns)
639
- (eq :project ns))
640
- " true" ))
641
- (lambda (response )
642
- (nrepl-dbind-response response (summary results status out err)
643
- (cond ((member " namespace-not-found" status)
644
- (unless silent
645
- (message " No test namespace: %s " (cider-propertize ns 'ns ))))
646
- (out (cider-emit-interactive-eval-output out))
647
- (err (cider-emit-interactive-eval-err-output err))
648
- (results
649
- (nrepl-dbind-response summary (error fail)
650
- (setq cider-test-last-summary summary)
651
- (setq cider-test-last-results results)
652
- (cider-test-highlight-problems results)
653
- (cider-test-echo-summary summary results)
654
- (if (or (not (zerop (+ error fail)))
655
- cider-test-show-report-on-success)
656
- (cider-test-render-report
657
- (cider-popup-buffer cider-test-report-buffer
658
- cider-auto-select-test-report-buffer)
659
- summary results)
660
- (when (get-buffer cider-test-report-buffer)
661
- (with-current-buffer cider-test-report-buffer
662
- (let ((inhibit-read-only t ))
663
- (erase-buffer )))
664
- (cider-test-render-report
665
- cider-test-report-buffer
666
- summary results))))))))
667
- conn))
668
- :clj ))
635
+ (let ((selector (when prompt-for-selector (cider-read-from-minibuffer " Test selector (as string): " ))))
636
+ (cider-map-connections
637
+ (lambda (conn )
638
+ (unless silent
639
+ (if (and tests (= (length tests) 1 ))
640
+ ; ; we generate a different message when running individual tests
641
+ (cider-test-echo-running ns (car tests))
642
+ (cider-test-echo-running ns)))
643
+ (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" ))
654
+ (lambda (response )
655
+ (nrepl-dbind-response response (summary results status out err)
656
+ (cond ((member " namespace-not-found" status)
657
+ (unless silent
658
+ (message " No test namespace: %s " (cider-propertize ns 'ns ))))
659
+ (out (cider-emit-interactive-eval-output out))
660
+ (err (cider-emit-interactive-eval-err-output err))
661
+ (results
662
+ (nrepl-dbind-response summary (error fail)
663
+ (setq cider-test-last-summary summary)
664
+ (setq cider-test-last-results results)
665
+ (cider-test-highlight-problems results)
666
+ (cider-test-echo-summary summary results)
667
+ (if (or (not (zerop (+ error fail)))
668
+ cider-test-show-report-on-success)
669
+ (cider-test-render-report
670
+ (cider-popup-buffer
671
+ cider-test-report-buffer
672
+ cider-auto-select-test-report-buffer)
673
+ summary
674
+ results)
675
+ (when (get-buffer cider-test-report-buffer)
676
+ (with-current-buffer cider-test-report-buffer
677
+ (let ((inhibit-read-only t ))
678
+ (erase-buffer )))
679
+ (cider-test-render-report
680
+ cider-test-report-buffer
681
+ summary results))))))))
682
+ conn))
683
+ :clj )))
669
684
670
685
(defun cider-test-rerun-failed-tests ()
671
686
" Rerun failed and erring tests from the last test run."
@@ -677,27 +692,40 @@ If SILENT is non-nil, suppress all messages other then test results."
677
692
(message " No prior failures to retest " )))
678
693
(message " No prior results to retest " )))
679
694
680
- (defun cider-test-run-loaded-tests ()
681
- " Run all tests defined in currently loaded namespaces."
682
- (interactive )
683
- (cider-test-execute :loaded ))
695
+ (defun cider-test-run-loaded-tests (prompt-for-selector )
696
+ " Run all tests defined in currently loaded namespaces.
684
697
685
- (defun cider-test-run-project-tests ()
686
- " Run all tests defined in all project namespaces, loading these as needed."
687
- (interactive )
688
- (cider-test-execute :project ))
698
+ If PROMPT-FOR-SELECTOR is non-nil, prompt the user for a test selector to filter the tests with."
699
+ (interactive " P" )
700
+ (cider-test-execute :loaded nil nil prompt-for-selector))
701
+
702
+ (defun cider-test-run-project-tests (prompt-for-selector )
703
+ " Run all tests defined in all project namespaces, loading these as needed.
704
+
705
+ If PROMPT-FOR-SELECTOR is non-nil, prompt the user for a test selector to filter the tests with."
706
+ (interactive " P" )
707
+ (cider-test-execute :project nil nil prompt-for-selector))
689
708
690
- (defun cider-test-run-ns-tests (suppress-inference &optional silent )
709
+ (defun cider-test-run-ns-tests-with-selector (suppress-inference )
710
+ " Run tests filtered by a selector for the current Clojure namespace context.
711
+
712
+ With a prefix arg SUPPRESS-INFERENCE it will try to run the tests in the
713
+ current ns."
714
+ (interactive " P" )
715
+ (cider-test-run-ns-tests suppress-inference nil 't ))
716
+
717
+ (defun cider-test-run-ns-tests (suppress-inference &optional silent prompt-for-selector )
691
718
" Run all tests for the current Clojure namespace context.
692
719
693
720
If SILENT is non-nil, suppress all messages other then test results.
694
721
With a prefix arg SUPPRESS-INFERENCE it will try to run the tests in the
695
- current ns."
722
+ current ns. If PROMPT-FOR-SELECTOR is non-nil, prompt the user for
723
+ a test selector to filter the tests with."
696
724
(interactive " P" )
697
725
(if-let* ((ns (if suppress-inference
698
726
(cider-current-ns t )
699
727
(funcall cider-test-infer-test-ns (cider-current-ns t )))))
700
- (cider-test-execute ns nil silent)
728
+ (cider-test-execute ns nil silent prompt-for-selector )
701
729
(if (eq major-mode 'cider-test-report-mode )
702
730
(when (y-or-n-p (concat " Test report does not define a namespace. "
703
731
" Rerun failed/erring tests?" ))
0 commit comments