Skip to content

Commit 71f737d

Browse files
vspinubbatsov
authored andcommitted
Move relevant tests from cider-client-tests to cider-interaction-tests
1 parent 2f28196 commit 71f737d

File tree

4 files changed

+75
-40
lines changed

4 files changed

+75
-40
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test-bytecomp : version $(ELS:.el=.elc-test)
3838
-l test/cider-bytecomp-warnings.el $<
3939

4040
test : version build
41-
$(CASK) exec buttercup -L .
41+
$(CASK) exec buttercup -L . -L ./test/utils/
4242

4343
.PHONY: clean
4444
clean :

test/cider-client-tests.el

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,10 @@
3131
(require 'buttercup)
3232
(require 'cider)
3333
(require 'cider-client)
34+
(require 'cider-connection-test-utils)
3435

3536
;;; cider-client tests
3637

37-
(defmacro with-connection-buffer (type symbol &rest body)
38-
"Run BODY in a temp buffer, with the given repl TYPE.
39-
SYMBOL is locally let-bound to the current buffer."
40-
(declare (indent 2)
41-
(debug (sexp sexp &rest form)))
42-
`(with-temp-buffer
43-
(setq major-mode 'cider-repl-mode)
44-
(setq cider-repl-type ,type)
45-
;; `with-current-buffer' doesn't bump the buffer up the list.
46-
(switch-to-buffer (current-buffer))
47-
(rename-buffer (format "*cider-repl %s-%s*" ,type (random 10000)) t)
48-
(let ((cider-connections (cons (current-buffer) cider-connections))
49-
(,symbol (current-buffer)))
50-
,@body)))
51-
52-
(defmacro cider-test-with-buffers (buffer-names &rest body)
53-
(let ((create (lambda (b) (list b `(generate-new-buffer " *temp*")))))
54-
`(let (,@(mapcar create buffer-names))
55-
(unwind-protect
56-
,@body
57-
(mapc 'kill-buffer (list ,@buffer-names))))))
58-
5938
(describe "cider-current-connection"
6039

6140
(describe "when there are no active connections"
@@ -498,20 +477,3 @@ SYMBOL is locally let-bound to the current buffer."
498477
(spy-on 'cider-connected-p :and-return-value nil)
499478
(spy-on 'clojure-expected-ns :and-return-value "clojure-expected-ns")
500479
(expect (cider-expected-ns "foo") :to-equal "clojure-expected-ns")))
501-
502-
(describe "cider-load-file"
503-
(it "works as expected in empty Clojure buffers"
504-
(spy-on 'cider-request:load-file :and-return-value nil)
505-
(with-connection-buffer "clj" b
506-
(with-temp-buffer
507-
(clojure-mode)
508-
(setq buffer-file-name (make-temp-name "tmp.clj"))
509-
(expect (lambda () (cider-load-buffer)) :not :to-throw)))))
510-
511-
(describe "cider-interactive-eval"
512-
(it "works as expected in empty Clojure buffers"
513-
(spy-on 'cider-nrepl-request:eval :and-return-value nil)
514-
(with-connection-buffer "clj" b
515-
(with-temp-buffer
516-
(clojure-mode)
517-
(expect (lambda () (cider-interactive-eval "(+ 1)")) :not :to-throw)))))

test/cider-interaction-tests.el

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
(require 'buttercup)
3131
(require 'cider-interaction)
32+
(require 'cider-connection-test-utils)
3233

3334
(describe "cider--var-namespace"
3435
(it "returns the namespace of a var"
@@ -84,3 +85,20 @@
8485
(it "raises a user error if the op is not supported"
8586
(spy-on 'cider-nrepl-op-supported-p :and-return-value nil)
8687
(expect (lambda () (cider-load-all-project-ns)) :to-throw 'user-error)))
88+
89+
(describe "cider-load-file"
90+
(it "works as expected in empty Clojure buffers"
91+
(spy-on 'cider-request:load-file :and-return-value nil)
92+
(with-connection-buffer "clj" b
93+
(with-temp-buffer
94+
(clojure-mode)
95+
(setq buffer-file-name (make-temp-name "tmp.clj"))
96+
(expect (lambda () (cider-load-buffer)) :not :to-throw)))))
97+
98+
(describe "cider-interactive-eval"
99+
(it "works as expected in empty Clojure buffers"
100+
(spy-on 'cider-nrepl-request:eval :and-return-value nil)
101+
(with-connection-buffer "clj" b
102+
(with-temp-buffer
103+
(clojure-mode)
104+
(expect (lambda () (cider-interactive-eval "(+ 1)")) :not :to-throw)))))
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
;;; cider-connection-test-utils.el
2+
3+
;; Copyright © 2012-2017 Tim King, Bozhidar Batsov
4+
5+
;; Author: Tim King <[email protected]>
6+
;; Bozhidar Batsov <[email protected]>
7+
;; Artur Malabarba <[email protected]>
8+
9+
;; This file is NOT part of GNU Emacs.
10+
11+
;; This program is free software: you can redistribute it and/or
12+
;; modify it under the terms of the GNU General Public License as
13+
;; published by the Free Software Foundation, either version 3 of the
14+
;; License, or (at your option) any later version.
15+
;;
16+
;; This program is distributed in the hope that it will be useful, but
17+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
18+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
;; General Public License for more details.
20+
;;
21+
;; You should have received a copy of the GNU General Public License
22+
;; along with this program. If not, see `http://www.gnu.org/licenses/'.
23+
24+
;;; Commentary:
25+
26+
;; This file is part of CIDER
27+
28+
;;; Code:
29+
30+
(require 'cider)
31+
(require 'cider-client)
32+
33+
(defmacro with-connection-buffer (type symbol &rest body)
34+
"Run BODY in a temp buffer, with the given repl TYPE.
35+
SYMBOL is locally let-bound to the current buffer."
36+
(declare (indent 2)
37+
(debug (sexp sexp &rest form)))
38+
`(with-temp-buffer
39+
(setq major-mode 'cider-repl-mode)
40+
(setq cider-repl-type ,type)
41+
;; `with-current-buffer' doesn't bump the buffer up the list.
42+
(switch-to-buffer (current-buffer))
43+
(rename-buffer (format "*cider-repl %s-%s*" ,type (random 10000)) t)
44+
(let ((cider-connections (cons (current-buffer) cider-connections))
45+
(,symbol (current-buffer)))
46+
,@body)))
47+
48+
(defmacro cider-test-with-buffers (buffer-names &rest body)
49+
(let ((create (lambda (b) (list b `(generate-new-buffer " *temp*")))))
50+
`(let (,@(mapcar create buffer-names))
51+
(unwind-protect
52+
,@body
53+
(mapc 'kill-buffer (list ,@buffer-names))))))
54+
55+
(provide 'cider-connection-test-utils)

0 commit comments

Comments
 (0)