aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNoam Postavsky2018-01-06 19:28:09 -0500
committerNoam Postavsky2018-01-18 22:17:40 -0500
commit1d50c185f0c857bb1a85945314b522540071f796 (patch)
tree0917acf47b9dc8a9d53750b17dd596316c10d56d /test
parent5472568a3c2338856d25380012ee4398e024c806 (diff)
downloademacs-1d50c185f0c857bb1a85945314b522540071f796.tar.gz
emacs-1d50c185f0c857bb1a85945314b522540071f796.zip
Add tests for term.el
* lisp/term.el (term-mode): Add `name' attribute to window-adjust-process-window-size-function value, so that it can be removed easily by tests. * test/lisp/term-tests.el: New tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/term-tests.el137
1 files changed, 137 insertions, 0 deletions
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el
new file mode 100644
index 00000000000..16466ea3cd4
--- /dev/null
+++ b/test/lisp/term-tests.el
@@ -0,0 +1,137 @@
1;;; term-tests.el --- tests for term.el -*- lexical-binding: t -*-
2
3;; Copyright (C) 2017 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Commentary:
21
22
23;;; Code:
24(require 'ert)
25(require 'term)
26(eval-when-compile (require 'cl-lib))
27
28(defvar term-height) ; Number of lines in window.
29(defvar term-width) ; Number of columns in window.
30
31(defun term-test-screen-from-input (width height input &optional return-var)
32 (with-temp-buffer
33 (term-mode)
34 ;; Keep dimensions independent from window size.
35 (remove-function (local 'window-adjust-process-window-size-function)
36 'term-maybe-reset-size)
37 (term-exec (current-buffer) "test" "cat" nil nil)
38 (term-char-mode)
39 (setq term-width width)
40 (setq term-height height)
41 ;; Pass input directly to `term-emulate-terminal', it's easier to
42 ;; control chunking, and we don't have to worry about wrestling
43 ;; with stty settings.
44 (let ((proc (get-buffer-process (current-buffer))))
45 (unwind-protect
46 (prog2 (if (consp input)
47 (mapc (lambda (input) (term-emulate-terminal proc input)) input)
48 (term-emulate-terminal proc input))
49 (if return-var (buffer-local-value return-var (current-buffer))
50 (buffer-substring-no-properties (point-min) (point-max)))
51 ;; End the process to avoid query on buffer kill.
52 (process-send-eof proc)
53 (accept-process-output proc))
54 ;; Make extra sure we don't get stuck in case we hit some
55 ;; error before sending eof.
56 (when (process-live-p proc)
57 (kill-process proc)
58 ;; Let Emacs update process status.
59 (accept-process-output proc))))))
60
61(ert-deftest term-simple-lines ()
62 (let ((str "\
63first line\r
64next line\r\n"))
65 (should (equal (term-test-screen-from-input 40 12 str)
66 (replace-regexp-in-string "\r" "" str)))))
67
68(ert-deftest term-carriage-return ()
69 (let ((str "\
70first line\r_next line\r\n"))
71 (should (equal (term-test-screen-from-input 40 12 str)
72 "_next line\n"))))
73
74(ert-deftest term-line-wrap ()
75 (should (string-match-p
76 ;; Don't be strict about trailing whitespace.
77 "\\`a\\{40\\}\na\\{20\\} *\\'"
78 (term-test-screen-from-input 40 12 (make-string 60 ?a))))
79 ;; Again, but split input into chunks.
80 (should (string-match-p
81 "\\`a\\{40\\}\na\\{20\\} *\\'"
82 (term-test-screen-from-input 40 12 (let ((str (make-string 30 ?a)))
83 (list str str))))))
84
85(ert-deftest term-cursor-movement ()
86 ;; Absolute positioning.
87 (should (equal "ab\ncd"
88 (term-test-screen-from-input
89 40 12 (concat "\e[2;2Hd"
90 "\e[2;1Hc"
91 "\e[1;2Hb"
92 "\e[1;1Ha"))))
93 ;; Send one byte at a time.
94 (should (equal "ab\ncd"
95 (term-test-screen-from-input
96 40 12 (split-string (concat "\e[2;2Hd"
97 "\e[2;1Hc"
98 "\e[1;2Hb"
99 "\e[1;1Ha") "" t))))
100 ;; Relative positioning.
101 (should (equal "ab\ncd"
102 (term-test-screen-from-input
103 40 12 (concat "\e[B\e[Cd"
104 "\e[D\e[Dc"
105 "\e[Ab"
106 "\e[D\e[Da")))))
107
108(ert-deftest term-scrolling-region ()
109 (should (equal "\
110line3
111line4
112line5
113line6
114"
115 (term-test-screen-from-input
116 40 12 "\e[1;5r\
117line1\r
118line2\r
119line3\r
120line4\r
121line5\r
122line6\r
123"))))
124
125(ert-deftest term-set-directory ()
126 (let ((term-ansi-at-user (user-real-login-name)))
127 (should (equal (term-test-screen-from-input
128 40 12 "\eAnSiTc /foo/\n" 'default-directory)
129 "/foo/"))
130 ;; Split input (Bug#17231).
131 (should (equal (term-test-screen-from-input
132 40 12 (list "\eAnSiTc /f" "oo/\n") 'default-directory)
133 "/foo/"))))
134
135(provide 'term-tests)
136
137;;; term-tests.el ends here