unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob ecd746196cebe35309738dbf9a454027543ca5fb 7242 bytes (raw)
name: test/lisp/erc/erc-fill-tests.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
 
;;; erc-fill-tests.el --- ERC message filling -*- lexical-binding: t -*-

;; Copyright (C) 2020-2021 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)
(require 'erc-fill)

(defun erc-fill-tests--insert (&rest strings)
  (let ((inhibit-read-only t))
    (erc-parse-server-response erc-server-process (apply #'concat strings))))

(defun erc-fill-tests--setup-server-buffer ()
  (with-current-buffer (get-buffer-create "foonet")
    (erc-mode)
    (setq erc-server-process (start-process "true" (current-buffer) "true")
          erc-server-current-nick "tester"
          erc-server-users (make-hash-table :test #'equal))
    (set-process-query-on-exit-flag erc-server-process nil)))

(defun erc-fill-tests--setup-channel-buffer ()
  (with-current-buffer (get-buffer-create "#chan")
    (erc-mode)
    (insert "\n\n")
    (setq erc-input-marker (make-marker)
          ;; Kludge to get around saving display prop
          erc-timestamp-use-align-to nil
          ;; Kludge to make whitespace compare equal without expanding
          indent-tabs-mode nil
          erc-insert-marker (make-marker)
          erc-default-recipients '("#chan")
          erc-channel-users (make-hash-table :test #'equal)
          erc-server-process (with-current-buffer "foonet"
                               erc-server-process))
    (set-marker erc-insert-marker (point-max))
    (erc-display-prompt)))

(defun erc-fill-tests--setup ()
  (advice-add 'format-time-string :filter-args
              (lambda (args) (list (car args) (cadr args) 0)) '((name . ts)))

  (erc-stamp-mode +1)

  (erc-fill-tests--setup-server-buffer)
  (erc-fill-tests--setup-channel-buffer)
  (erc-fill-tests--populate))

(defun erc-fill-tests--populate ()
  (let* ((ts (+ (* 2 60 60 24) (* 60 60 24 365 10))) ; Jan 1 1980
         (ct (time-convert ts)))

    (cl-letf (((symbol-function 'current-time) (lambda () ct)))
      (with-current-buffer "foonet"
        (erc-fill-tests--insert ":irc.foonet.org 353 tester = #chan :"
                                "alice @bob robot tester")
        (erc-fill-tests--insert ":irc.foonet.org 366 tester #chan :"
                                "End of /NAMES list.")
        (erc-fill-tests--insert ":irc.foonet.org 324 tester #chan +nt")
        (erc-fill-tests--insert ":irc.foonet.org 329 tester #chan 1620104779")

        (setq ct (time-convert (cl-incf ts 60)))
        (erc-fill-tests--insert
         ":bob!~u@rz2v467q4rwhy.irc PRIVMSG #chan :lorem ipsum"
         " This buffer is for text that is not saved, and for Lisp evaluation.")

        (setq ct (time-convert (cl-incf ts 120)))
        (erc-fill-tests--insert
         ":alice!~u@rz2v467q4rwhy.irc PRIVMSG #chan :tester, welcome!"
         " Your name may or may not be highlighted depending on whether"
         " erc-button's been enabled by an earlier test. ERC needs help!")

        (erc-fill-tests--insert
         ":robot!~u@rz2v467q4rwhy.irc PRIVMSG #chan :・゜゜・。。・゜゜\\_o< QUACK!")

        (setq ct (time-convert (cl-incf ts (* 60 60 24))))
        (erc-fill-tests--insert
         ":bob!~u@rz2v467q4rwhy.irc PRIVMSG #chan :tester, welcome!"
         " To create a file, visit it with ? and enter text in its buffer.")))))

(defun erc-fill-tests--teardown ()
  (advice-remove 'format-time-string 'ts)
  (let (erc-kill-server-hook
        erc-kill-channel-hook)
    (kill-buffer "#chan")
    (kill-buffer "foonet"))
  (should (= erc-fill-column 78)))

(defun erc-fill-tests--compare (name)
  ;; Git didn't allow committing with a trailing space after the
  ;; prompt, hence this:
  (equal (substring-no-properties (buffer-string) 0 -1)
         (with-temp-buffer
           (insert-file-contents (ert-resource-file name))
           (buffer-string))))

(defun erc-fill-tests--await-fill ()
  (call-interactively #'erc-fill-buffer)
  (thread-join erc-fill--refill-thread))

(ert-deftest erc-fill-buffer ()
  (let (erc-insert-pre-hook
        erc-insert-modify-hook
        erc-send-modify-hook
        erc-mode-hook
        erc-stamp-mode)

    (erc-fill-tests--setup)

    (with-current-buffer "#chan"
      ;; These would get clobbered by the new thread if we let-bound
      ;; them, and we can't set them globally, so best just fake it:
      (setq-local erc-fill-mode t
                  erc-stamp-mode t
                  erc-fill-column 60)
      (erc-fill-tests--await-fill)
      (ert-info ("Baseline")
        (should (erc-fill-tests--compare "variable-60.buffer")))

      (ert-info ("Wider")
        (setq erc-fill-column 72)
        (erc-fill-tests--await-fill)
        (should (erc-fill-tests--compare "variable-72.buffer")))

      (ert-info ("Fancy")
        (setq erc-fill-function #'erc-fill-static)
        (erc-fill-tests--await-fill)
        (should (erc-fill-tests--compare "static-72.buffer")))

      (ert-info ("Fancy normal")
        (setq erc-fill-column 60)
        (erc-fill-tests--await-fill)
        (should (erc-fill-tests--compare "static-60.buffer")))

      (ert-info ("Again!")
        (erc-fill-tests--await-fill)
        (should (erc-fill-tests--compare "static-60.buffer")))

      (ert-info ("Back home")
        (setq erc-fill-function #'erc-fill-variable)
        (erc-fill-tests--await-fill)
        (should (erc-fill-tests--compare "variable-60.buffer")))))

  (when noninteractive
    (erc-fill-tests--teardown)))

(ert-deftest erc-fill-buffer--interrupted ()
  (let (erc-insert-pre-hook
        erc-insert-modify-hook
        erc-send-modify-hook
        erc-mode-hook
        erc-stamp-mode)

    (erc-fill-tests--setup)

    (with-current-buffer "#chan"
      (setq-local erc-fill-mode t ; see note re these in prev test
                  erc-stamp-mode t
                  erc-fill-column 60)
      (erc-fill-tests--await-fill)
      (ert-info ("Baseline")
        (should (erc-fill-tests--compare "variable-60.buffer")))

      (ert-info ("Denied while previous job in progress")
        (setq erc-fill-column 72)
        (erc-fill-tests--await-fill)
        (should (erc-fill-tests--compare "variable-72.buffer")))

      (ert-info ("Override switch cancels ongoing job")
        (setq erc-fill-column 60)
        (call-interactively #'erc-fill-buffer)
        (sleep-for (cl-random 0.1))
        (erc-fill-buffer t)
        (thread-join erc-fill--refill-thread)
        (should (erc-fill-tests--compare "variable-60.buffer")))

      (ert-info ("Thread variable cleared")
        (should-not erc-fill--refill-thread))))

  (when noninteractive
    (erc-fill-tests--teardown)))

;;; erc-fill-tests.el ends here

debug log:

solving ecd746196c ...
found ecd746196c in https://yhetil.org/emacs-bugs/871r2zt8g9.fsf__30822.935029731$1638191497$gmane$org@neverwas.me/
found a0b695a6c7 in https://yhetil.org/emacs-bugs/87fsrrqxcy.fsf__29180.3152345651$1637381603$gmane$org@neverwas.me/ ||
	https://yhetil.org/emacs-bugs/878rxdad2o.fsf@neverwas.me/
found a7e3d78d74 in https://yhetil.org/emacs-bugs/87o86gn8gs.fsf__23446.8106342078$1637291730$gmane$org@neverwas.me/ ||
	https://yhetil.org/emacs-bugs/87bl2gjuo9.fsf@neverwas.me/
found cf1b3ba78f in https://yhetil.org/emacs-bugs/87v90pzfgn.fsf__41738.4281916142$1637247311$gmane$org@neverwas.me/

applying [1/4] https://yhetil.org/emacs-bugs/87v90pzfgn.fsf__41738.4281916142$1637247311$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-fill-tests.el b/test/lisp/erc/erc-fill-tests.el
new file mode 100644
index 0000000000..cf1b3ba78f


applying [2/4] https://yhetil.org/emacs-bugs/87o86gn8gs.fsf__23446.8106342078$1637291730$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-fill-tests.el b/test/lisp/erc/erc-fill-tests.el
index cf1b3ba78f..a7e3d78d74 100644

Checking patch test/lisp/erc/erc-fill-tests.el...
Applied patch test/lisp/erc/erc-fill-tests.el cleanly.
Checking patch test/lisp/erc/erc-fill-tests.el...
Applied patch test/lisp/erc/erc-fill-tests.el cleanly.

skipping https://yhetil.org/emacs-bugs/87o86gn8gs.fsf__23446.8106342078$1637291730$gmane$org@neverwas.me/ for a7e3d78d74
skipping https://yhetil.org/emacs-bugs/87bl2gjuo9.fsf@neverwas.me/ for a7e3d78d74
index at:
100644 a7e3d78d74c21203c2fabf8e479c808767cdb891	test/lisp/erc/erc-fill-tests.el

applying [3/4] https://yhetil.org/emacs-bugs/87fsrrqxcy.fsf__29180.3152345651$1637381603$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-fill-tests.el b/test/lisp/erc/erc-fill-tests.el
index a7e3d78d74..a0b695a6c7 100644

Checking patch test/lisp/erc/erc-fill-tests.el...
Applied patch test/lisp/erc/erc-fill-tests.el cleanly.

skipping https://yhetil.org/emacs-bugs/87fsrrqxcy.fsf__29180.3152345651$1637381603$gmane$org@neverwas.me/ for a0b695a6c7
skipping https://yhetil.org/emacs-bugs/878rxdad2o.fsf@neverwas.me/ for a0b695a6c7
index at:
100644 a0b695a6c765294f8652004d638a77d764bde302	test/lisp/erc/erc-fill-tests.el

applying [4/4] https://yhetil.org/emacs-bugs/871r2zt8g9.fsf__30822.935029731$1638191497$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-fill-tests.el b/test/lisp/erc/erc-fill-tests.el
index a0b695a6c7..ecd746196c 100644

Checking patch test/lisp/erc/erc-fill-tests.el...
Applied patch test/lisp/erc/erc-fill-tests.el cleanly.

skipping https://yhetil.org/emacs-bugs/871r2zt8g9.fsf__30822.935029731$1638191497$gmane$org@neverwas.me/ for ecd746196c
index at:
100644 ecd746196cebe35309738dbf9a454027543ca5fb	test/lisp/erc/erc-fill-tests.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).