aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park2024-04-01 15:27:47 -0700
committerF. Jason Park2024-04-07 12:59:21 -0700
commite0df2841fb78251d5461a17e2d9be581c152bdc2 (patch)
treec69f5b6ad1b26189ba196bec9a4e18e1435a638b /test
parentc1266d355a2801271f2f875a1f7d47030c6c0e7a (diff)
downloademacs-e0df2841fb78251d5461a17e2d9be581c152bdc2.tar.gz
emacs-e0df2841fb78251d5461a17e2d9be581c152bdc2.zip
Allow updating of /IGNORE timeouts in ERC
* lisp/erc/erc.el (erc--read-time-period, erc--decode-time-period): Move body of former, now a superficial wrapper, to latter, a new function. (erc--format-time-period): New function. (erc--get-ignore-timer-args): New function. (erc--find-ignore-timer): New function to search through `timer-list' to find matching ignore timer. (erc-cmd-IGNORE): Refactor and redo doc string. Add new optional `timespec' parameter, primarily to aid in testing. Update an existing timer instead of always creating one, and display time remaining in "ignore list" output. Pass server buffer instead of current buffer to timer callbacks because `erc--unignore-user' displays its messages in the `active' buffer, not necessarily the issuing one. Note that doing this does discard potentially useful information, so if ever reverting, we can change the `cl-find' :test in `erc--find-ignore-timer' to something that compares the `erc-server-process' of both buffers. ;; ;; Something like: ;; ;; (defun erc--ignore-timers-equal-p (a b) ;; (and (equal (car a) (car b)) ;; (eq (buffer-local-value 'erc-server-process (cadr a)) ;; (buffer-local-value 'erc-server-process (cadr b))))) ;; (erc-cmd-UNIGNORE): Pass `erc-ignore-list' member matching `user' parameter to `erc--unignore-user' instead of original, raw parameter, along with the server buffer. (erc--unignore-user): Cancel existing timer and don't bother switching to server buffer since we're already there. (erc-message-english-ignore-list): New variable. * test/lisp/erc/erc-scenarios-ignore.el: New file. * test/lisp/erc/erc-tests.el (erc--read-time-period): New test. (erc-cmd-UNIGNORE): New test. (Bug#70127)
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-scenarios-ignore.el79
-rw-r--r--test/lisp/erc/erc-tests.el28
2 files changed, 107 insertions, 0 deletions
diff --git a/test/lisp/erc/erc-scenarios-ignore.el b/test/lisp/erc/erc-scenarios-ignore.el
new file mode 100644
index 00000000000..1142bbef14d
--- /dev/null
+++ b/test/lisp/erc/erc-scenarios-ignore.el
@@ -0,0 +1,79 @@
1;;; erc-scenarios-ignore.el --- /IGNORE scenarios ERC -*- lexical-binding: t -*-
2
3;; Copyright (C) 2024 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;; TODO add test covering the same ignored speaker in two different
23;; channels on the same server: they should be ignored in both.
24
25;;; Code:
26
27(require 'ert-x)
28(eval-and-compile
29 (let ((load-path (cons (ert-resource-directory) load-path)))
30 (require 'erc-scenarios-common)))
31
32(ert-deftest erc-scenarios-ignore/basic ()
33 :tags '(:expensive-test)
34 (erc-scenarios-common-with-cleanup
35 ((erc-scenarios-common-dialog "base/assoc/multi-net")
36 (erc-server-flood-penalty 0.1)
37 (dumb-server-foonet (erc-d-run "localhost" t 'foonet))
38 (dumb-server-barnet (erc-d-run "localhost" t 'barnet))
39 (erc-autojoin-channels-alist '((foonet "#chan") (barnet "#chan")))
40 (port-foonet (process-contact dumb-server-foonet :service))
41 (port-barnet (process-contact dumb-server-barnet :service))
42 (expect (erc-d-t-make-expecter)))
43
44 (ert-info ("Connect to two networks")
45 (with-current-buffer (erc :server "127.0.0.1"
46 :port port-barnet
47 :nick "tester"
48 :password "changeme"
49 :full-name "tester"))
50 (with-current-buffer (erc :server "127.0.0.1"
51 :port port-foonet
52 :nick "tester"
53 :password "changeme"
54 :full-name "tester")
55 (funcall expect 10 "debug mode")))
56
57 (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan@foonet"))
58 (funcall expect 10 "<bob> tester, welcome!")
59 (funcall expect 10 "<alice> tester, welcome!")
60 (erc-scenarios-common-say "/ignore alice 1m")
61 (erc-scenarios-common-say "/ignore mike 1h")
62 (funcall expect 10 "ignoring alice for 1m0s")
63 (funcall expect 10 "<bob> alice: Signior Iachimo")
64 (erc-scenarios-common-say "/ignore")
65 (funcall expect 10 "alice 59s")
66 (funcall expect 10 "mike 59m59s")
67 (funcall expect -0.1 "<alice>")
68 (funcall expect 10 "<bob> alice: The ground is bloody")
69 (erc-scenarios-common-say "/unignore alice")
70 (funcall expect 10 "<alice>"))
71
72 ;; No <mike> messages were ignored on network barnet.
73 (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan@barnet"))
74 (funcall expect 10 "<mike> tester, welcome!")
75 (funcall expect 10 "<joe> tester, welcome!")
76 (funcall expect 10 "<mike> joe: Whipp'd")
77 (funcall expect 10 "<mike> joe: Double"))))
78
79;;; erc-scenarios-ignore.el ends here
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 3e8ddef3731..22432a68034 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -50,6 +50,34 @@
50 (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1d"))) 50 (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1d")))
51 (should (equal (erc--read-time-period "foo: ") 86400)))) 51 (should (equal (erc--read-time-period "foo: ") 86400))))
52 52
53(ert-deftest erc--format-time-period ()
54 (should (equal (erc--format-time-period 59) "59s"))
55 (should (equal (erc--format-time-period 59.9) "59s"))
56 (should (equal (erc--format-time-period 60) "1m0s"))
57 (should (equal (erc--format-time-period 119) "1m59s"))
58 (should (equal (erc--format-time-period 119.9) "1m59s"))
59 (should (equal (erc--format-time-period 120.9) "2m0s"))
60 (should (equal (erc--format-time-period 3599.9) "59m59s"))
61 (should (equal (erc--format-time-period 3600) "1h0m0s")))
62
63;; This asserts that the first pattern on file matching a supplied
64;; `user' parameter will be removed after confirmation.
65(ert-deftest erc-cmd-UNIGNORE ()
66 ;; XXX these functions mutate `erc-ignore-list' via `delete'.
67 (should (local-variable-if-set-p 'erc-ignore-list))
68 (erc-tests-common-make-server-buf)
69
70 (setq erc-ignore-list (list ".")) ; match anything
71 (ert-simulate-keys (list ?\r)
72 (erc-cmd-IGNORE "abc"))
73 (should (equal erc-ignore-list (list "abc" ".")))
74
75 (cl-letf (((symbol-function 'y-or-n-p) #'always))
76 (erc-cmd-UNIGNORE "abcdef")
77 (should (equal erc-ignore-list (list ".")))
78 (erc-cmd-UNIGNORE "foo"))
79 (should-not erc-ignore-list))
80
53(ert-deftest erc-with-all-buffers-of-server () 81(ert-deftest erc-with-all-buffers-of-server ()
54 (let (proc-exnet 82 (let (proc-exnet
55 proc-onet 83 proc-onet