aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park2022-04-05 17:45:00 -0700
committerF. Jason Park2022-06-30 15:03:26 -0700
commita63ed6f78a6f7169574cfb0a2d5df45890b540d6 (patch)
tree893aaf2d42a183810e10c0ceef3141335d398072 /test
parent4ae0707704eecb38836c1b0159bc3c456889a7a9 (diff)
downloademacs-a63ed6f78a6f7169574cfb0a2d5df45890b540d6.tar.gz
emacs-a63ed6f78a6f7169574cfb0a2d5df45890b540d6.zip
Remove duplicate ERC prompt on reconnect
* lisp/erc/erc-backend.el (erc--unhide-prompt, erc--hide-prompt, erc--unhide-prompt-on-self-insert): Add functions to ensure prompt is hidden on disconnect and shown when a user types /reconnect in a disconnected server buffer. (erc-process-sentinel): Register aforementioned function with `pre-command-hook' when prompt is deleted after disconnecting. (erc-server-PRIVMSG): Ensure prompt is showing when a new message arrives from target. * lisp/erc/erc.el (erc-hide-prompt): Repurpose unused option by changing meaning slightly to mean "selectively hide prompt when disconnected." Also delete obsolete, commented-out code that at some point used this option in its prior incarnation. (erc-prompt-hidden): Add new option to specify look of prompt when hidden. (erc-unhide-query-prompt): Add option to force-reveal query prompts on reconnect. (erc-open): Augment earlier reconnect-detection semantics by incorporating `erc--server-reconnecting'. In existing buffers, remove prompt-related hooks and reveal prompt, if necessary. (erc-cmd-RECONNECT): Allow a user to reconnect when already connected (by first disconnecting). (erc-connection-established): Possibly unhide query prompts. (Bug#54826) * test/lisp/erc/erc-tests.el (erc-tests--test-prep, erc-tests--set-fake-server-process): Factor out some common buffer-prep boilerplate involving user input and the server process. Shared with bug#54536.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-tests.el152
1 files changed, 146 insertions, 6 deletions
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 3c76cb97caf..061dfc2f5e0 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -135,6 +135,150 @@
135 (should (get-buffer "#spam")) 135 (should (get-buffer "#spam"))
136 (kill-buffer "#spam"))) 136 (kill-buffer "#spam")))
137 137
138(defun erc-tests--send-prep ()
139 ;; Caller should probably shadow `erc-insert-modify-hook' or
140 ;; populate user tables for erc-button.
141 (erc-mode)
142 (insert "\n\n")
143 (setq erc-input-marker (make-marker)
144 erc-insert-marker (make-marker))
145 (set-marker erc-insert-marker (point-max))
146 (erc-display-prompt)
147 (should (= (point) erc-input-marker)))
148
149(defun erc-tests--set-fake-server-process (&rest args)
150 (setq erc-server-process
151 (apply #'start-process (car args) (current-buffer) args))
152 (set-process-query-on-exit-flag erc-server-process nil))
153
154(ert-deftest erc-hide-prompt ()
155 (let (erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
156
157 (with-current-buffer (get-buffer-create "ServNet")
158 (erc-tests--send-prep)
159 (goto-char erc-insert-marker)
160 (should (looking-at-p (regexp-quote erc-prompt)))
161 (erc-tests--set-fake-server-process "sleep" "1")
162 (set-process-sentinel erc-server-process #'ignore)
163 (setq erc-network 'ServNet)
164 (set-process-query-on-exit-flag erc-server-process nil))
165
166 (with-current-buffer (get-buffer-create "#chan")
167 (erc-tests--send-prep)
168 (goto-char erc-insert-marker)
169 (should (looking-at-p (regexp-quote erc-prompt)))
170 (setq erc-server-process (buffer-local-value 'erc-server-process
171 (get-buffer "ServNet"))
172 erc-default-recipients '("#chan")))
173
174 (with-current-buffer (get-buffer-create "bob")
175 (erc-tests--send-prep)
176 (goto-char erc-insert-marker)
177 (should (looking-at-p (regexp-quote erc-prompt)))
178 (setq erc-server-process (buffer-local-value 'erc-server-process
179 (get-buffer "ServNet"))
180 erc-default-recipients '("bob")))
181
182 (ert-info ("Value: t (default)")
183 (should (eq erc-hide-prompt t))
184 (with-current-buffer "ServNet"
185 (should (= (point) erc-insert-marker))
186 (erc--hide-prompt erc-server-process)
187 (should (string= ">" (get-text-property (point) 'display))))
188
189 (with-current-buffer "#chan"
190 (goto-char erc-insert-marker)
191 (should (string= ">" (get-text-property (point) 'display)))
192 (should (memq #'erc--unhide-prompt-on-self-insert pre-command-hook))
193 (goto-char erc-input-marker)
194 (ert-simulate-command '(self-insert-command 1 ?/))
195 (goto-char erc-insert-marker)
196 (should-not (get-text-property (point) 'display))
197 (should-not (memq #'erc--unhide-prompt-on-self-insert
198 pre-command-hook)))
199
200 (with-current-buffer "bob"
201 (goto-char erc-insert-marker)
202 (should (string= ">" (get-text-property (point) 'display)))
203 (should (memq #'erc--unhide-prompt-on-self-insert pre-command-hook))
204 (goto-char erc-input-marker)
205 (ert-simulate-command '(self-insert-command 1 ?/))
206 (goto-char erc-insert-marker)
207 (should-not (get-text-property (point) 'display))
208 (should-not (memq #'erc--unhide-prompt-on-self-insert
209 pre-command-hook)))
210
211 (with-current-buffer "ServNet"
212 (should (get-text-property erc-insert-marker 'display))
213 (should (memq #'erc--unhide-prompt-on-self-insert pre-command-hook))
214 (erc--unhide-prompt)
215 (should-not (memq #'erc--unhide-prompt-on-self-insert
216 pre-command-hook))
217 (should-not (get-text-property erc-insert-marker 'display))))
218
219 (ert-info ("Value: server")
220 (setq erc-hide-prompt '(server))
221 (with-current-buffer "ServNet"
222 (erc--hide-prompt erc-server-process)
223 (should (string= ">" (get-text-property erc-insert-marker 'display))))
224
225 (with-current-buffer "#chan"
226 (should-not (get-text-property erc-insert-marker 'display)))
227
228 (with-current-buffer "bob"
229 (should-not (get-text-property erc-insert-marker 'display)))
230
231 (with-current-buffer "ServNet"
232 (erc--unhide-prompt)
233 (should-not (get-text-property erc-insert-marker 'display))))
234
235 (ert-info ("Value: channel")
236 (setq erc-hide-prompt '(channel))
237 (with-current-buffer "ServNet"
238 (erc--hide-prompt erc-server-process)
239 (should-not (get-text-property erc-insert-marker 'display)))
240
241 (with-current-buffer "bob"
242 (should-not (get-text-property erc-insert-marker 'display)))
243
244 (with-current-buffer "#chan"
245 (should (string= ">" (get-text-property erc-insert-marker 'display)))
246 (erc--unhide-prompt)
247 (should-not (get-text-property erc-insert-marker 'display))))
248
249 (ert-info ("Value: query")
250 (setq erc-hide-prompt '(query))
251 (with-current-buffer "ServNet"
252 (erc--hide-prompt erc-server-process)
253 (should-not (get-text-property erc-insert-marker 'display)))
254
255 (with-current-buffer "bob"
256 (should (string= ">" (get-text-property erc-insert-marker 'display)))
257 (erc--unhide-prompt)
258 (should-not (get-text-property erc-insert-marker 'display)))
259
260 (with-current-buffer "#chan"
261 (should-not (get-text-property erc-insert-marker 'display))))
262
263 (ert-info ("Value: nil")
264 (setq erc-hide-prompt nil)
265 (with-current-buffer "ServNet"
266 (erc--hide-prompt erc-server-process)
267 (should-not (get-text-property erc-insert-marker 'display)))
268
269 (with-current-buffer "bob"
270 (should-not (get-text-property erc-insert-marker 'display)))
271
272 (with-current-buffer "#chan"
273 (should-not (get-text-property erc-insert-marker 'display))
274 (erc--unhide-prompt) ; won't blow up when prompt already showing
275 (should-not (get-text-property erc-insert-marker 'display))))
276
277 (when noninteractive
278 (kill-buffer "#chan")
279 (kill-buffer "bob")
280 (kill-buffer "ServNet"))))
281
138(ert-deftest erc--switch-to-buffer () 282(ert-deftest erc--switch-to-buffer ()
139 (defvar erc-modified-channels-alist) ; lisp/erc/erc-track.el 283 (defvar erc-modified-channels-alist) ; lisp/erc/erc-track.el
140 284
@@ -218,14 +362,10 @@
218(ert-deftest erc-ring-previous-command () 362(ert-deftest erc-ring-previous-command ()
219 (with-current-buffer (get-buffer-create "*#fake*") 363 (with-current-buffer (get-buffer-create "*#fake*")
220 (erc-mode) 364 (erc-mode)
221 (insert "\n\n") 365 (erc-tests--send-prep)
366 (setq-local erc-last-input-time 0)
222 (should-not (local-variable-if-set-p 'erc-send-completed-hook)) 367 (should-not (local-variable-if-set-p 'erc-send-completed-hook))
223 (set (make-local-variable 'erc-send-completed-hook) nil) ; skip t (globals) 368 (set (make-local-variable 'erc-send-completed-hook) nil) ; skip t (globals)
224 (setq erc-input-marker (make-marker)
225 erc-insert-marker (make-marker))
226 (set-marker erc-insert-marker (point-max))
227 (erc-display-prompt)
228 (should (= (point) erc-input-marker))
229 ;; Just in case erc-ring-mode is already on 369 ;; Just in case erc-ring-mode is already on
230 (setq-local erc-pre-send-functions nil) 370 (setq-local erc-pre-send-functions nil)
231 (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring) 371 (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring)