Skip to content

Commit

Permalink
[Fix #1776] Add new customization variable cider-test-defining-forms.
Browse files Browse the repository at this point in the history
This fix is strictly simpler than that suggested in
#1776 (comment).  It
has the advantage of being much more robust.

I partially implemented the suggested fix, and witnessed the following two
issues.  First, full "macroexpand" does not leave a recognizable `deftest` form;
it generally leaves a `(def test-... (fn [] ...))` sexp.  That implies that a
recursive macroexpansion would be required, with each step of the recursion
checking for a recognized form.  Second, even recognizing such a form is tricky,
because the expansion may refer to deftest in an aliased namespace (e.g.,
`t/deftest` or `clojure.test/deftest` rather than bare `deftest`).  One could
then try to identify possible namespaces using the current environment, but this
is getting complicated.

Therefore, I think it better to have the user configure their environment to
help them solve this problem.  (And, of course, future work can implement the
full macroexpansion approach.)
  • Loading branch information
ncalexan authored and bbatsov committed Jan 4, 2017
1 parent 72b0caa commit a4d85b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Add new customization variable `cider-special-mode-truncate-lines`.
* Add an option `cider-inspector-fill-frame` to control whether the cider inspector window fills its frame.
* [#1893](https://github.com/clojure-emacs/cider/issues/1893)Add negative prefix argument to `cider-refresh` to inhibit invoking of cider-refresh-functions
* [#1776](https://github.com/clojure-emacs/cider/issues/1776)Add new customization variable `cider-test-defining-forms` allowing new test defining forms to be recognized.

### Changes

Expand Down
11 changes: 10 additions & 1 deletion cider-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@
:group 'cider-test
: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)
:group 'cider-test
:package-version '(cider . "0.15.0"))

(defvar cider-test-last-summary nil
"The summary of the last run test.")

Expand Down Expand Up @@ -680,7 +689,7 @@ is searched."
(cider-test-execute ns (list var)))
(let ((ns (clojure-find-ns))
(def (clojure-find-def)))
(if (and ns (member (car def) '("deftest" "defspec")))
(if (and ns (member (car def) cider-test-defining-forms))
(progn
(cider-test-update-last-test ns (cdr def))
(cider-test-execute ns (cdr def)))
Expand Down
5 changes: 5 additions & 0 deletions doc/running_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ customize the variable `cider-test-infer-test-ns`. It should be bound to a
function that takes the current namespace and returns the matching test
namespace (which may be the same as the current namespace).

* 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.

* If you want to view the test report regardless of whether the tests have
passed or failed:

Expand Down

0 comments on commit a4d85b6

Please sign in to comment.