unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 3ac1089c5416204efde147adafbc9397b13e47c0 10241 bytes (raw)
name: test/lisp/erc/erc-scenarios-base-association.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
 
;;; erc-scenarios-base-association.el --- base assoc scenarios -*- lexical-binding: t -*-

;; Copyright (C) 2022-2023 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/>.

;;; Code:

(require 'ert-x)
(eval-and-compile
  (let ((load-path (cons (ert-resource-directory) load-path)))
    (require 'erc-scenarios-common)))

(declare-function erc-network-name "erc-networks")
(declare-function erc-network "erc-networks")
(declare-function erc-track-get-active-buffer "erc-track" (arg))
(defvar erc-autojoin-channels-alist)
(defvar erc-track-mode)
(defvar erc-network)

;; Two networks, same channel name, no confusion (no bouncer).  Some
;; of this draws from bug#47522 "foil-in-server-buf".  It shows that
;; disambiguation-related changes added for bug#48598 are not specific
;; to bouncers.

(defun erc-scenarios-common--base-association-multi-net (second-join)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/assoc/multi-net")
       (erc-server-flood-penalty 0.1)
       (dumb-server-foonet-buffer (get-buffer-create "*server-foonet*"))
       (dumb-server-barnet-buffer (get-buffer-create "*server-barnet*"))
       (dumb-server-foonet (erc-d-run "localhost" t "server-foonet" 'foonet))
       (dumb-server-barnet (erc-d-run "localhost" t "server-barnet" 'barnet))
       (expect (erc-d-t-make-expecter)))

    (ert-info ("Connect to foonet, join #chan")
      (with-current-buffer
          (erc :server "127.0.0.1"
               :port (process-contact dumb-server-foonet :service)
               :nick "tester"
               :password "changeme"
               :full-name "tester")
        (funcall expect 3 "debug mode")
        (erc-cmd-JOIN "#chan")))

    (erc-d-t-wait-for 2 (get-buffer "#chan"))

    (ert-info ("Connect to barnet, join #chan")
      (with-current-buffer
          (erc :server "127.0.0.1"
               :port (process-contact dumb-server-barnet :service)
               :nick "tester"
               :password "changeme"
               :full-name "tester")
        (funcall expect 5 "debug mode")))

    (funcall second-join)

    (erc-d-t-wait-for 3 (get-buffer "#chan@barnet"))

    (erc-d-t-wait-for 2 "Buf #chan now #chan@foonet"
      (and (get-buffer "#chan@foonet") (not (get-buffer "#chan"))))

    (ert-info ("All #chan@foonet output consumed")
      (with-current-buffer "#chan@foonet"
        (funcall expect 3 "bob")
        (funcall expect 3 "was created on")
        (funcall expect 3 "prosperous")))

    (ert-info ("All #chan@barnet output consumed")
      (with-current-buffer "#chan@barnet"
        (funcall expect 3 "mike")
        (funcall expect 3 "was created on")
        (funcall expect 20 "ingenuous")))))

(ert-deftest erc-scenarios-base-association-multi-net--baseline ()
  :tags '(:expensive-test)
  (erc-scenarios-common--base-association-multi-net
   (lambda () (with-current-buffer "barnet" (erc-cmd-JOIN "#chan")))))

;; The /join command only targets the current buffer's process.  This
;; recasts scenario bug#48598 "ambiguous-join" (which was based on
;; bug#47522) to show that issuing superfluous /join commands
;; (apparently fairly common) is benign.

(ert-deftest erc-scenarios-base-association-multi-net--ambiguous-join ()
  :tags '(:expensive-test)
  (erc-scenarios-common--base-association-multi-net
   (lambda ()
     (ert-info ("Nonsensical JOIN attempts silently dropped.")
       (with-current-buffer "foonet" (erc-cmd-JOIN "#chan"))
       (sit-for 0.1)
       (with-current-buffer "#chan" (erc-cmd-JOIN "#chan"))
       (sit-for 0.1)
       (erc-d-t-wait-for 2 (get-buffer "#chan"))
       (erc-d-t-wait-for 1 "Only one #chan buffer exists"
         (should (equal (erc-scenarios-common-buflist "#chan")
                        (list (get-buffer "#chan")))))
       (with-current-buffer "*server-barnet*"
         (erc-d-t-absent-for 0.1 "JOIN"))
       (with-current-buffer "barnet" (erc-cmd-JOIN "#chan"))))))

;; Playback for same channel on two networks routed correctly.
;; Originally from Bug#48598: 28.0.50; buffer-naming collisions
;; involving bouncers in ERC.

(ert-deftest erc-scenarios-base-association-bouncer-history ()
  :tags '(:expensive-test)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/assoc/bouncer-history")
       (erc-d-t-cleanup-sleep-secs 1)
       (dumb-server (erc-d-run "localhost" t 'foonet 'barnet))
       (port (process-contact dumb-server :service))
       (erc-server-flood-penalty 0.5)
       (expect (erc-d-t-make-expecter))
       erc-autojoin-channels-alist
       erc-server-buffer-foo erc-server-process-foo
       erc-server-buffer-bar erc-server-process-bar)

    (ert-info ("Connect to foonet")
      (with-current-buffer
          (setq erc-server-buffer-foo (erc :server "127.0.0.1"
                                           :port port
                                           :nick "tester"
                                           :password "foonet:changeme"
                                           :full-name "tester"))
        (setq erc-server-process-foo erc-server-process)
        (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
        (funcall expect 5 "foonet")))

    (erc-d-t-wait-for 5 (get-buffer "#chan"))

    (ert-info ("Connect to barnet")
      (with-current-buffer
          (setq erc-server-buffer-bar (erc :server "127.0.0.1"
                                           :port port
                                           :nick "tester"
                                           :password "barnet:changeme"
                                           :full-name "tester"))
        (setq erc-server-process-bar erc-server-process)
        (erc-d-t-wait-for 5 "Temporary name assigned"
          (string= (buffer-name) (format "127.0.0.1:%d" port)))
        (funcall expect 5 "barnet")))

    (ert-info ("Server buffers are unique")
      (should-not (eq erc-server-buffer-foo erc-server-buffer-bar)))

    (ert-info ("Networks correctly determined and adopted as buffer names")
      (with-current-buffer erc-server-buffer-foo
        (erc-d-t-wait-for 3 "network name foonet becomes buffer name"
          (and (eq (erc-network) 'foonet) (string= (buffer-name) "foonet"))))
      (with-current-buffer erc-server-buffer-bar
        (erc-d-t-wait-for 3 "network name barnet becomes buffer name"
          (and (eq (erc-network) 'barnet) (string= (buffer-name) "barnet")))))

    (erc-d-t-wait-for 5 (get-buffer "#chan@barnet"))

    (ert-info ("Two channel buffers created, original #chan renamed")
      (should (= 4 (length (erc-buffer-list))))
      (should (equal (list (get-buffer "#chan@barnet")
                           (get-buffer "#chan@foonet"))
                     (erc-scenarios-common-buflist "#chan"))))

    (ert-info ("#chan@foonet is exclusive, no cross-contamination")
      (with-current-buffer "#chan@foonet"
        (erc-d-t-search-for 1 "<bob>")
        (erc-d-t-absent-for 0.1 "<joe>")
        (should (eq erc-server-process erc-server-process-foo))))

    (ert-info ("#chan@barnet is exclusive, no cross-contamination")
      (with-current-buffer "#chan@barnet"
        (erc-d-t-search-for 1 "<joe>")
        (erc-d-t-absent-for 0.1 "<bob>")
        (should (eq erc-server-process erc-server-process-bar))))

    (ert-info ("All output sent")
      (with-current-buffer "#chan@foonet"
        (erc-d-t-search-for 10 "please your lordship"))
      (with-current-buffer "#chan@barnet"
        (erc-d-t-search-for 10 "I'll bid adieu")))))

;; Some modules may need to perform housekeeping when a newly
;; connected server buffer is deemed a duplicate after its persistent
;; network context is discovered on MOTD end.  One such module is
;; `track', which needs to rid its list of modified channels of the
;; buffer being killed.  Without this, a user may encounter an
;; "Attempt to display deleted buffer" error when they try switching
;; to it.

(ert-deftest erc-scenarios-networks-merge-server-track ()
  :tags '(:expensive-test)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "networks/merge-server")
       (dumb-server (erc-d-run "localhost" t 'track 'track))
       (port (process-contact dumb-server :service))
       (erc-server-flood-penalty 0.1)
       (erc-join-buffer 'bury)
       (expect (erc-d-t-make-expecter)))

    (ert-info ("Connect")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :nick "tester")
        (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
        (should erc-track-mode)
        (funcall expect 5 "changed mode for tester")
        (erc-cmd-JOIN "#chan")))

    (ert-info ("Join channel and quit")
      (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
        (funcall expect 5 "The hour that fools should ask")
        (erc-cmd-QUIT ""))
      (with-current-buffer "FooNet"
        (funcall expect 5 "finished")))

    (ert-info ("Reconnect")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :nick "tester")
        (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
        (funcall expect 5 "changed mode for tester")))

    (with-current-buffer "#chan"
      (funcall expect 5 "The hour that fools should ask")
      ;; Simulate the old `erc-track-switch-buffer'
      (switch-to-buffer (erc-track-get-active-buffer 1))
      (erc-d-t-wait-for 10 (eq (get-buffer "FooNet") (current-buffer)))
      (erc-cmd-QUIT ""))))

;;; erc-scenarios-base-association.el ends here

debug log:

solving 3ac1089c541 ...
found 3ac1089c541 in https://yhetil.org/emacs-bugs/877csje0uz.fsf__19768.6912653566$1685890409$gmane$org@neverwas.me/
found a40a4cb7550 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 a40a4cb7550e43058647edff74ddbd45a3a10650	test/lisp/erc/erc-scenarios-base-association.el

applying [1/1] https://yhetil.org/emacs-bugs/877csje0uz.fsf__19768.6912653566$1685890409$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-scenarios-base-association.el b/test/lisp/erc/erc-scenarios-base-association.el
index a40a4cb7550..3ac1089c541 100644

Checking patch test/lisp/erc/erc-scenarios-base-association.el...
Applied patch test/lisp/erc/erc-scenarios-base-association.el cleanly.

index at:
100644 3ac1089c5416204efde147adafbc9397b13e47c0	test/lisp/erc/erc-scenarios-base-association.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).