aboutsummaryrefslogtreecommitdiffstats
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
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)
-rw-r--r--etc/ERC-NEWS11
-rw-r--r--lisp/erc/erc-log.el17
-rw-r--r--lisp/erc/erc-stamp.el16
-rw-r--r--lisp/erc/erc-truncate.el21
-rw-r--r--lisp/erc/erc.el9
-rw-r--r--test/lisp/erc/erc-scenarios-log.el207
6 files changed, 264 insertions, 17 deletions
diff --git a/etc/ERC-NEWS b/etc/ERC-NEWS
index c7d157eacfb..e9ec9e2caab 100644
--- a/etc/ERC-NEWS
+++ b/etc/ERC-NEWS
@@ -131,6 +131,17 @@ been restored with a slightly revised role contingent on a few
131assumptions explained in its doc string. For clarity, it has been 131assumptions explained in its doc string. For clarity, it has been
132renamed 'erc-ensure-target-buffer-on-privmsg'. 132renamed 'erc-ensure-target-buffer-on-privmsg'.
133 133
134** Improved interplay between buffer truncation and message logging.
135While most of these improvements are subtle, some affect everyday use.
136For example, users of the 'truncate' module may notice that truncation
137now happens between messages rather than arbitrary lines. And those
138with the default 'erc-insert-timestamp-left-and-right' for their
139'erc-insert-timestamp-function' will see date stamps reprinted after
140every "/CLEAR" but omitted from any logs. One notable casualty of
141these changes has been the deprecation of the ancient option
142'erc-truncate-buffer-on-save'. Users of the 'log' module can achieve
143the same effect by issuing a "/CLEAR" at the prompt.
144
134** Miscellaneous UX changes. 145** Miscellaneous UX changes.
135Some minor quality-of-life niceties have finally made their way to 146Some minor quality-of-life niceties have finally made their way to
136ERC. For example, the function 'erc-echo-timestamp' is now 147ERC. For example, the function 'erc-echo-timestamp' is now
diff --git a/lisp/erc/erc-log.el b/lisp/erc/erc-log.el
index 2b58a7c56ed..d3106da4017 100644
--- a/lisp/erc/erc-log.el
+++ b/lisp/erc/erc-log.el
@@ -124,6 +124,7 @@ custom function which returns the directory part and set
124(defcustom erc-truncate-buffer-on-save nil 124(defcustom erc-truncate-buffer-on-save nil
125 "Erase the contents of any ERC (channel, query, server) buffer when it is saved." 125 "Erase the contents of any ERC (channel, query, server) buffer when it is saved."
126 :type 'boolean) 126 :type 'boolean)
127(make-obsolete 'erc-truncate-buffer-on-save 'erc-cmd-CLEAR "30.1")
127 128
128(defcustom erc-enable-logging t 129(defcustom erc-enable-logging t
129 "If non-nil, ERC will log IRC conversations. 130 "If non-nil, ERC will log IRC conversations.
@@ -230,6 +231,7 @@ also be a predicate function. To only log when you are not set away, use:
230 (add-hook 'erc-part-hook #'erc-conditional-save-buffer) 231 (add-hook 'erc-part-hook #'erc-conditional-save-buffer)
231 ;; append, so that 'erc-initialize-log-marker runs first 232 ;; append, so that 'erc-initialize-log-marker runs first
232 (add-hook 'erc-connect-pre-hook #'erc-log-setup-logging 'append) 233 (add-hook 'erc-connect-pre-hook #'erc-log-setup-logging 'append)
234 (add-hook 'erc--pre-clear-functions #'erc-save-buffer-in-logs)
233 (dolist (buffer (erc-buffer-list)) 235 (dolist (buffer (erc-buffer-list))
234 (erc-log-setup-logging buffer)) 236 (erc-log-setup-logging buffer))
235 (erc--modify-local-map t "C-c C-l" #'erc-save-buffer-in-logs)) 237 (erc--modify-local-map t "C-c C-l" #'erc-save-buffer-in-logs))
@@ -242,6 +244,7 @@ also be a predicate function. To only log when you are not set away, use:
242 (remove-hook 'erc-quit-hook #'erc-conditional-save-queries) 244 (remove-hook 'erc-quit-hook #'erc-conditional-save-queries)
243 (remove-hook 'erc-part-hook #'erc-conditional-save-buffer) 245 (remove-hook 'erc-part-hook #'erc-conditional-save-buffer)
244 (remove-hook 'erc-connect-pre-hook #'erc-log-setup-logging) 246 (remove-hook 'erc-connect-pre-hook #'erc-log-setup-logging)
247 (remove-hook 'erc--pre-clear-functions #'erc-save-buffer-in-logs)
245 (dolist (buffer (erc-buffer-list)) 248 (dolist (buffer (erc-buffer-list))
246 (erc-log-disable-logging buffer)) 249 (erc-log-disable-logging buffer))
247 (erc--modify-local-map nil "C-c C-l" #'erc-save-buffer-in-logs))) 250 (erc--modify-local-map nil "C-c C-l" #'erc-save-buffer-in-logs)))
@@ -301,6 +304,8 @@ Returns nil if `erc-server-buffer-p' returns t."
301 (dolist (buffer (erc-buffer-list)) 304 (dolist (buffer (erc-buffer-list))
302 (erc-save-buffer-in-logs buffer))) 305 (erc-save-buffer-in-logs buffer)))
303 306
307(defvar erc-log--save-in-progress-p nil)
308
304;;;###autoload 309;;;###autoload
305(defun erc-logging-enabled (&optional buffer) 310(defun erc-logging-enabled (&optional buffer)
306 "Return non-nil if logging is enabled for BUFFER. 311 "Return non-nil if logging is enabled for BUFFER.
@@ -310,6 +315,7 @@ is writable (it will be created as necessary) and
310`erc-enable-logging' returns a non-nil value." 315`erc-enable-logging' returns a non-nil value."
311 (or buffer (setq buffer (current-buffer))) 316 (or buffer (setq buffer (current-buffer)))
312 (and erc-log-channels-directory 317 (and erc-log-channels-directory
318 (not erc-log--save-in-progress-p)
313 (or (functionp erc-log-channels-directory) 319 (or (functionp erc-log-channels-directory)
314 (erc-directory-writable-p erc-log-channels-directory)) 320 (erc-directory-writable-p erc-log-channels-directory))
315 (if (functionp erc-enable-logging) 321 (if (functionp erc-enable-logging)
@@ -399,7 +405,7 @@ automatically.
399You can save every individual message by putting this function on 405You can save every individual message by putting this function on
400`erc-insert-post-hook'." 406`erc-insert-post-hook'."
401 (interactive) 407 (interactive)
402 (or buffer (setq buffer (current-buffer))) 408 (unless (bufferp buffer) (setq buffer (current-buffer)))
403 (when (erc-logging-enabled buffer) 409 (when (erc-logging-enabled buffer)
404 (let ((file (erc-current-logfile buffer)) 410 (let ((file (erc-current-logfile buffer))
405 (coding-system erc-log-file-coding-system)) 411 (coding-system erc-log-file-coding-system))
@@ -423,10 +429,11 @@ You can save every individual message by putting this function on
423 (write-region start end file t 'nomessage)))) 429 (write-region start end file t 'nomessage))))
424 (if (and erc-truncate-buffer-on-save 430 (if (and erc-truncate-buffer-on-save
425 (called-interactively-p 'interactive)) 431 (called-interactively-p 'interactive))
426 (progn 432 (let ((erc-log--save-in-progress-p t))
427 (let ((inhibit-read-only t)) (erase-buffer)) 433 (erc-cmd-CLEAR)
428 (move-marker erc-last-saved-position (point-max)) 434 (erc-button--display-error-notice-with-keys
429 (erc-display-prompt)) 435 (erc-server-buffer) "Option `%s' is deprecated."
436 " Use /CLEAR instead." 'erc-truncate-buffer-on-save))
430 (move-marker erc-last-saved-position 437 (move-marker erc-last-saved-position
431 ;; If we place erc-last-saved-position at 438 ;; If we place erc-last-saved-position at
432 ;; erc-insert-marker, because text gets 439 ;; erc-insert-marker, because text gets
diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el
index 9191bbe5a2a..500f6f3c0c9 100644
--- a/lisp/erc/erc-stamp.el
+++ b/lisp/erc/erc-stamp.el
@@ -166,12 +166,14 @@ from entering them and instead jump over them."
166 (add-hook 'erc-insert-modify-hook #'erc-add-timestamp t) 166 (add-hook 'erc-insert-modify-hook #'erc-add-timestamp t)
167 (add-hook 'erc-send-modify-hook #'erc-add-timestamp t) 167 (add-hook 'erc-send-modify-hook #'erc-add-timestamp t)
168 (add-hook 'erc-mode-hook #'erc-stamp--recover-on-reconnect) 168 (add-hook 'erc-mode-hook #'erc-stamp--recover-on-reconnect)
169 (add-hook 'erc--pre-clear-functions #'erc-stamp--reset-on-clear)
169 (unless erc--updating-modules-p 170 (unless erc--updating-modules-p
170 (erc-buffer-filter #'erc-munge-invisibility-spec))) 171 (erc-buffer-filter #'erc-munge-invisibility-spec)))
171 ((remove-hook 'erc-mode-hook #'erc-munge-invisibility-spec) 172 ((remove-hook 'erc-mode-hook #'erc-munge-invisibility-spec)
172 (remove-hook 'erc-insert-modify-hook #'erc-add-timestamp) 173 (remove-hook 'erc-insert-modify-hook #'erc-add-timestamp)
173 (remove-hook 'erc-send-modify-hook #'erc-add-timestamp) 174 (remove-hook 'erc-send-modify-hook #'erc-add-timestamp)
174 (remove-hook 'erc-mode-hook #'erc-stamp--recover-on-reconnect) 175 (remove-hook 'erc-mode-hook #'erc-stamp--recover-on-reconnect)
176 (remove-hook 'erc--pre-clear-functions #'erc-stamp--reset-on-clear)
175 (erc-with-all-buffers-of-server nil nil 177 (erc-with-all-buffers-of-server nil nil
176 (kill-local-variable 'erc-timestamp-last-inserted) 178 (kill-local-variable 'erc-timestamp-last-inserted)
177 (kill-local-variable 'erc-timestamp-last-inserted-left) 179 (kill-local-variable 'erc-timestamp-last-inserted-left)
@@ -584,6 +586,20 @@ enabled when the message was inserted."
584(defun erc--echo-ts-csf (_window _before dir) 586(defun erc--echo-ts-csf (_window _before dir)
585 (erc-echo-timestamp dir (get-text-property (point) 'erc-timestamp))) 587 (erc-echo-timestamp dir (get-text-property (point) 'erc-timestamp)))
586 588
589(defun erc-stamp--update-saved-position (&rest _)
590 (remove-function (local 'erc-stamp--insert-date-function)
591 #'erc-stamp--update-saved-position)
592 (move-marker erc-last-saved-position (1- (point))))
593
594(defun erc-stamp--reset-on-clear (pos)
595 "Forget last-inserted stamps when POS is at insert marker."
596 (when (= pos (1- erc-insert-marker))
597 (add-function :after (local 'erc-stamp--insert-date-function)
598 #'erc-stamp--update-saved-position)
599 (setq erc-timestamp-last-inserted nil
600 erc-timestamp-last-inserted-left nil
601 erc-timestamp-last-inserted-right nil)))
602
587(provide 'erc-stamp) 603(provide 'erc-stamp)
588 604
589;;; erc-stamp.el ends here 605;;; erc-stamp.el ends here
diff --git a/lisp/erc/erc-truncate.el b/lisp/erc/erc-truncate.el
index b8fd4ae2e14..8430a68d92b 100644
--- a/lisp/erc/erc-truncate.el
+++ b/lisp/erc/erc-truncate.el
@@ -50,9 +50,9 @@ This prevents the query buffer from getting too large, which can
50bring any grown Emacs to its knees after a few days worth of 50bring any grown Emacs to its knees after a few days worth of
51tracking heavy-traffic channels." 51tracking heavy-traffic channels."
52 ;;enable 52 ;;enable
53 ((add-hook 'erc-insert-post-hook #'erc-truncate-buffer)) 53 ((add-hook 'erc-insert-done-hook #'erc-truncate-buffer))
54 ;; disable 54 ;; disable
55 ((remove-hook 'erc-insert-post-hook #'erc-truncate-buffer))) 55 ((remove-hook 'erc-insert-done-hook #'erc-truncate-buffer)))
56 56
57;;;###autoload 57;;;###autoload
58(defun erc-truncate-buffer-to-size (size &optional buffer) 58(defun erc-truncate-buffer-to-size (size &optional buffer)
@@ -75,9 +75,11 @@ region is logged if `erc-logging-enabled' returns non-nil."
75 (save-restriction 75 (save-restriction
76 (widen) 76 (widen)
77 (let ((end (- erc-insert-marker size))) 77 (let ((end (- erc-insert-marker size)))
78 ;; truncate at line boundaries 78 ;; Truncate at message boundary (formerly line boundary
79 ;; before 5.6).
79 (goto-char end) 80 (goto-char end)
80 (beginning-of-line) 81 (goto-char (or (previous-single-property-change (point) 'erc-command)
82 (pos-bol)))
81 (setq end (point)) 83 (setq end (point))
82 ;; try to save the current buffer using 84 ;; try to save the current buffer using
83 ;; `erc-save-buffer-in-logs'. We use this, in case the 85 ;; `erc-save-buffer-in-logs'. We use this, in case the
@@ -91,10 +93,7 @@ region is logged if `erc-logging-enabled' returns non-nil."
91 ;; (not (memq 'erc-save-buffer-in-logs 93 ;; (not (memq 'erc-save-buffer-in-logs
92 ;; erc-insert-post-hook)) 94 ;; erc-insert-post-hook))
93 ;; Comments? 95 ;; Comments?
94 (when (and (boundp 'erc-enable-logging) 96 (run-hook-with-args 'erc--pre-clear-functions end)
95 erc-enable-logging
96 (erc-logging-enabled buffer))
97 (erc-save-buffer-in-logs))
98 ;; disable undoing for the truncating 97 ;; disable undoing for the truncating
99 (buffer-disable-undo) 98 (buffer-disable-undo)
100 (let ((inhibit-read-only t)) 99 (let ((inhibit-read-only t))
@@ -103,10 +102,10 @@ region is logged if `erc-logging-enabled' returns non-nil."
103 102
104;;;###autoload 103;;;###autoload
105(defun erc-truncate-buffer () 104(defun erc-truncate-buffer ()
106 "Truncates the current buffer to `erc-max-buffer-size'. 105 "Truncate current buffer to `erc-max-buffer-size'."
107Meant to be used in hooks, like `erc-insert-post-hook'."
108 (interactive) 106 (interactive)
109 (erc-truncate-buffer-to-size erc-max-buffer-size)) 107 (save-excursion
108 (erc-truncate-buffer-to-size erc-max-buffer-size)))
110 109
111(provide 'erc-truncate) 110(provide 'erc-truncate)
112;;; erc-truncate.el ends here 111;;; erc-truncate.el ends here
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 9c1125a9351..5a91285c1d1 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -3436,10 +3436,17 @@ If no USER argument is specified, list the contents of `erc-ignore-list'."
3436 (erc-with-server-buffer 3436 (erc-with-server-buffer
3437 (setq erc-ignore-list (delete user erc-ignore-list)))))) 3437 (setq erc-ignore-list (delete user erc-ignore-list))))))
3438 3438
3439(defvar erc--pre-clear-functions nil
3440 "Abnormal hook run when truncating buffers.
3441Called with position indicating boundary of interval to be excised.")
3442
3439(defun erc-cmd-CLEAR () 3443(defun erc-cmd-CLEAR ()
3440 "Clear the window content." 3444 "Clear the window content."
3441 (let ((inhibit-read-only t)) 3445 (let ((inhibit-read-only t))
3442 (delete-region (point-min) (line-beginning-position))) 3446 (run-hook-with-args 'erc--pre-clear-functions (1- erc-insert-marker))
3447 ;; Ostensibly, `line-beginning-position' is for use in lisp code.
3448 (delete-region (point-min) (min (line-beginning-position)
3449 (1- erc-insert-marker))))
3443 t) 3450 t)
3444(put 'erc-cmd-CLEAR 'process-not-needed t) 3451(put 'erc-cmd-CLEAR 'process-not-needed t)
3445 3452
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