Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render diffs for expected / actual test results #2172

Merged
merged 1 commit into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* [#2172](https://github.com/clojure-emacs/cider/pull/2172): Render diffs for expected / actual test results.
* [#2167](https://github.com/clojure-emacs/cider/pull/2167): Add new defcustom `cider-jdk-src-paths`. Configure it to connect stack trace links to Java source code.
* [#2161](https://github.com/clojure-emacs/cider/issues/2161): Add new interactive command `cider-eval-defun-to-point` which is bound to `C-c C-v (C-)z`. It evaluates the current top-level form up to the point.
* [#2113](https://github.com/clojure-emacs/cider/issues/2113): Add new interactive commands `cider-eval-last-sexp-in-context` (bound to `C-c C-v (C-)c`) and `cider-eval-sexp-at-point-in-context` (bound to `C-c C-v (C-)b`).
Expand Down
75 changes: 48 additions & 27 deletions cider-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
(require 'cider-overlays)

(require 'button)
(require 'cl-lib)
(require 'easymenu)
(require 'seq)

Expand Down Expand Up @@ -375,33 +376,53 @@ With the actual value, the outermost '(not ...)' s-expression is removed."
(defun cider-test-render-assertion (buffer test)
"Emit into BUFFER report detail for the TEST assertion."
(with-current-buffer buffer
(nrepl-dbind-response test (var context type message expected actual error gen-input)
(cider-propertize-region (cider-intern-keys (cdr test))
(let ((beg (point))
(type-face (cider-test-type-simple-face type))
(bg `(:background ,cider-test-items-background-color)))
(cider-insert (capitalize type) type-face nil " in ")
(cider-insert var 'font-lock-function-name-face t)
(when context (cider-insert context 'font-lock-doc-face t))
(when message (cider-insert message 'font-lock-doc-string-face t))
(when expected
(cider-insert "expected: " 'font-lock-comment-face nil
(cider-font-lock-as-clojure expected)))
(when actual
(cider-insert " actual: " 'font-lock-comment-face nil
(cider-font-lock-as-clojure actual)))
(when error
(cider-insert " error: " 'font-lock-comment-face nil)
(insert-text-button error
'follow-link t
'action '(lambda (_button) (cider-test-stacktrace))
'help-echo "View causes and stacktrace")
(insert "\n"))
(when gen-input
(cider-insert " input: " 'font-lock-comment-face nil
(cider-font-lock-as-clojure gen-input)))
(overlay-put (make-overlay beg (point)) 'font-lock-face bg))
(insert "\n")))))
(nrepl-dbind-response test (var context type message expected actual diffs error gen-input)
(cl-flet ((insert-label (s)
(cider-insert (format "%8s: " s) 'font-lock-comment-face))
(insert-align-label (s)
(insert (format "%12s" s)))
(insert-rect (s)
(insert-rectangle (thread-first s
cider-font-lock-as-clojure
(split-string "\n")))
(beginning-of-line)))
(cider-propertize-region (cider-intern-keys (cdr test))
(let ((beg (point))
(type-face (cider-test-type-simple-face type))
(bg `(:background ,cider-test-items-background-color)))
(cider-insert (capitalize type) type-face nil " in ")
(cider-insert var 'font-lock-function-name-face t)
(when context (cider-insert context 'font-lock-doc-face t))
(when message (cider-insert message 'font-lock-doc-string-face t))
(when expected
(insert-label "expected")
(insert-rect expected)
(insert "\n"))
(if diffs
(dolist (d diffs)
(cl-destructuring-bind (actual (removed added)) d
(insert-label "actual")
(insert-rect actual)
(insert-label "diff")
(insert "- ")
(insert-rect removed)
(insert-align-label "+ ")
(insert-rect added)
(insert "\n")))
(insert-label "actual")
(insert-rect actual))
(when error
(insert-label "error")
(insert-text-button error
'follow-link t
'action '(lambda (_button) (cider-test-stacktrace))
'help-echo "View causes and stacktrace")
(insert "\n"))
(when gen-input
(insert-label "input")
(insert (cider-font-lock-as-clojure gen-input)))
(overlay-put (make-overlay beg (point)) 'font-lock-face bg))
(insert "\n"))))))

(defun cider-test-non-passing (tests)
"For a list of TESTS, each an nrepl-dict, return only those that did not pass."
Expand Down