aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park2023-05-28 21:16:39 -0700
committerF. Jason Park2023-05-29 21:46:23 -0700
commit31a80f61ec03bcbb79720c0dc640272aba160865 (patch)
tree5695dfd273d872e84cee6cdcb2d570373fb08966 /test
parent4f93c52f7fd1b7c5f75a0d049e5a1015a268265a (diff)
downloademacs-31a80f61ec03bcbb79720c0dc640272aba160865.tar.gz
emacs-31a80f61ec03bcbb79720c0dc640272aba160865.zip
Preserve prompt in erc-cmd-CLEAR
* etc/ERC-NEWS: Mention behavioral changes to functionality provided by the `truncate' and `log' modules and also the "/CLEAR" command. * lisp/erc/erc-log.el (erc-truncate-buffer-on-save): Deprecate option because three's a crowd, and ERC already has a dedicated module as well as a slash command for this purpose. And although this commit restores functionality, this option has been unusable since at least the release of ERC 5.5, with no known complaints received thus far. Also, the doc string of `erc-save-buffer-in-logs' makes no mention of this feature WRT interactive invocations or otherwise. (erc-log-mode, erc-log-enable, erc-log-disable): Subscribe to new internal hook `erc--pre-clear-functions'. (erc-log--save-in-progress-p): New variable to help restore `erc-truncate-buffer-on-save' and promote code reuse. (erc-logging-enabled): Guard with `erc-log--saved-in-progress-p'. (erc-save-buffer-in-logs): Overload `buffer' parameter to allow various hooks to supply a non-buffer as well. Warn when people use `erc-truncate-buffer-on-save', which is now deprecated. * lisp/erc/erc-stamp.el (erc-stamp-mode, erc-stamp-enable, erc-stamp-disable): Subscribe to `erc--pre-clear-functions'. (erc-stamp--update-saved-position): New function for updating last-logged marker on `erc-stamp--insert-date-function'. (erc-stamp--reset-on-clear): New function to forget last inserted stamps when truncating. * lisp/erc/erc-truncate.el (erc-truncate-mode, erc-truncate-enable, erc-truncate-disable): Use `erc-insert-done-hook' instead of `erc-insert-post-hook', as implicitly suggested by an ancient comment, which ponders whether truncating the buffer at the insertion phase may be harmful to other hook members. (erc-truncate-buffer-to-size): Set truncation boundary at message break instead of line break. Run `erc--pre-clear-functions'. (erc-truncate-buffer): Save excursion. This should probably be handled by `erc-truncate-buffer-to-size' instead, but that's likelier to cause breakage in third-party code. * lisp/erc/erc.el (erc--pre-clear-functions): New internal hook. (erc-cmd-CLEAR): Run `erc--pre-clear-functions' before clearing, and don't blow away prompt. The latter was a regression caused by 05f6fdb9e78 "Preserve ERC prompt and its bounding markers". * test/lisp/erc/erc-scenarios-log.el: New file. (Bug#60936)
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-scenarios-log.el207
1 files changed, 207 insertions, 0 deletions
diff --git a/test/lisp/erc/erc-scenarios-log.el b/test/lisp/erc/erc-scenarios-log.el
new file mode 100644
index 00000000000..c37e6b323aa
--- /dev/null
+++ b/test/lisp/erc/erc-scenarios-log.el
@@ -0,0 +1,207 @@
1;;; erc-scenarios-log.el --- erc-log scenarios -*- lexical-binding: t -*-
2
3;; Copyright (C) 2023 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;;; Code:
23
24(require 'ert-x)
25(eval-and-compile
26 (let ((load-path (cons (ert-resource-directory) load-path)))
27 (require 'erc-scenarios-common)))
28
29(require 'erc-log)
30(require 'erc-truncate)
31
32(defvar erc-timestamp-format-left)
33
34(ert-deftest erc-scenarios-log--kill-hook ()
35 :tags '(:expensive-test)
36 (erc-scenarios-common-with-cleanup
37 ((erc-scenarios-common-dialog "base/assoc/bouncer-history")
38 (dumb-server (erc-d-run "localhost" t 'foonet))
39 (tempdir (make-temp-file "erc-tests-log." t nil nil))
40 (erc-log-channels-directory tempdir)
41 (erc-modules (cons 'log erc-modules))
42 (port (process-contact dumb-server :service))
43 (logfile (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port)
44 tempdir))
45 (erc-server-flood-penalty 0.1)
46 (expect (erc-d-t-make-expecter)))
47
48 (ert-info ("Connect to foonet")
49 (with-current-buffer (erc :server "127.0.0.1"
50 :port port
51 :nick "tester"
52 :password "foonet:changeme"
53 :full-name "tester")
54 (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
55 (funcall expect 5 "foonet")))
56
57 (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan"))
58 (funcall expect 10 "was created on")
59 (funcall expect 10 "please your lordship")
60 (with-current-buffer "foonet"
61 (delete-process erc-server-process)
62 (funcall expect 5 "failed"))
63 (should-not (file-exists-p logfile))
64 (kill-buffer)
65 (should (file-exists-p logfile)))
66
67 (with-temp-buffer
68 (insert-file-contents logfile)
69 (funcall expect 1 "You have joined")
70 (funcall expect 1 "Playback Complete.")
71 (funcall expect 1 "please your lordship"))
72
73 (erc-log-mode -1)
74 (if noninteractive
75 (delete-directory tempdir :recursive)
76 (add-hook 'kill-emacs-hook
77 (lambda () (delete-directory tempdir :recursive))))))
78
79;; This shows that, in addition to truncating the buffer, /clear also
80;; syncs the log.
81
82(ert-deftest erc-scenarios-log--clear-stamp ()
83 :tags '(:expensive-test)
84 (erc-scenarios-common-with-cleanup
85 ((erc-scenarios-common-dialog "base/assoc/bouncer-history")
86 (dumb-server (erc-d-run "localhost" t 'foonet))
87 (tempdir (make-temp-file "erc-tests-log." t nil nil))
88 (erc-log-channels-directory tempdir)
89 (erc-modules (cons 'log erc-modules))
90 (erc-timestamp-format-left "\n[%a %b %e %Y @@STAMP@@]\n")
91 (port (process-contact dumb-server :service))
92 (logfile (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port)
93 tempdir))
94 (erc-server-flood-penalty 0.1)
95 (expect (erc-d-t-make-expecter)))
96
97 (unless noninteractive
98 (add-hook 'kill-emacs-hook
99 (lambda () (delete-directory tempdir :recursive))))
100
101 (ert-info ("Connect to foonet")
102 (with-current-buffer (erc :server "127.0.0.1"
103 :port port
104 :nick "tester"
105 :password "foonet:changeme"
106 :full-name "tester")
107 (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
108 (funcall expect 5 "foonet")))
109
110 (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan"))
111 (funcall expect 10 "@@STAMP@@")
112 (funcall expect 10 "Grows, lives")
113 (should-not (file-exists-p logfile))
114 (goto-char (point-max))
115 (erc-cmd-CLEAR)
116 (should (file-exists-p logfile))
117 (funcall expect 10 "please your lordship")
118 (ert-info ("Buffer truncated")
119 (goto-char (point-min))
120 (funcall expect 10 "@@STAMP@@" (point)) ; reset
121 (funcall expect -0.1 "Grows, lives")
122 (funcall expect 1 "For these two")))
123
124 (ert-info ("Current contents saved")
125 (with-temp-buffer
126 (insert-file-contents logfile)
127 (funcall expect 1 "@@STAMP@@")
128 (funcall expect 1 "You have joined")
129 (funcall expect 1 "Playback Complete.")
130 (funcall expect 1 "Grows, lives")
131 (funcall expect -0.01 "please your lordship")))
132
133 (ert-info ("Remainder saved, timestamp printed when option non-nil")
134 (with-current-buffer "foonet"
135 (delete-process erc-server-process)
136 (funcall expect 5 "failed"))
137 (kill-buffer "#chan")
138 (with-temp-buffer
139 (insert-file-contents logfile)
140 (funcall expect 1 "@@STAMP@@")
141 (funcall expect 1 "Grows, lives")
142 (funcall expect -0.01 "@@STAMP@@")
143 (forward-line 1) ; no blank, no timestamp
144 (should (looking-at (rx "<bob> alice: For these two hours,")))
145 (funcall expect 1 "please your lordship")))
146
147 (erc-log-mode -1)
148 (when noninteractive (delete-directory tempdir :recursive))))
149
150(ert-deftest erc-scenarios-log--truncate ()
151 :tags '(:expensive-test)
152 (erc-scenarios-common-with-cleanup
153 ((erc-scenarios-common-dialog "base/assoc/bouncer-history")
154 (dumb-server (erc-d-run "localhost" t 'foonet))
155 (tempdir (make-temp-file "erc-tests-log." t nil nil))
156 (erc-log-channels-directory tempdir)
157 (erc-modules (cons 'truncate (cons 'log erc-modules)))
158 (erc-max-buffer-size 512)
159 (port (process-contact dumb-server :service))
160 (logchan (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port)
161 tempdir))
162 (logserv (expand-file-name
163 (format "127.0.0.1:%d!tester@127.0.0.1:%d.txt" port port)
164 tempdir))
165 (erc-server-flood-penalty 0.1)
166 (expect (erc-d-t-make-expecter)))
167
168 (unless noninteractive
169 (add-hook 'kill-emacs-hook
170 (lambda () (delete-directory tempdir :recursive))))
171
172 (ert-info ("Connect to foonet")
173 (with-current-buffer (erc :server "127.0.0.1"
174 :port port
175 :nick "tester"
176 :password "foonet:changeme"
177 :full-name "tester")
178 (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
179 (should-not (file-exists-p logserv))
180 (should-not (file-exists-p logchan))
181 (funcall expect 10 "*** MAXLIST=beI:60")
182 (should (= (pos-bol) (point-min)))
183 (should (file-exists-p logserv))))
184
185 (ert-info ("Log file ahead of truncation point")
186 ;; Log contains lines still present in buffer.
187 (with-temp-buffer
188 (insert-file-contents logserv)
189 (funcall expect 10 "*** MAXLIST=beI:60")))
190
191 (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan"))
192 (funcall expect 10 "please your lordship")
193 (should (file-exists-p logchan))
194 (funcall expect -0.1 "[07:04:37] alice: Here," (point-min)))
195
196 (ert-info ("Log ahead of truncation point")
197 (with-temp-buffer
198 (insert-file-contents logchan)
199 (funcall expect 1 "You have joined")
200 (funcall expect 1 "[07:04:37] alice: Here,")
201 (funcall expect 1 "loathed enemy")
202 (funcall expect -0.1 "please your lordship")))
203
204 (erc-log-mode -1)
205 (when noninteractive (delete-directory tempdir :recursive))))
206
207;;; erc-scenarios-log.el ends here