From 71f737d444da95c6175b513d500c56ae9711bbd0 Mon Sep 17 00:00:00 2001 From: Vitalie Spinu Date: Mon, 31 Jul 2017 11:18:07 +0200 Subject: Move relevant tests from cider-client-tests to cider-interaction-tests --- Makefile | 2 +- test/cider-client-tests.el | 40 +--------------------- test/cider-interaction-tests.el | 18 ++++++++++ test/utils/cider-connection-test-utils.el | 55 +++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 40 deletions(-) create mode 100644 test/utils/cider-connection-test-utils.el diff --git a/Makefile b/Makefile index 28d788ce..d84ff956 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ test-bytecomp : version $(ELS:.el=.elc-test) -l test/cider-bytecomp-warnings.el $< test : version build - $(CASK) exec buttercup -L . + $(CASK) exec buttercup -L . -L ./test/utils/ .PHONY: clean clean : diff --git a/test/cider-client-tests.el b/test/cider-client-tests.el index cf4c9985..2206dc47 100644 --- a/test/cider-client-tests.el +++ b/test/cider-client-tests.el @@ -31,31 +31,10 @@ (require 'buttercup) (require 'cider) (require 'cider-client) +(require 'cider-connection-test-utils) ;;; cider-client tests -(defmacro with-connection-buffer (type symbol &rest body) - "Run BODY in a temp buffer, with the given repl TYPE. -SYMBOL is locally let-bound to the current buffer." - (declare (indent 2) - (debug (sexp sexp &rest form))) - `(with-temp-buffer - (setq major-mode 'cider-repl-mode) - (setq cider-repl-type ,type) - ;; `with-current-buffer' doesn't bump the buffer up the list. - (switch-to-buffer (current-buffer)) - (rename-buffer (format "*cider-repl %s-%s*" ,type (random 10000)) t) - (let ((cider-connections (cons (current-buffer) cider-connections)) - (,symbol (current-buffer))) - ,@body))) - -(defmacro cider-test-with-buffers (buffer-names &rest body) - (let ((create (lambda (b) (list b `(generate-new-buffer " *temp*"))))) - `(let (,@(mapcar create buffer-names)) - (unwind-protect - ,@body - (mapc 'kill-buffer (list ,@buffer-names)))))) - (describe "cider-current-connection" (describe "when there are no active connections" @@ -498,20 +477,3 @@ SYMBOL is locally let-bound to the current buffer." (spy-on 'cider-connected-p :and-return-value nil) (spy-on 'clojure-expected-ns :and-return-value "clojure-expected-ns") (expect (cider-expected-ns "foo") :to-equal "clojure-expected-ns"))) - -(describe "cider-load-file" - (it "works as expected in empty Clojure buffers" - (spy-on 'cider-request:load-file :and-return-value nil) - (with-connection-buffer "clj" b - (with-temp-buffer - (clojure-mode) - (setq buffer-file-name (make-temp-name "tmp.clj")) - (expect (lambda () (cider-load-buffer)) :not :to-throw))))) - -(describe "cider-interactive-eval" - (it "works as expected in empty Clojure buffers" - (spy-on 'cider-nrepl-request:eval :and-return-value nil) - (with-connection-buffer "clj" b - (with-temp-buffer - (clojure-mode) - (expect (lambda () (cider-interactive-eval "(+ 1)")) :not :to-throw))))) diff --git a/test/cider-interaction-tests.el b/test/cider-interaction-tests.el index c2cb6f47..0681861c 100644 --- a/test/cider-interaction-tests.el +++ b/test/cider-interaction-tests.el @@ -29,6 +29,7 @@ (require 'buttercup) (require 'cider-interaction) +(require 'cider-connection-test-utils) (describe "cider--var-namespace" (it "returns the namespace of a var" @@ -84,3 +85,20 @@ (it "raises a user error if the op is not supported" (spy-on 'cider-nrepl-op-supported-p :and-return-value nil) (expect (lambda () (cider-load-all-project-ns)) :to-throw 'user-error))) + +(describe "cider-load-file" + (it "works as expected in empty Clojure buffers" + (spy-on 'cider-request:load-file :and-return-value nil) + (with-connection-buffer "clj" b + (with-temp-buffer + (clojure-mode) + (setq buffer-file-name (make-temp-name "tmp.clj")) + (expect (lambda () (cider-load-buffer)) :not :to-throw))))) + +(describe "cider-interactive-eval" + (it "works as expected in empty Clojure buffers" + (spy-on 'cider-nrepl-request:eval :and-return-value nil) + (with-connection-buffer "clj" b + (with-temp-buffer + (clojure-mode) + (expect (lambda () (cider-interactive-eval "(+ 1)")) :not :to-throw))))) diff --git a/test/utils/cider-connection-test-utils.el b/test/utils/cider-connection-test-utils.el new file mode 100644 index 00000000..b51f090e --- /dev/null +++ b/test/utils/cider-connection-test-utils.el @@ -0,0 +1,55 @@ +;;; cider-connection-test-utils.el + +;; Copyright © 2012-2017 Tim King, Bozhidar Batsov + +;; Author: Tim King +;; Bozhidar Batsov +;; Artur Malabarba + +;; This file is NOT part of GNU Emacs. + +;; This program is free software: you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation, either version 3 of the +;; License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see `http://www.gnu.org/licenses/'. + +;;; Commentary: + +;; This file is part of CIDER + +;;; Code: + +(require 'cider) +(require 'cider-client) + +(defmacro with-connection-buffer (type symbol &rest body) + "Run BODY in a temp buffer, with the given repl TYPE. +SYMBOL is locally let-bound to the current buffer." + (declare (indent 2) + (debug (sexp sexp &rest form))) + `(with-temp-buffer + (setq major-mode 'cider-repl-mode) + (setq cider-repl-type ,type) + ;; `with-current-buffer' doesn't bump the buffer up the list. + (switch-to-buffer (current-buffer)) + (rename-buffer (format "*cider-repl %s-%s*" ,type (random 10000)) t) + (let ((cider-connections (cons (current-buffer) cider-connections)) + (,symbol (current-buffer))) + ,@body))) + +(defmacro cider-test-with-buffers (buffer-names &rest body) + (let ((create (lambda (b) (list b `(generate-new-buffer " *temp*"))))) + `(let (,@(mapcar create buffer-names)) + (unwind-protect + ,@body + (mapc 'kill-buffer (list ,@buffer-names)))))) + +(provide 'cider-connection-test-utils) -- cgit v1.2.3