aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park2022-07-11 05:14:57 -0700
committerF. Jason Park2022-11-16 21:34:36 -0800
commited5022b4eec676bd6c0509615a1f939b796b942b (patch)
tree0ad5489bdd8e7ea7b27cd110d559cbe347b1a682 /test
parent535cc4c81a91d0661418ce59be951dda9e233a2e (diff)
downloademacs-ed5022b4eec676bd6c0509615a1f939b796b942b.tar.gz
emacs-ed5022b4eec676bd6c0509615a1f939b796b942b.zip
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.)
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-scenarios-misc.el28
-rw-r--r--test/lisp/erc/erc-tests.el94
-rw-r--r--test/lisp/erc/resources/join/legacy/foonet.eld2
3 files changed, 123 insertions, 1 deletions
diff --git a/test/lisp/erc/erc-scenarios-misc.el b/test/lisp/erc/erc-scenarios-misc.el
index ded620ccc1d..8557a779069 100644
--- a/test/lisp/erc/erc-scenarios-misc.el
+++ b/test/lisp/erc/erc-scenarios-misc.el
@@ -177,4 +177,32 @@
177 (erc-scenarios-common-say "Hi") 177 (erc-scenarios-common-say "Hi")
178 (funcall expect 10 "Hola"))))) 178 (funcall expect 10 "Hola")))))
179 179
180(defvar url-irc-function)
181
182(ert-deftest erc-scenarios-handle-irc-url ()
183 :tags '(:expensive-test)
184 (erc-scenarios-common-with-cleanup
185 ((erc-scenarios-common-dialog "join/legacy")
186 (dumb-server (erc-d-run "localhost" t 'foonet))
187 (port (process-contact dumb-server :service))
188 (expect (erc-d-t-make-expecter))
189 (url-irc-function 'url-irc-erc)
190 (erc-url-connect-function
191 (lambda (scheme &rest r)
192 (ert-info ("Connect to foonet")
193 (should (equal scheme "irc"))
194 (with-current-buffer (apply #'erc `(:full-name "tester" ,@r))
195 (should (string= (buffer-name)
196 (format "127.0.0.1:%d" port)))
197 (current-buffer))))))
198
199 (with-temp-buffer
200 (insert (format ";; irc://tester:changeme@127.0.0.1:%d/#chan" port))
201 (goto-char 10)
202 (browse-url-at-point))
203
204 (ert-info ("Connected")
205 (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
206 (funcall expect 10 "welcome")))))
207
180;;; erc-scenarios-misc.el ends here 208;;; erc-scenarios-misc.el ends here
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index db54cb4889f..a5100ec1556 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1084,4 +1084,98 @@
1084 '(nil 7000 nil "Bob's Name" t 1084 '(nil 7000 nil "Bob's Name" t
1085 "bob:changeme" nil nil nil nil "bobo" nil))))))) 1085 "bob:changeme" nil nil nil nil "bobo" nil)))))))
1086 1086
1087(defun erc-tests--make-server-buf (name)
1088 (with-current-buffer (get-buffer-create name)
1089 (erc-mode)
1090 (setq erc-server-process (start-process "sleep" (current-buffer)
1091 "sleep" "1")
1092 erc-session-server (concat "irc." name ".org")
1093 erc-session-port 6667
1094 erc-network (intern name))
1095 (set-process-query-on-exit-flag erc-server-process nil)
1096 (current-buffer)))
1097
1098(defun erc-tests--make-client-buf (server name)
1099 (unless (bufferp server)
1100 (setq server (get-buffer server)))
1101 (with-current-buffer (get-buffer-create name)
1102 (erc-mode)
1103 (setq erc--target (erc--target-from-string name))
1104 (dolist (v '(erc-server-process
1105 erc-session-server
1106 erc-session-port
1107 erc-network))
1108 (set v (buffer-local-value v server)))
1109 (current-buffer)))
1110
1111(ert-deftest erc-handle-irc-url ()
1112 (let* (calls
1113 rvbuf
1114 erc-networks-alist
1115 erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook
1116 (erc-url-connect-function
1117 (lambda (&rest r)
1118 (push r calls)
1119 (if (functionp rvbuf) (funcall rvbuf) rvbuf))))
1120
1121 (cl-letf (((symbol-function 'erc-cmd-JOIN)
1122 (lambda (&rest r) (push r calls))))
1123
1124 (with-current-buffer (erc-tests--make-server-buf "foonet")
1125 (setq rvbuf (current-buffer)))
1126 (erc-tests--make-server-buf "barnet")
1127 (erc-tests--make-server-buf "baznet")
1128
1129 (ert-info ("Unknown network")
1130 (erc-handle-irc-url "irc.foonet.org" 6667 "#chan" nil nil "irc")
1131 (should (equal '("#chan" nil) (pop calls)))
1132 (should-not calls))
1133
1134 (ert-info ("Unknown network, no port")
1135 (erc-handle-irc-url "irc.foonet.org" nil "#chan" nil nil "irc")
1136 (should (equal '("#chan" nil) (pop calls)))
1137 (should-not calls))
1138
1139 (ert-info ("Known network, no port")
1140 (setq erc-networks-alist '((foonet "irc.foonet.org")))
1141 (erc-handle-irc-url "irc.foonet.org" nil "#chan" nil nil "irc")
1142 (should (equal '("#chan" nil) (pop calls)))
1143 (should-not calls))
1144
1145 (ert-info ("Known network, different port")
1146 (erc-handle-irc-url "irc.foonet.org" 6697 "#chan" nil nil "irc")
1147 (should (equal '("#chan" nil) (pop calls)))
1148 (should-not calls))
1149
1150 (ert-info ("Known network, existing chan with key")
1151 (erc-tests--make-client-buf "foonet" "#chan")
1152 (erc-handle-irc-url "irc.foonet.org" nil "#chan?sec" nil nil "irc")
1153 (should (equal '("#chan" "sec") (pop calls)))
1154 (should-not calls))
1155
1156 (ert-info ("Unknown network, connect, no chan")
1157 (erc-handle-irc-url "irc.gnu.org" nil nil nil nil "irc")
1158 (should (equal '("irc" :server "irc.gnu.org") (pop calls)))
1159 (should-not calls))
1160
1161 (ert-info ("Unknown network, connect, chan")
1162 (with-current-buffer "foonet"
1163 (should-not (local-variable-p 'erc-after-connect)))
1164 (setq rvbuf (lambda () (erc-tests--make-server-buf "gnu")))
1165 (erc-handle-irc-url "irc.gnu.org" nil "#spam" nil nil "irc")
1166 (should (equal '("irc" :server "irc.gnu.org") (pop calls)))
1167 (should-not calls)
1168 (with-current-buffer "gnu"
1169 (should (local-variable-p 'erc-after-connect))
1170 (funcall (car erc-after-connect))
1171 (should (equal '("#spam" nil) (pop calls)))
1172 (should-not (local-variable-p 'erc-after-connect)))
1173 (should-not calls))))
1174
1175 (when noninteractive
1176 (kill-buffer "foonet")
1177 (kill-buffer "barnet")
1178 (kill-buffer "baznet")
1179 (kill-buffer "#chan")))
1180
1087;;; erc-tests.el ends here 1181;;; erc-tests.el ends here
diff --git a/test/lisp/erc/resources/join/legacy/foonet.eld b/test/lisp/erc/resources/join/legacy/foonet.eld
index 344ba7c1daf..4025094a59c 100644
--- a/test/lisp/erc/resources/join/legacy/foonet.eld
+++ b/test/lisp/erc/resources/join/legacy/foonet.eld
@@ -1,5 +1,5 @@
1;; -*- mode: lisp-data; -*- 1;; -*- mode: lisp-data; -*-
2((pass 1 "PASS :changeme")) 2((pass 10 "PASS :changeme"))
3((nick 1 "NICK tester")) 3((nick 1 "NICK tester"))
4((user 1 "USER user 0 * :tester") 4((user 1 "USER user 0 * :tester")
5 (0 ":irc.foonet.org 001 tester :Welcome to the foonet IRC Network tester") 5 (0 ":irc.foonet.org 001 tester :Welcome to the foonet IRC Network tester")