Skip to content

Commit

Permalink
Handle missing connection gracefully in apropos commands
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Mar 19, 2016
1 parent db23cb5 commit 7f0b7a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cider-apropos.el
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ strings, include private vars, and be case sensitive."
(y-or-n-p "Search doc strings? ")
(y-or-n-p "Include private symbols? ")
(y-or-n-p "Case-sensitive? ")))))
(cider-ensure-connected)
(cider-ensure-op-supported "apropos")
(if-let ((summary (cider-apropos-summary
query ns docs-p privates-p case-sensitive-p))
Expand All @@ -122,6 +123,8 @@ strings, include private vars, and be case sensitive."
(defun cider-apropos-documentation ()
"Shortcut for (cider-apropos <query> nil t)."
(interactive)
(cider-ensure-connected)
(cider-ensure-op-supported "apropos")
(cider-apropos (read-string "Search for Clojure documentation (a regular expression): ") nil t))

(provide 'cider-apropos)
Expand Down
20 changes: 20 additions & 0 deletions test/cider-apropos-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(require 'ert)
(require 'noflet)
(require 'cider)
(require 'cider-apropos)

(ert-deftest cider-apropos-not-connected ()
(noflet ((cider-connected-p () nil))
(should-error (cider-apropos "test") :type 'user-error)))

(ert-deftest cider-apropos-unsupported-op ()
(noflet ((cider-ensure-op-supported (op) nil))
(should-error (cider-apropos "test") :type 'user-error)))

(ert-deftest cider-apropos-documentation-not-connected ()
(noflet ((cider-connected-p () nil))
(should-error (cider-apropos-documentation) :type 'user-error)))

(ert-deftest cider-apropos-documentation-unsupported-op ()
(noflet ((cider-ensure-op-supported (op) nil))
(should-error (cider-apropos-documentation) :type 'user-error)))

0 comments on commit 7f0b7a8

Please sign in to comment.