all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 109cf27b01aac1613007ed1d48f21749f532e16f 5360 bytes (raw)
name: test/lisp/erc/erc-scenarios-base-kill-on-part.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
 
;;; erc-scenarios-base-kill-on-part.el --- killing buffers on part -*- lexical-binding: t -*-

;; Copyright (C) 2024 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)))

;; Assert channel buffer is killed when `erc-kill-buffer-on-part' is
;; enabled and a user issues a /part.
(ert-deftest erc-scenarios-base-kill-on-part--enabled ()
  :tags '(:expensive-test)
  (should-not erc-kill-buffer-on-part)

  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/reuse-buffers/channel")
       (erc-server-flood-penalty 0.1)
       (dumb-server (erc-d-run "localhost" t 'foonet))
       (port (process-contact dumb-server :service))
       (erc-kill-buffer-on-part t)
       (calls nil)
       (erc-part-hook (lambda (b) (push (buffer-name b) calls)))
       (expect (erc-d-t-make-expecter)))

    (ert-info ("Connect to foonet")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :nick "tester"
                                :password "foonet:changeme"
                                :full-name "tester")
        (funcall expect 10 "This server is in debug mode")))

    (with-current-buffer (erc-d-t-wait-for 20 (get-buffer "#chan"))
      (funcall expect 10 "<alice> bob: Whilst I can shake")
      (erc-scenarios-common-say "/part"))

    (erc-d-t-wait-for 20 (null (get-buffer "#chan")))
    (should (equal calls '("#chan")))))

;; When `erc-kill-buffer-on-part' is non-nil, and the parted buffer has
;; already been killed, don't kill the server buffer.  Bug#70840
(ert-deftest erc-scenarios-base-kill-on-part--enabled/killed ()
  :tags '(:expensive-test)
  (should-not erc-kill-buffer-on-part)

  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/reuse-buffers/channel")
       (erc-server-flood-penalty 0.1)
       (dumb-server (erc-d-run "localhost" t 'foonet))
       (port (process-contact dumb-server :service))
       (erc-kill-buffer-on-part t)
       (killingp nil)
       (calls nil)
       (erc-part-hook (lambda (b) (push (cons (buffer-name b) killingp)
                                        calls)))
       (expect (erc-d-t-make-expecter)))

    (ert-info ("Connect to foonet")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :nick "tester"
                                :password "foonet:changeme"
                                :full-name "tester")
        (funcall expect 10 "This server is in debug mode")))

    (with-current-buffer (erc-d-t-wait-for 20 (get-buffer "#chan"))
      (funcall expect 10 "<alice> bob: Whilst I can shake")
      ;; There's a race here because the response handler may run
      ;; before `killingp' is nil, but at least false negatives aren't
      ;; possible.  Shadowing `erc-server-send-queue' temporarily
      ;; would fix it, but that's too leaky for this style of test.
      (setq killingp 'kill)
      (kill-buffer)
      (setq killingp nil))

    (erc-d-t-wait-for 20 (null (get-buffer "#chan")))
    (should (equal calls '(("#chan" . kill))))
    (erc-d-t-ensure-for 0.1 (get-buffer "foonet"))))

(ert-deftest erc-scenarios-base-kill-on-part--enabled/killed/compat ()
  :tags '(:expensive-test)
  (should-not erc-kill-buffer-on-part)

  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/reuse-buffers/channel")
       (erc-server-flood-penalty 0.1)
       (dumb-server (erc-d-run "localhost" t 'foonet))
       (port (process-contact dumb-server :service))
       (erc-kill-buffer-on-part t)
       (erc--run-part-hook-with-nil-buffer-p t) ; option under test
       (killingp nil)
       (calls nil)
       (erc-part-hook (lambda (b) (push (cons b killingp) calls)))
       (expect (erc-d-t-make-expecter)))

    (ert-info ("Connect to foonet")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :nick "tester"
                                :password "foonet:changeme"
                                :full-name "tester")
        (funcall expect 10 "This server is in debug mode")))

    (with-current-buffer (erc-d-t-wait-for 20 (get-buffer "#chan"))
      (funcall expect 10 "<alice> bob: Whilst I can shake")
      (setq killingp 'kill)
      (kill-buffer)
      (setq killingp nil))

    (erc-d-t-wait-for 20 (null (get-buffer "#chan")))
    (erc-d-t-wait-for 20 (equal calls '((nil . nil))))
    (should (get-buffer "foonet"))))

;;; erc-scenarios-base-kill-on-part.el ends here

debug log:

solving 109cf27b01a ...
found 109cf27b01a in https://yhetil.org/emacs/87seyj6wgh.fsf__27960.7857389905$1715779469$gmane$org@neverwas.me/

applying [1/1] https://yhetil.org/emacs/87seyj6wgh.fsf__27960.7857389905$1715779469$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-scenarios-base-kill-on-part.el b/test/lisp/erc/erc-scenarios-base-kill-on-part.el
new file mode 100644
index 00000000000..109cf27b01a

Checking patch test/lisp/erc/erc-scenarios-base-kill-on-part.el...
Applied patch test/lisp/erc/erc-scenarios-base-kill-on-part.el cleanly.

index at:
100644 109cf27b01aac1613007ed1d48f21749f532e16f	test/lisp/erc/erc-scenarios-base-kill-on-part.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.