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

cider-test: don't render a newline between expected and actual #3375

Merged
merged 5 commits into from
Aug 4, 2023
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 @@ -26,6 +26,7 @@
- Bump the injected `cider-nrepl` to [0.34](https://github.com/clojure-emacs/cider-nrepl/blob/v0.34.0/CHANGELOG.md#0340-2023-08-03).
- Improve `nrepl-dict` error reporting.
- Preserve the `:cljs-repl-type` more reliably.
- [#3375](https://github.com/clojure-emacs/cider/pull/3375): `cider-test`: don't render a newline between expected and actual, most times.

## 1.7.0 (2023-03-23)

Expand Down
13 changes: 12 additions & 1 deletion cider-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ With the actual value, the outermost '(not ...)' s-expression is removed."
(cider-insert "t" 'font-lock-constant-face t))
(insert "\n\n"))))

(defun cider-test--string-contains-newline (input-string)
"Returns whether INPUT-STRING contains an escaped newline."
(when (stringp input-string)
(and (string-match-p "\\n" input-string)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this regexp really match?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escaped newlines as coming from Clojure / cider-nrepl. These aren't vanilla elisp newlines.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It matches the letter "n" in a string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! will fix

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

t)))

(defun cider-test-render-assertion (buffer test)
"Emit into BUFFER report detail for the TEST assertion."
(with-current-buffer buffer
Expand Down Expand Up @@ -427,12 +433,17 @@ With the actual value, the outermost '(not ...)' s-expression is removed."
(when expected
(insert-label "expected")
(insert-rect expected)
(insert "\n"))
;; Only place a newline between expected and actual when the values are deemed 'dense',
;; otherwise favor compact output:
(when (or (cider-test--string-contains-newline expected)
(cider-test--string-contains-newline actual))
(insert "\n")))
(if diffs
(dolist (d diffs)
(cl-destructuring-bind (actual (removed added)) d
(insert-label "actual")
(insert-rect actual)
(insert "\n")
(insert-label "diff")
(insert "- ")
(insert-rect removed)
Expand Down
37 changes: 37 additions & 0 deletions test/cider-test-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
;;; cider-test-tests.el -*- lexical-binding: t; -*-

;; Copyright © 2023 Bozhidar Batsov

;; Author: Bozhidar Batsov <[email protected]>

;; 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 'buttercup)
(require 'cider-test)

(describe "cider-test--string-contains-newline"
(expect (cider-test--string-contains-newline "Hello\nWorld")
:to-equal
nil)
(expect (cider-test--string-contains-newline "Hello\\nWorld")
:to-equal
t))
Loading