aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNoam Postavsky2017-04-23 22:21:42 -0400
committerNoam Postavsky2017-05-19 18:16:15 -0400
commit267be4bdc28564a99f45da29e84eb98838117b50 (patch)
tree3816b74e945cb1a17a1f4c8ad5e25e4abb0e8206 /test
parentc1c8b67246c4314b302cca2ac43f13a0baba4c16 (diff)
downloademacs-267be4bdc28564a99f45da29e84eb98838117b50.tar.gz
emacs-267be4bdc28564a99f45da29e84eb98838117b50.zip
Refactor lisp eval result printing
* lisp/simple.el (eval-expression-print-format): Don't check `standard-output' or `current-prefix-arg'. (eval-expression-get-print-arguments): New function, centralizes decision about how to print results of `eval-expression' and `eval-last-sexp'. (eval-expression): * lisp/progmodes/elisp-mode.el (elisp--eval-last-sexp-print-value): Use it.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/progmodes/elisp-mode-tests.el18
-rw-r--r--test/lisp/simple-tests.el42
2 files changed, 50 insertions, 10 deletions
diff --git a/test/lisp/progmodes/elisp-mode-tests.el b/test/lisp/progmodes/elisp-mode-tests.el
index 93c428b2d2b..5edb590b1e5 100644
--- a/test/lisp/progmodes/elisp-mode-tests.el
+++ b/test/lisp/progmodes/elisp-mode-tests.el
@@ -114,6 +114,24 @@
114 (should (member "backup-buffer" comps)) 114 (should (member "backup-buffer" comps))
115 (should-not (member "backup-inhibited" comps))))) 115 (should-not (member "backup-inhibited" comps)))))
116 116
117;;; eval-last-sexp
118
119(ert-deftest eval-last-sexp-print-format-sym ()
120 (with-temp-buffer
121 (let ((current-prefix-arg '(4)))
122 (erase-buffer) (insert "t")
123 (call-interactively #'eval-last-sexp)
124 (should (equal (buffer-string) "tt")))))
125
126(ert-deftest eval-last-sexp-print-format-sym-echo ()
127 ;; We can only check the echo area when running interactive.
128 (skip-unless (not noninteractive))
129 (with-temp-buffer
130 (let ((current-prefix-arg nil))
131 (erase-buffer) (insert "t") (message nil)
132 (call-interactively #'eval-last-sexp)
133 (should (equal (current-message) "t")))))
134
117;;; xref 135;;; xref
118 136
119(defun xref-elisp-test-descr-to-target (xref) 137(defun xref-elisp-test-descr-to-target (xref)
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index f4849c4b21d..b74e28ccaf1 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -20,6 +20,7 @@
20;;; Code: 20;;; Code:
21 21
22(require 'ert) 22(require 'ert)
23(eval-when-compile (require 'cl-lib))
23 24
24(defmacro simple-test--dummy-buffer (&rest body) 25(defmacro simple-test--dummy-buffer (&rest body)
25 (declare (indent 0) 26 (declare (indent 0)
@@ -35,6 +36,8 @@
35 (buffer-substring (point) (point-max)))))) 36 (buffer-substring (point) (point-max))))))
36 37
37 38
39
40;;; `transpose-sexps'
38(defmacro simple-test--transpositions (&rest body) 41(defmacro simple-test--transpositions (&rest body)
39 (declare (indent 0) 42 (declare (indent 0)
40 (debug t)) 43 (debug t))
@@ -46,6 +49,13 @@
46 (cons (buffer-substring (point-min) (point)) 49 (cons (buffer-substring (point-min) (point))
47 (buffer-substring (point) (point-max))))) 50 (buffer-substring (point) (point-max)))))
48 51
52;;; Transposition with negative args (bug#20698, bug#21885)
53(ert-deftest simple-transpose-subr ()
54 (should (equal (simple-test--transpositions (transpose-sexps -1))
55 '("(s1) (s2) (s4)" . " (s3) (s5)")))
56 (should (equal (simple-test--transpositions (transpose-sexps -2))
57 '("(s1) (s4)" . " (s2) (s3) (s5)"))))
58
49 59
50;;; `newline' 60;;; `newline'
51(ert-deftest newline () 61(ert-deftest newline ()
@@ -239,8 +249,8 @@
239 (should (equal ?\s (char-syntax ?\f))) 249 (should (equal ?\s (char-syntax ?\f)))
240 (should (equal ?\s (char-syntax ?\n)))))) 250 (should (equal ?\s (char-syntax ?\n))))))
241 251
242 252
243;;; auto-boundary tests 253;;; undo auto-boundary tests
244(ert-deftest undo-auto-boundary-timer () 254(ert-deftest undo-auto-boundary-timer ()
245 (should 255 (should
246 undo-auto-current-boundary-timer)) 256 undo-auto-current-boundary-timer))
@@ -269,14 +279,6 @@
269 (insert "hello") 279 (insert "hello")
270 (undo-auto--boundaries 'test)))) 280 (undo-auto--boundaries 'test))))
271 281
272;;; Transposition with negative args (bug#20698, bug#21885)
273(ert-deftest simple-transpose-subr ()
274 (should (equal (simple-test--transpositions (transpose-sexps -1))
275 '("(s1) (s2) (s4)" . " (s3) (s5)")))
276 (should (equal (simple-test--transpositions (transpose-sexps -2))
277 '("(s1) (s4)" . " (s2) (s3) (s5)"))))
278
279
280;; Test for a regression introduced by undo-auto--boundaries changes. 282;; Test for a regression introduced by undo-auto--boundaries changes.
281;; https://lists.gnu.org/archive/html/emacs-devel/2015-11/msg01652.html 283;; https://lists.gnu.org/archive/html/emacs-devel/2015-11/msg01652.html
282(defun undo-test-kill-c-a-then-undo () 284(defun undo-test-kill-c-a-then-undo ()
@@ -374,5 +376,25 @@ See Bug#21722."
374 (undo) 376 (undo)
375 (point))))) 377 (point)))))
376 378
379
380;;; `eval-expression'
381
382(ert-deftest eval-expression-print-format-sym ()
383 (with-temp-buffer
384 (cl-letf (((symbol-function 'read--expression) (lambda (&rest _) t)))
385 (let ((current-prefix-arg '(4)))
386 (call-interactively #'eval-expression)
387 (should (equal (buffer-string) "t"))))))
388
389(ert-deftest eval-expression-print-format-sym-echo ()
390 ;; We can only check the echo area when running interactive.
391 (skip-unless (not noninteractive))
392 (with-temp-buffer
393 (cl-letf (((symbol-function 'read--expression) (lambda (&rest _) t)))
394 (let ((current-prefix-arg nil))
395 (message nil)
396 (call-interactively #'eval-expression)
397 (should (equal (current-message) "t"))))))
398
377(provide 'simple-test) 399(provide 'simple-test)
378;;; simple-test.el ends here 400;;; simple-test.el ends here