branch: elpa/cider
commit 9efbf2d3ab6a8de87c9d757c027996441657af01
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
Signal an error when running tests without a connection
Switching `cider-test-execute' to `cider-map-repls :auto' (for the new
ClojureScript test support) silently dropped the connection guard: with
`:auto', `cider-map-repls' maps over zero REPLs when disconnected, so the
command just did nothing instead of raising the usual "no REPL" error.
None of the public test commands guard upstream, so pressing a test key
with no REPL connected was a silent no-op. Add `cider-ensure-session' to
fail fast with a clear message.
---
lisp/cider-test.el | 4 ++++
test/cider-test-tests.el | 9 +++++++++
2 files changed, 13 insertions(+)
diff --git a/lisp/cider-test.el b/lisp/cider-test.el
index 052dfe1acf..822e91e561 100644
--- a/lisp/cider-test.el
+++ b/lisp/cider-test.el
@@ -846,6 +846,10 @@ If SILENT is non-nil, suppress all messages other then
test results.
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-map-repls' with `:auto' does not ensure a connection (it maps over
+ ;; zero REPLs when disconnected), so guard here to fail fast with a clear
+ ;; error instead of silently doing nothing.
+ (cider-ensure-session)
(cider-test-clear-highlights)
(let ((include-selectors
(if prompt-for-filters
diff --git a/test/cider-test-tests.el b/test/cider-test-tests.el
index 465b99d316..103ffa0b9b 100644
--- a/test/cider-test-tests.el
+++ b/test/cider-test-tests.el
@@ -189,3 +189,12 @@
(lambda () (setq captured (list cider-test-default-include-selectors
cider-test-default-exclude-selectors))))
(expect captured :to-equal '(("keep") ("skip"))))))
+
+(describe "cider-test-execute"
+ (it "fails fast without a session, before dispatching to any REPL"
+ (spy-on 'cider-ensure-session :and-call-fake
+ (lambda () (user-error "No linked CIDER sessions")))
+ (spy-on 'cider-map-repls)
+ (expect (cider-test-execute :loaded) :to-throw 'user-error)
+ ;; the guard must fire before any REPL dispatch / side effect
+ (expect 'cider-map-repls :not :to-have-been-called)))