Skip to content

Commit

Permalink
[Fix #1425] Define cider-auto-test-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Malabarba committed Mar 30, 2016
1 parent 46f5d41 commit 6804a6a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ an individual test using `C-c C-t t`.

### New Features

* [#1636](https://github.com/clojure-emacs/cider/pull/1636): New minor-mode `cider-auto-test-mode` for test-driven-development. When activated, tests are rerun after every load-file.
* Javadoc commands take into account the variable `clojure.java.javadoc/*remote-javadocs*`.
* Javadoc also works on classes of the AmazonAWS Java SDK.
* Apropos commands now accept lists of space-separated words as arguments, in addition to regular expressions (similar to Emacs's own apropos commands).
Expand Down
23 changes: 23 additions & 0 deletions cider-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,29 @@ is searched."
(cider-test-execute ns (cdr def))
(message "No test at point"))))))

;;; Auto-test mode
(defun cider--test-silently ()
"Like `cider-test-run-tests', but with less feedback.
Only notify the user if there actually were any tests to run and only after
the results are received."
(when (cider-connected-p)
(let ((cider-auto-select-test-report-buffer nil)
(cider-test-show-report-on-success nil))
(cider-test-run-ns-tests nil 'soft))))

;;;###autoload
(define-minor-mode cider-auto-test-mode
"Toggle automatic testing of Clojure files.
When enabled this reruns tests every time a Clojure file is loaded.
Only runs tests corresponding to the loaded file's namespace and does
nothing if no tests are defined or if the file failed to load."
nil (cider-mode " Test") nil
:global t
(if cider-auto-test-mode
(add-hook 'cider-file-loaded-hook #'cider--test-silently)
(remove-hook 'cider-file-loaded-hook #'cider--test-silently)))

(provide 'cider-test)

;;; cider-test.el ends here
14 changes: 14 additions & 0 deletions doc/extended_workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ passed or failed:
(setq cider-test-show-report-on-success t)
```

#### Running tests automatically (test-driven development)

CIDER provides a minor-mode that automatically runs all tests for a namespace
whenever you load a file (with <kbd>C-c C-k</kbd>). You can toggle it
manually with <kbd>M-x</kbd> `cider-auto-test-mode`, or you can use:

```el
(cider-auto-test-mode 1)
```

This is completely equivalent to manually typing <kbd>C-c C-t C-n</kbd> every
time you load a Clojure buffer. Also, as described above before, CIDER is smart
enough to figure out the namespace containing the tests.

#### Using cider-test with alternative test libraries

The `clojure.test` machinery is designed to be pluggable. Any test library
Expand Down

0 comments on commit 6804a6a

Please sign in to comment.