1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00
emacs/test/lisp/erc/erc-scenarios-join-timing.el
F. Jason Park 2f5fe1a48e Cancel ERC autojoin timer in the server buffer
* lisp/erc/erc-join.el (erc-autojoin-channels-delayed): Only cancel
`erc--autojoin-timer' in the server buffer in which it's local.  After
Emacs 28 brought commit fc66ec3322 "Prefer
defvar-local in erc", customizing `erc-autojoin-timing' to `ident' led
to ERC emitting redundant JOINs before `erc-autojoin--join' was factored
out.  Additionally, don't bother binding options around the call to
`erc-autojoin-channels' to shape its behavior, preferring instead to
call the internal workhorse function directly.  Ever since bug#5521
introduced those options, the logic in `erc-autojoin-channels' has
ignored `erc-autojoin-delay' anyway, so long as `erc-autojoin-timing'
isn't `ident'.  This change may break third party advice.
(erc-autojoin-after-ident): Restore code to cancel timer.  It was
erroneously deleted in 959fbcf34b "favor
network identities in erc-join".
* test/lisp/erc/erc-join-tests.el: Require erc-tests-common atop file so
tests can take advantage of common utilities.
(erc-autojoin-channels--connect): Replace with a function and three
separate tests.
(erc-join-tests--autojoin-channels-connect): New function.
(erc-autojoin-channels/server, erc-autojoin-channels/network)
(erc-autojoin-channels/nomatch): New tests.
(erc-autojoin-channels--delay): Replace with a function and three
separate tests.  Remove guard to skip test on Solaris.
(erc-join-tests--autojoin-channels-ident): New function.
(erc-autojoin-channels-delayed/server)
(erc-autojoin-channels-delayed/network)
(erc-autojoin-channels-delayed/nomatch): New tests.
(erc-autojoin-channels--ident): Replace with function and two separate
tests.
(erc-join-tests--autojoin-after-ident): New function.
(erc-autojoin-after-ident/server)
(erc-autojoin-after-ident/network): New tests.
(erc-join-tests--autojoin-add--common)
(erc-join-tests--autojoin-add): Rename former to latter.
(erc-autojoin-add--network)
(erc-autojoin-add--network-extended-syntax)
(erc-autojoin-add--network-id): Adjust arguments to fixture.
(erc-autojoin-add--server): Use common utils.
(erc-join-tests--autojoin-remove--common)
(erc-join-tests--autojoin-remove): Rename former to latter.
(erc-autojoin-remove--network)
(erc-autojoin-remove--network-id): Adjust args for fixture.
(erc-autojoin-remove--server): Use common utils.
* test/lisp/erc/erc-scenarios-join-timing.el: New file.
* test/lisp/erc/resources/erc-scenarios-common.el
(erc-scenarios-common--run-in-term): In subprocess, don't use failure
tally as exit status unless body form succeeds.
* test/lisp/erc/resources/erc-tests-common.el
(erc-tests-common-init-server-proc): Use `make-process' instead of
`start-process'.
(erc-tests-common-make-server-buf): Use `erc-server-current-nick' to
create the `erc-networks--id' as a `erc-networks--id-qualifying'
instance, which is more realistic than a "fixed" variant.
* test/lisp/erc/resources/join/timing/connect-both.eld: New file.
* test/lisp/erc/resources/join/timing/ident-both.eld: New file.
(Bug#79017)
2025-07-27 19:57:28 -07:00

100 lines
4 KiB
EmacsLisp

;;; erc-scenarios-join-timing.el --- Services integration -*- lexical-binding: t -*-
;; Copyright (C) 2025 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; These tests illustrate behavior related to `erc-autojoin-timing'.
;; When the option's value is `ident', the services module runs code on
;; its behalf via `erc-nickserv-identified-hook'.
;; TODO add variants where `erc-nickserv-identify-mode' is not `both'.
;;; Code:
(require 'ert-x)
(eval-and-compile
(let ((load-path (cons (ert-resource-directory) load-path)))
(require 'erc-scenarios-common)))
(require 'erc-join)
(require 'erc-services)
(defun erc-scenarios-join-timing--services-identify-both (dialog)
(should (eq erc-nickserv-identify-mode 'both))
(erc-scenarios-common-with-cleanup
((erc-scenarios-common-dialog "join/timing")
(erc-server-flood-penalty 0.1)
(erc-modules (cons 'services erc-modules))
(erc-autojoin-channels-alist '((Libera.Chat "#chan")))
(erc-nickserv-passwords '((Libera.Chat (("tester" . "changeme")))))
(expect (erc-d-t-make-expecter))
(dumb-server (erc-d-run "localhost" t dialog))
(port (process-contact dumb-server :service)))
(ert-info ("Connect without password")
(with-current-buffer (erc :server "127.0.0.1"
:port port
:nick "tester"
:user "tester"
:full-name "tester")
(should (string= (buffer-name) (format "127.0.0.1:%d" port)))
(erc-d-t-wait-for 5 (eq erc-network 'Libera.Chat))
(funcall expect 5 "This nickname is registered.")
(with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
(funcall expect 10 "created"))
(funcall expect 2 "You are now identified")
(funcall expect 2 "You are now logged in as tester")))
(erc-services-mode -1)
(should-not (memq 'services erc-modules))))
;; This asserts the default behavior, when `erc-autojoin-timing' is
;; `connect'. Here, ERC emits the JOIN request before being informed by
;; NickServ that it needs to log in. The server then holds off on
;; granting the JOIN until authentication has completed.
(ert-deftest erc-scenarios-join-timing/connect ()
:tags '(:expensive-test)
(should (eq erc-autojoin-timing 'connect))
(erc-scenarios-join-timing--services-identify-both 'connect-both))
;; This demos the integration between the `join' and `services' modules
;; that occurs when `erc-autojoin-timing' is `ident'. Here, ERC
;; arranges not to request a JOIN until it's been authenticated by the
;; server. Since `erc-autojoin-delay' remains at its default of 30,
;; authentication occurs before the fallback timer fires.
(ert-deftest erc-scenarios-join-timing/ident ()
:tags '(:expensive-test)
(should (eq erc-autojoin-timing 'connect))
(should (= erc-autojoin-delay 30))
(let ((erc-autojoin-timing 'ident)
;; In the interest of time saving, this currently doesn't wait
;; around to verify that a second JOIN isn't sent. However, the
;; logic in `erc-autojoin--join' prevents such sending anyway,
;; meaning some other means of verification would be needed.
(erc-autojoin-delay 5))
(erc-scenarios-join-timing--services-identify-both 'ident-both)))
;;; erc-scenarios-join-timing.el ends here