1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Improve new connections in erc-handle-irc-url

* doc/misc/erc.texi: Add new Integrations section to the info manual
under Advanced Usage.
* etc/ERC-NEWS: Add new section mentioning improved UX when clicking
on irc:// links.

* lisp/erc/erc.el (erc-handle-irc-url): Add optional "scheme"
parameter.  Fix `erc-open' invocation so that the server buffer is
named correctly by deferring to a new customizable opener.  Arrange
for JOINing a channel in a manner similar to ERC's autojoin module.
(erc-url-connect-function): Add new option for creating a new ERC
connection based on info parsed from a URL.
(erc--url-default-connect-function): New function to serve as an
interactive-only fallback when a user hasn't specified a URL connect
function.
* lisp/erc/erc-compat.el (erc-compat--29-browse-url--irc): Add new
compatibility function for `browse-url-irc' and include it in
`browse-url-default-handlers' on Emacs versions below 29.

* test/lisp/erc/erc-tests.el (erc-tests--make-server-buf,
erc-tests--make-client-buf): Add helpers for creating dummy ERC
buffers.
(erc-handle-irc-url): Add test.
* test/lisp/erc/erc-scenarios-misc.el (erc-scenarios-handle-irc-url):
Add new test.
* test/lisp/erc/resources/join/legacy/foonet.eld: Relax
timeout.  (Bug#56514.)
This commit is contained in:
F. Jason Park 2022-07-11 05:14:57 -07:00
parent 535cc4c81a
commit ed5022b4ee
7 changed files with 263 additions and 20 deletions

View file

@ -177,4 +177,32 @@
(erc-scenarios-common-say "Hi")
(funcall expect 10 "Hola")))))
(defvar url-irc-function)
(ert-deftest erc-scenarios-handle-irc-url ()
:tags '(:expensive-test)
(erc-scenarios-common-with-cleanup
((erc-scenarios-common-dialog "join/legacy")
(dumb-server (erc-d-run "localhost" t 'foonet))
(port (process-contact dumb-server :service))
(expect (erc-d-t-make-expecter))
(url-irc-function 'url-irc-erc)
(erc-url-connect-function
(lambda (scheme &rest r)
(ert-info ("Connect to foonet")
(should (equal scheme "irc"))
(with-current-buffer (apply #'erc `(:full-name "tester" ,@r))
(should (string= (buffer-name)
(format "127.0.0.1:%d" port)))
(current-buffer))))))
(with-temp-buffer
(insert (format ";; irc://tester:changeme@127.0.0.1:%d/#chan" port))
(goto-char 10)
(browse-url-at-point))
(ert-info ("Connected")
(with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
(funcall expect 10 "welcome")))))
;;; erc-scenarios-misc.el ends here

View file

@ -1084,4 +1084,98 @@
'(nil 7000 nil "Bob's Name" t
"bob:changeme" nil nil nil nil "bobo" nil)))))))
(defun erc-tests--make-server-buf (name)
(with-current-buffer (get-buffer-create name)
(erc-mode)
(setq erc-server-process (start-process "sleep" (current-buffer)
"sleep" "1")
erc-session-server (concat "irc." name ".org")
erc-session-port 6667
erc-network (intern name))
(set-process-query-on-exit-flag erc-server-process nil)
(current-buffer)))
(defun erc-tests--make-client-buf (server name)
(unless (bufferp server)
(setq server (get-buffer server)))
(with-current-buffer (get-buffer-create name)
(erc-mode)
(setq erc--target (erc--target-from-string name))
(dolist (v '(erc-server-process
erc-session-server
erc-session-port
erc-network))
(set v (buffer-local-value v server)))
(current-buffer)))
(ert-deftest erc-handle-irc-url ()
(let* (calls
rvbuf
erc-networks-alist
erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook
(erc-url-connect-function
(lambda (&rest r)
(push r calls)
(if (functionp rvbuf) (funcall rvbuf) rvbuf))))
(cl-letf (((symbol-function 'erc-cmd-JOIN)
(lambda (&rest r) (push r calls))))
(with-current-buffer (erc-tests--make-server-buf "foonet")
(setq rvbuf (current-buffer)))
(erc-tests--make-server-buf "barnet")
(erc-tests--make-server-buf "baznet")
(ert-info ("Unknown network")
(erc-handle-irc-url "irc.foonet.org" 6667 "#chan" nil nil "irc")
(should (equal '("#chan" nil) (pop calls)))
(should-not calls))
(ert-info ("Unknown network, no port")
(erc-handle-irc-url "irc.foonet.org" nil "#chan" nil nil "irc")
(should (equal '("#chan" nil) (pop calls)))
(should-not calls))
(ert-info ("Known network, no port")
(setq erc-networks-alist '((foonet "irc.foonet.org")))
(erc-handle-irc-url "irc.foonet.org" nil "#chan" nil nil "irc")
(should (equal '("#chan" nil) (pop calls)))
(should-not calls))
(ert-info ("Known network, different port")
(erc-handle-irc-url "irc.foonet.org" 6697 "#chan" nil nil "irc")
(should (equal '("#chan" nil) (pop calls)))
(should-not calls))
(ert-info ("Known network, existing chan with key")
(erc-tests--make-client-buf "foonet" "#chan")
(erc-handle-irc-url "irc.foonet.org" nil "#chan?sec" nil nil "irc")
(should (equal '("#chan" "sec") (pop calls)))
(should-not calls))
(ert-info ("Unknown network, connect, no chan")
(erc-handle-irc-url "irc.gnu.org" nil nil nil nil "irc")
(should (equal '("irc" :server "irc.gnu.org") (pop calls)))
(should-not calls))
(ert-info ("Unknown network, connect, chan")
(with-current-buffer "foonet"
(should-not (local-variable-p 'erc-after-connect)))
(setq rvbuf (lambda () (erc-tests--make-server-buf "gnu")))
(erc-handle-irc-url "irc.gnu.org" nil "#spam" nil nil "irc")
(should (equal '("irc" :server "irc.gnu.org") (pop calls)))
(should-not calls)
(with-current-buffer "gnu"
(should (local-variable-p 'erc-after-connect))
(funcall (car erc-after-connect))
(should (equal '("#spam" nil) (pop calls)))
(should-not (local-variable-p 'erc-after-connect)))
(should-not calls))))
(when noninteractive
(kill-buffer "foonet")
(kill-buffer "barnet")
(kill-buffer "baznet")
(kill-buffer "#chan")))
;;; erc-tests.el ends here

View file

@ -1,5 +1,5 @@
;; -*- mode: lisp-data; -*-
((pass 1 "PASS :changeme"))
((pass 10 "PASS :changeme"))
((nick 1 "NICK tester"))
((user 1 "USER user 0 * :tester")
(0 ":irc.foonet.org 001 tester :Welcome to the foonet IRC Network tester")