aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Porter2023-11-10 17:53:02 -0800
committerJim Porter2023-11-10 18:00:21 -0800
commitf2b162f8ee5d93dafd87be34acef746e67d9ab26 (patch)
treee8c6bbef7dd3e3ef1251dff376fbb0050d8c2ab7
parent8b3969006fe6095178eea38df096d73bdd460a15 (diff)
downloademacs-f2b162f8ee5d93dafd87be34acef746e67d9ab26.tar.gz
emacs-f2b162f8ee5d93dafd87be34acef746e67d9ab26.zip
Add some more Eshell history tests
* test/lisp/eshell/em-hist-tests.el (em-hist-test/check-history-file): New function. Use it throughout this file. (em-hist-test/history-append): Rename to... (em-hist-test/write-history/append): ... this. (em-hist-test/history-read): Rename to... (em-hist-test/write-history/overwrite): ... this. (em-hist-test/write-history/append-multiple-eshells) (em-hist-test/write-history/overwrite-multiple-shells): New tests. (em-hist-test/write-history/read-only): Check the resulting history.
-rw-r--r--test/lisp/eshell/em-hist-tests.el127
1 files changed, 91 insertions, 36 deletions
diff --git a/test/lisp/eshell/em-hist-tests.el b/test/lisp/eshell/em-hist-tests.el
index 4851bdc50b2..e90ce141a81 100644
--- a/test/lisp/eshell/em-hist-tests.el
+++ b/test/lisp/eshell/em-hist-tests.el
@@ -19,6 +19,9 @@
19 19
20;;; Code: 20;;; Code:
21 21
22(eval-when-compile
23 (require 'cl-lib))
24
22(require 'ert) 25(require 'ert)
23(require 'ert-x) 26(require 'ert-x)
24(require 'em-hist) 27(require 'em-hist)
@@ -29,9 +32,94 @@
29 (file-name-directory (or load-file-name 32 (file-name-directory (or load-file-name
30 default-directory)))) 33 default-directory))))
31 34
35(cl-defun em-hist-test/check-history-file (file-name expected &optional
36 (expected-ring t))
37 "Check that the contents of FILE-NAME match the EXPECTED history entries.
38Additonally, check that after loading the file, the history ring
39matches too. If EXPECTED-RING is a list, compare the ring
40elements against that; if t (the default), check again EXPECTED."
41 (when (eq expected-ring t) (setq expected-ring expected))
42 ;; First check the actual file.
43 (should (equal (with-temp-buffer
44 (insert-file-contents file-name)
45 (buffer-string))
46 (mapconcat (lambda (i) (concat i "\n")) expected)))
47 ;; Now read the history ring and check that too.
48 (let (eshell-history-ring eshell-history-index eshell-hist--new-items)
49 (eshell-read-history file-name)
50 (should (equal (nreverse (ring-elements eshell-history-ring))
51 expected-ring))))
52
32;;; Tests: 53;;; Tests:
33 54
34(ert-deftest em-hist-test/write-readonly-history () 55(ert-deftest em-hist-test/write-history/append ()
56 "Test appending new history to history file."
57 (ert-with-temp-file histfile
58 (with-temp-eshell
59 (em-hist-test/check-history-file histfile nil)
60 (eshell-insert-command "echo hi")
61 (eshell-write-history histfile 'append)
62 (em-hist-test/check-history-file histfile '("echo hi"))
63 (eshell-insert-command "echo bye")
64 (eshell-write-history histfile 'append)
65 (em-hist-test/check-history-file histfile '("echo hi" "echo bye")))))
66
67(ert-deftest em-hist-test/write-history/append-multiple-eshells ()
68 "Test appending new history to history file from multiple Eshells."
69 (ert-with-temp-file histfile
70 (with-temp-eshell
71 (with-temp-eshell
72 ;; Enter some commands and save them.
73 (eshell-insert-command "echo foo")
74 (eshell-insert-command "echo bar")
75 (eshell-write-history histfile 'append)
76 (em-hist-test/check-history-file histfile '("echo foo" "echo bar")))
77 ;; Now do the same in the first Eshell buffer.
78 (eshell-insert-command "echo goat")
79 (eshell-insert-command "echo panda")
80 (eshell-write-history histfile 'append)
81 (em-hist-test/check-history-file
82 histfile '("echo foo" "echo bar" "echo goat" "echo panda")))))
83
84(ert-deftest em-hist-test/write-history/overwrite ()
85 "Test overwriting history file."
86 (ert-with-temp-file histfile
87 (with-temp-eshell
88 (em-hist-test/check-history-file histfile nil)
89 (eshell-insert-command "echo hi")
90 (eshell-insert-command "echo bye")
91 (eshell-insert-command "echo bye")
92 (eshell-insert-command "echo hi")
93 (eshell-write-history histfile)
94 (em-hist-test/check-history-file
95 histfile '("echo hi" "echo bye" "echo bye" "echo hi"))
96 (let ((eshell-hist-ignoredups t))
97 (em-hist-test/check-history-file
98 histfile '("echo hi" "echo bye" "echo bye" "echo hi")
99 '("echo hi" "echo bye" "echo hi")))
100 (let ((eshell-hist-ignoredups 'erase))
101 (em-hist-test/check-history-file
102 histfile '("echo hi" "echo bye" "echo bye" "echo hi")
103 '("echo bye" "echo hi"))))))
104
105(ert-deftest em-hist-test/write-history/overwrite-multiple-shells ()
106 "Test overwriting history file from multiple Eshells."
107 (ert-with-temp-file histfile
108 (with-temp-eshell
109 (with-temp-eshell
110 ;; Enter some commands and save them.
111 (eshell-insert-command "echo foo")
112 (eshell-insert-command "echo bar")
113 (eshell-write-history histfile)
114 (em-hist-test/check-history-file histfile '("echo foo" "echo bar")))
115 ;; Now do the same in the first Eshell buffer.
116 (eshell-insert-command "echo goat")
117 (eshell-insert-command "echo panda")
118 (eshell-write-history histfile)
119 (em-hist-test/check-history-file
120 histfile '("echo goat" "echo panda")))))
121
122(ert-deftest em-hist-test/write-history/read-only ()
35 "Test that having read-only strings in history is okay." 123 "Test that having read-only strings in history is okay."
36 (ert-with-temp-file histfile 124 (ert-with-temp-file histfile
37 (let ((eshell-history-ring (make-ring 2))) 125 (let ((eshell-history-ring (make-ring 2)))
@@ -39,41 +127,8 @@
39 (propertize "echo foo" 'read-only t)) 127 (propertize "echo foo" 'read-only t))
40 (ring-insert eshell-history-ring 128 (ring-insert eshell-history-ring
41 (propertize "echo bar" 'read-only t)) 129 (propertize "echo bar" 'read-only t))
42 (eshell-write-history histfile)))) 130 (eshell-write-history histfile)
43 131 (em-hist-test/check-history-file histfile '("echo foo" "echo bar")))))
44(ert-deftest em-hist-test/history-append ()
45 "Test 'history -a'."
46 (ert-with-temp-file histfile
47 (with-temp-eshell
48 (let ((eshell-history-file-name histfile))
49 (eshell-insert-command "echo hi")
50 (eshell-insert-command "history -w")
51 (eshell-insert-command "history -a")
52 (eshell-insert-command "echo bye")
53 (eshell-insert-command "history -a")
54 (eshell-insert-command "history -r")
55 (should (equal (ring-elements eshell-history-ring)
56 '("history -a" "echo bye"
57 "history -a" "history -w" "echo hi")))))))
58
59(ert-deftest em-hist-test/history-read ()
60 "Test 'history -r'."
61 (ert-with-temp-file histfile
62 (with-temp-eshell
63 (let ((eshell-history-file-name histfile))
64 (eshell-insert-command "echo hi")
65 (eshell-insert-command "echo bye")
66 (eshell-insert-command "echo bye")
67 (eshell-insert-command "echo hi")
68 (eshell-insert-command "history -w")
69 (let ((eshell-hist-ignoredups t))
70 (eshell-insert-command "history -r")
71 (should (equal (ring-elements eshell-history-ring)
72 '("history -w" "echo hi" "echo bye" "echo hi"))))
73 (let ((eshell-hist-ignoredups 'erase))
74 (eshell-insert-command "history -r")
75 (should (equal (ring-elements eshell-history-ring)
76 '("history -w" "echo hi" "echo bye"))))))))
77 132
78(ert-deftest em-hist-test/add-to-history/allow-dups () 133(ert-deftest em-hist-test/add-to-history/allow-dups ()
79 "Test adding to history, allowing dups." 134 "Test adding to history, allowing dups."