Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

interim commit while changing machines

  • Loading branch information...
commit 1053ecb2af588b8c6cc02f1043623af2d49b7f73 1 parent 2cacb8d
Gareth Jones authored
Showing with 62 additions and 52 deletions.
  1. +62 −52 clojure-test-mode.el
View
114 clojure-test-mode.el
@@ -37,7 +37,7 @@
;;; Usage:
-;; Once you have a SLIME session active, you can run the tests in the
+;; Once you have an nrepl session active, you can run the tests in the
;; current buffer with C-c C-,. Failing tests and errors will be
;; highlighted using overlays. To clear the overlays, use C-c k.
@@ -124,15 +124,11 @@
(require 'clojure-mode)
(require 'which-func)
(require 'nrepl nil t)
-(require 'slime nil t)
(declare-function nrepl-repl-buffer "nrepl.el")
(declare-function nrepl-make-response-handler "nrepl.el")
(declare-function nrepl-send-string "nrepl.el")
(declare-function nrepl-current-ns "nrepl.el")
-(declare-function slime-eval-async "slime.el")
-(declare-function slime-connection-name "slime.el")
-(declare-function slime-connected-p "slime.el")
;; Faces
@@ -176,26 +172,29 @@
;; Support Functions
-(defun clojure-test-make-handler (value-handler)
- (let ((out-handler (lambda (_ out)
- (with-current-buffer (nrepl-repl-buffer)
- (insert out)))))
- (nrepl-make-response-handler (current-buffer)
+(defun clojure-test-nrepl-connected-p ()
+ (get-buffer "*nrepl-connection*"))
+
+(defun clojure-test-make-handler (callback)
+ (lexical-let ((buffer (current-buffer))
+ (callback callback))
+ (nrepl-make-response-handler buffer
+ (lambda (buffer value)
+ (funcall callback buffer value))
(lambda (buffer value)
- (funcall value-handler value))
- out-handler out-handler nil)))
+ (nrepl-emit-interactive-output value))
+ (lambda (buffer err)
+ (nrepl-emit-interactive-output err))
+ '())))
(defun clojure-test-eval (string &optional handler)
- (if (get-buffer "*nrepl-connection*")
- (nrepl-send-string string (or (nrepl-current-ns) "user")
- (clojure-test-make-handler (or handler #'identity)))
- (slime-eval-async `(swank:eval-and-grab-output ,string)
- (or handler #'identity))))
+ (nrepl-send-string string
+ (clojure-test-make-handler (or handler #'identity))
+ (or (nrepl-current-ns) "user")))
(defun clojure-test-load-reporting ()
"Redefine the test-is report function to store results in metadata."
- (when (or (get-buffer "*nrepl-connection*")
- (eq (compare-strings "clojure" 0 7 (slime-connection-name) 0 7) t))
+ (when (clojure-test-nrepl-connected-p)
(clojure-test-eval
"(ns clojure.test.mode
(:use [clojure.test :only [file-position *testing-vars* *test-out*
@@ -241,29 +240,17 @@
(do-report {:type :end-test-ns, :ns ns-obj}))
(do-report (assoc @*report-counters* :type :summary))))")))
-(defun clojure-test-get-results (result)
- (clojure-test-eval
- (concat "(map #(cons (str (:name (meta %)))
+(defun clojure-test-get-results (buffer result)
+ (with-current-buffer buffer
+ (clojure-test-eval
+ (concat "(map #(cons (str (:name (meta %)))
(:status (meta %))) (vals (ns-interns '"
- (clojure-find-ns) ")))")
- #'clojure-test-extract-results))
+ (clojure-find-ns) ")))")
+ #'clojure-test-extract-results)))
-(defun clojure-test-echo-results ()
- (message
- (propertize
- (format "Ran %s tests. %s failures, %s errors."
- clojure-test-count clojure-test-failure-count
- clojure-test-error-count)
- 'face
- (cond ((not (= clojure-test-error-count 0)) 'clojure-test-error-face)
- ((not (= clojure-test-failure-count 0)) 'clojure-test-failure-face)
- (t 'clojure-test-success-face)))))
-
-(defun clojure-test-extract-results (results)
- (let ((result-vars (read (cadr results))))
- ;; slime-eval-async hands us a cons with a useless car
+(defun clojure-test-extract-results (buffer results)
+ (let ((result-vars (read results)))
(mapc #'clojure-test-extract-result result-vars)
- ;; (slime-repl-emit (concat "\n" (make-string (1- (window-width)) ?=) "\n"))
(clojure-test-echo-results)))
(defun clojure-test-extract-result (result)
@@ -280,6 +267,16 @@
(incf clojure-test-error-count)
(clojure-test-highlight-problem line event actual)))))))
+(defun clojure-test-echo-results ()
+ (message
+ (propertize
+ (format "Ran %s tests. %s failures, %s errors."
+ clojure-test-count clojure-test-failure-count
+ clojure-test-error-count)
+ 'face
+ (cond ((not (= clojure-test-error-count 0)) 'clojure-test-error-face)
+ ((not (= clojure-test-failure-count 0)) 'clojure-test-failure-face)
+ (t 'clojure-test-success-face)))))
(defun clojure-test-highlight-problem (line event message)
(save-excursion
@@ -333,12 +330,25 @@ Retuns the problem overlay if such a position is found, otherwise nil."
clojure-test-ns-segment-position))
(before (subseq segments 0 clojure-test-ns-segment-position))
(after (subseq segments clojure-test-ns-segment-position))
- (newfile (replace-regexp-in-string "_test$" "" (car after)))
+ (newfile (replace-regexp-in-string "_test$" "" (car after)))
(impl-segments (append before (list newfile))))
(mapconcat 'identity impl-segments "/")))
;; Commands
+(defun clojure-test-wang ()
+ (interactive)
+ (clojure-test-eval
+ "(doseq [t (vals (ns-interns *ns*))]
+ (alter-meta! t assoc :status [])
+ (alter-meta! t assoc :test nil))"
+ (lambda (buffer value)
+ (message "sup")))
+ ;; (clojure-test-clear
+ ;; (lambda (buffer value)
+ ;; (message "cleared tests")))
+ )
+
(defun clojure-test-run-tests ()
"Run all the tests in the current namespace."
(interactive)
@@ -348,15 +358,16 @@ Retuns the problem overlay if such a position is found, otherwise nil."
(if (not (clojure-in-tests-p))
(clojure-jump-to-test))
(clojure-test-clear
- (lambda (&rest args)
- ;; clojure-test-eval will wrap in with-out-str
- (clojure-test-eval (format "(clojure.core/load-file \"%s\")"
- (expand-file-name (buffer-file-name)))
- (lambda (&rest args)
- (clojure-test-eval "(binding [clojure.test/report
- clojure.test.mode/report]
- (clojure.test/run-tests))"
- #'clojure-test-get-results)))))))
+ (lambda (buffer value)
+ (message "cleared tests. buffer: %s, value: %s" buffer value)
+ (with-current-buffer buffer
+ (nrepl-load-current-buffer)
+ (clojure-test-eval "(binding [clojure.test/report clojure.test.mode/report]
+ (clojure.test/run-tests))"
+ #'clojure-test-get-results))
+ ))
+ ))
+
(defun clojure-test-run-test ()
"Run the test at point."
(interactive)
@@ -407,7 +418,7 @@ Retuns the problem overlay if such a position is found, otherwise nil."
(problem (clojure-test-find-next-problem here)))
(if problem
(goto-char problem)
- (goto-char here)
+ n (goto-char here)
(message "No next problem."))))
(defun clojure-test-previous-problem ()
@@ -445,11 +456,10 @@ Retuns the problem overlay if such a position is found, otherwise nil."
(define-minor-mode clojure-test-mode
"A minor mode for running Clojure tests."
nil " Test" clojure-test-mode-map
- (when (or (get-buffer "*nrepl-connection*") (slime-connected-p))
+ (when (clojure-test-nrepl-connected-p)
(clojure-test-load-reporting)))
(add-hook 'nrepl-connected-hook 'clojure-test-load-reporting)
-(add-hook 'slime-connected-hook 'clojure-test-load-reporting)
;;;###autoload
(progn
Please sign in to comment.
Something went wrong with that request. Please try again.