diff options
author | Bozhidar Batsov <bozhidar@batsov.com> | 2018-04-17 09:55:06 +0300 |
---|---|---|
committer | Bozhidar Batsov <bozhidar@batsov.com> | 2018-04-17 09:55:06 +0300 |
commit | 9228edd20d2669e57be834e65fa312ec22d60a17 (patch) | |
tree | 9a3d01f259e7309a8c196ba2c953923efb5d90d0 /cider-test.el | |
parent | fdb0b91a5229b60d5fdd08e7f18b1362c1839710 (diff) |
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.
Diffstat (limited to 'cider-test.el')
-rw-r--r-- | cider-test.el | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/cider-test.el b/cider-test.el index ffacb570..2dfeb07c 100644 --- a/cider-test.el +++ b/cider-test.el @@ -141,7 +141,7 @@ Add to this list to have CIDER recognize additional test defining macros." (define-key map (kbd "C-t") #'cider-test-run-test) (define-key map (kbd "C-g") #'cider-test-rerun-test) (define-key map (kbd "C-n") #'cider-test-run-ns-tests) - (define-key map (kbd "C-s") #'cider-test-run-ns-tests-with-selector) + (define-key map (kbd "C-s") #'cider-test-run-ns-tests-with-filters) (define-key map (kbd "C-l") #'cider-test-run-loaded-tests) (define-key map (kbd "C-p") #'cider-test-run-project-tests) (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." (define-key map (kbd "t") #'cider-test-run-test) (define-key map (kbd "g") #'cider-test-rerun-test) (define-key map (kbd "n") #'cider-test-run-ns-tests) - (define-key map (kbd "s") #'cider-test-run-ns-tests-with-selector) + (define-key map (kbd "s") #'cider-test-run-ns-tests-with-filters) (define-key map (kbd "l") #'cider-test-run-loaded-tests) (define-key map (kbd "p") #'cider-test-run-project-tests) (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." '("Test" ["Run test" cider-test-run-test] ["Run namespace tests" cider-test-run-ns-tests] - ["Run namespace tests with selector" cider-test-run-ns-tests-with-selector] + ["Run namespace tests with filters" cider-test-run-ns-tests-with-filters] ["Run all loaded tests" cider-test-run-loaded-tests] - ["Run all loaded tests with selector" (apply-partially cider-test-run-loaded-tests 'prompt-for-selector)] + ["Run all loaded tests with filters" (apply-partially cider-test-run-loaded-tests 'prompt-for-filters)] ["Run all project tests" cider-test-run-project-tests] - ["Run all project tests with selector" (apply-partially cider-test-run-project-tests 'prompt-for-selector)] + ["Run all project tests with filters" (apply-partially cider-test-run-project-tests 'prompt-for-filters)] ["Run tests after load-file" cider-auto-test-mode :style toggle :selected cider-auto-test-mode] "--" @@ -191,7 +191,7 @@ Add to this list to have CIDER recognize additional test defining macros." ;; `f' for "run failed". (define-key map "f" #'cider-test-rerun-failed-tests) (define-key map "n" #'cider-test-run-ns-tests) - (define-key map "s" #'cider-test-run-ns-tests-with-selector) + (define-key map "s" #'cider-test-run-ns-tests-with-filters) (define-key map "l" #'cider-test-run-loaded-tests) (define-key map "p" #'cider-test-run-project-tests) ;; `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." ["Rerun current test" cider-test-run-test] ["Rerun failed/erring tests" cider-test-rerun-failed-tests] ["Run all ns tests" cider-test-run-ns-tests] - ["Run all ns tests with selector" cider-test-run-ns-tests-with-selector] + ["Run all ns tests with filters" cider-test-run-ns-tests-with-filters] ["Run all loaded tests" cider-test-run-loaded-tests] - ["Run all loaded tests with selector" (apply-partially cider-test-run-loaded-tests 'prompt-for-selector)] + ["Run all loaded tests with filters" (apply-partially cider-test-run-loaded-tests 'prompt-for-filters)] ["Run all project tests" cider-test-run-project-tests] - ["Run all project tests with selector" (apply-partially cider-test-run-project-tests 'prompt-for-selector)] + ["Run all project tests with filters" (apply-partially cider-test-run-project-tests 'prompt-for-filters)] "--" ["Jump to test definition" cider-test-jump] ["Display test error" cider-test-stacktrace] @@ -620,7 +620,7 @@ This uses the Leiningen convention of appending '-test' to the namespace name." (declare-function cider-emit-interactive-eval-output "cider-interaction") (declare-function cider-emit-interactive-eval-err-output "cider-interaction") -(defun cider-test-execute (ns &optional tests silent prompt-for-selector) +(defun cider-test-execute (ns &optional tests silent prompt-for-filters) "Run tests for NS, which may be a keyword, optionally specifying TESTS. 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 report is optionally displayed. When test failures/errors occur, their sources are highlighted. If SILENT is non-nil, suppress all messages other then test results. -If PROMPT-FOR-SELECTOR is non-nil, prompt the user for a test selector. -The selector will be used to filter the tests before running them." +If PROMPT-FOR-FILTERS is non-nil, prompt the user for a test selector filters. +The include/exclude selectors will be used to filter the tests before + running them." (cider-test-clear-highlights) - (let ((selector (when prompt-for-selector (cider-read-from-minibuffer "Test selector (as string): ")))) + (let ((include-selectors + (when prompt-for-filters + (split-string + (cider-read-from-minibuffer "Test selectors to include (space separated): ")))) + (exclude-selectors + (when prompt-for-filters + (split-string + (cider-read-from-minibuffer "Test selectors to exclude (space separated): "))))) (cider-map-connections (lambda (conn) (unless silent @@ -641,16 +649,15 @@ The selector will be used to filter the tests before running them." (cider-test-echo-running ns (car tests)) (cider-test-echo-running ns))) (cider-nrepl-send-request - `("op" ,(cond ((stringp ns) "test") - ((eq :project ns) "test-all") - ((eq :loaded ns) "test-all") - ((eq :non-passing ns) "retest")) - "selector" ,(when (stringp selector) selector) - "ns" ,(when (stringp ns) ns) - "tests" ,(when (stringp ns) tests) - "load?" ,(when (or (stringp ns) - (eq :project ns)) - "true")) + `("op" ,(cond ((stringp ns) "test") + ((eq :project ns) "test-all") + ((eq :loaded ns) "test-all") + ((eq :non-passing ns) "retest")) + "includes" ,(when (listp include-selectors) include-selectors) + "excludes" ,(when (listp exclude-selectors) exclude-selectors) + "ns" ,(when (stringp ns) ns) + "tests" ,(when (stringp ns) tests) + "load?" ,(when (or (stringp ns) (eq :project ns)) "true")) (lambda (response) (nrepl-dbind-response response (summary results status out err) (cond ((member "namespace-not-found" status) @@ -692,40 +699,40 @@ The selector will be used to filter the tests before running them." (message "No prior failures to retest"))) (message "No prior results to retest"))) -(defun cider-test-run-loaded-tests (prompt-for-selector) +(defun cider-test-run-loaded-tests (prompt-for-filters) "Run all tests defined in currently loaded namespaces. -If PROMPT-FOR-SELECTOR is non-nil, prompt the user for a test selector to filter the tests with." +If PROMPT-FOR-FILTERS is non-nil, prompt the user for a test selectors to filter the tests with." (interactive "P") - (cider-test-execute :loaded nil nil prompt-for-selector)) + (cider-test-execute :loaded nil nil prompt-for-filters)) -(defun cider-test-run-project-tests (prompt-for-selector) +(defun cider-test-run-project-tests (prompt-for-filters) "Run all tests defined in all project namespaces, loading these as needed. -If PROMPT-FOR-SELECTOR is non-nil, prompt the user for a test selector to filter the tests with." +If PROMPT-FOR-FILTERS is non-nil, prompt the user for a test selectors to filter the tests with." (interactive "P") - (cider-test-execute :project nil nil prompt-for-selector)) + (cider-test-execute :project nil nil prompt-for-filters)) -(defun cider-test-run-ns-tests-with-selector (suppress-inference) - "Run tests filtered by a selector for the current Clojure namespace context. +(defun cider-test-run-ns-tests-with-filters (suppress-inference) + "Run tests filtered by selectors for the current Clojure namespace context. With a prefix arg SUPPRESS-INFERENCE it will try to run the tests in the current ns." (interactive "P") (cider-test-run-ns-tests suppress-inference nil 't)) -(defun cider-test-run-ns-tests (suppress-inference &optional silent prompt-for-selector) +(defun cider-test-run-ns-tests (suppress-inference &optional silent prompt-for-filters) "Run all tests for the current Clojure namespace context. If SILENT is non-nil, suppress all messages other then test results. With a prefix arg SUPPRESS-INFERENCE it will try to run the tests in the -current ns. If PROMPT-FOR-SELECTOR is non-nil, prompt the user for -a test selector to filter the tests with." +current ns. If PROMPT-FOR-FILTERS is non-nil, prompt the user for +test selectors to filter the tests with." (interactive "P") (if-let* ((ns (if suppress-inference (cider-current-ns t) (funcall cider-test-infer-test-ns (cider-current-ns t))))) - (cider-test-execute ns nil silent prompt-for-selector) + (cider-test-execute ns nil silent prompt-for-filters) (if (eq major-mode 'cider-test-report-mode) (when (y-or-n-p (concat "Test report does not define a namespace. " "Rerun failed/erring tests?")) |