unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 9d3116d3db3a43c38bc42bb5f7e492a41a5fcb26 8201 bytes (raw)
name: test/lisp/erc/erc-scenarios-log.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
 
;;; erc-scenarios-log.el --- erc-log scenarios -*- lexical-binding: t -*-

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

;;; Commentary:

;;; Code:

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

(require 'erc-log)
(require 'erc-truncate)

(defvar erc-timestamp-format-left)

(ert-deftest erc-scenarios-log--kill-hook ()
  :tags '(:expensive-test)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/assoc/bouncer-history")
       (dumb-server (erc-d-run "localhost" t 'foonet))
       (tempdir (make-temp-file "erc-tests-log." t nil nil))
       (erc-log-channels-directory tempdir)
       (erc-modules (cons 'log erc-modules))
       (port (process-contact dumb-server :service))
       (logfile (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port)
                                  tempdir))
       (erc-server-flood-penalty 0.1)
       (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")
        (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
        (funcall expect 5 "foonet")))

    (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan"))
      (funcall expect 10 "was created on")
      (funcall expect 10 "please your lordship")
      (with-current-buffer "foonet"
        (delete-process erc-server-process)
        (funcall expect 5 "failed"))
      (should-not (file-exists-p logfile))
      (kill-buffer)
      (should (file-exists-p logfile)))

    (with-temp-buffer
      (insert-file-contents logfile)
      (funcall expect 1 "You have joined")
      (funcall expect 1 "Playback Complete.")
      (funcall expect 1 "please your lordship"))

    (erc-log-mode -1)
    (if noninteractive
        (delete-directory tempdir :recursive)
      (add-hook 'kill-emacs-hook
                (lambda () (delete-directory tempdir :recursive))))))

;; This shows that, in addition to truncating the buffer, /clear also
;; syncs the log.

(ert-deftest erc-scenarios-log--clear-stamp ()
  :tags '(:expensive-test)
  (require 'erc-stamp)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/assoc/bouncer-history")
       (dumb-server (erc-d-run "localhost" t 'foonet))
       (tempdir (make-temp-file "erc-tests-log." t nil nil))
       (erc-log-channels-directory tempdir)
       (erc-modules (cons 'log erc-modules))
       (erc-timestamp-format-left "\n[%a %b %e %Y @@STAMP@@]\n")
       (port (process-contact dumb-server :service))
       (logfile (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port)
                                  tempdir))
       (erc-server-flood-penalty 0.1)
       (expect (erc-d-t-make-expecter)))

    (unless noninteractive
      (add-hook 'kill-emacs-hook
                (lambda () (delete-directory tempdir :recursive))))

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

    (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan"))
      (funcall expect 10 "@@STAMP@@")
      (funcall expect 10 "Grows, lives")
      (should-not (file-exists-p logfile))
      (goto-char (point-max))
      (erc-cmd-CLEAR)
      (should (file-exists-p logfile))
      (funcall expect 10 "please your lordship")
      (ert-info ("Buffer truncated")
        (goto-char (point-min))
        (funcall expect 10 "@@STAMP@@" (point)) ; reset
        (funcall expect -0.1 "Grows, lives")
        (funcall expect 1 "For these two")))

    (ert-info ("Current contents saved")
      (with-temp-buffer
        (insert-file-contents logfile)
        (funcall expect 1 "@@STAMP@@")
        (funcall expect 1 "You have joined")
        (funcall expect 1 "Playback Complete.")
        (funcall expect 1 "Grows, lives")
        (funcall expect -0.01 "please your lordship")))

    (ert-info ("Remainder saved, timestamp printed when option non-nil")
      (with-current-buffer "foonet"
        (delete-process erc-server-process)
        (funcall expect 5 "failed"))
      (kill-buffer "#chan")
      (with-temp-buffer
        (insert-file-contents logfile)
        (funcall expect 1 "@@STAMP@@")
        (funcall expect 1 "Grows, lives")
        (funcall expect -0.01 "@@STAMP@@")
        (forward-line 1) ; no blank, no timestamp
        (should (looking-at (rx "<bob> alice: For these two hours,")))
        (funcall expect 1 "please your lordship")))

    (erc-log-mode -1)
    (when noninteractive (delete-directory tempdir :recursive))))

(ert-deftest erc-scenarios-log--truncate ()
  :tags '(:expensive-test)
  (erc-scenarios-common-with-cleanup
      ((erc-scenarios-common-dialog "base/assoc/bouncer-history")
       (dumb-server (erc-d-run "localhost" t 'foonet))
       (tempdir (make-temp-file "erc-tests-log." t nil nil))
       (erc-log-channels-directory tempdir)
       (erc-modules (cons 'truncate (cons 'log erc-modules)))
       (erc-max-buffer-size 512)
       (port (process-contact dumb-server :service))
       (logchan (expand-file-name (format "#chan!tester@127.0.0.1:%d.txt" port)
                                  tempdir))
       (logserv (expand-file-name
                 (format "127.0.0.1:%d!tester@127.0.0.1:%d.txt" port port)
                 tempdir))
       (erc-server-flood-penalty 0.1)
       (expect (erc-d-t-make-expecter)))

    (unless noninteractive
      (add-hook 'kill-emacs-hook
                (lambda () (delete-directory tempdir :recursive))))

    (ert-info ("Connect to foonet")
      (with-current-buffer (erc :server "127.0.0.1"
                                :port port
                                :nick "tester"
                                :password "foonet:changeme"
                                :full-name "tester")
        (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
        (should-not (file-exists-p logserv))
        (should-not (file-exists-p logchan))
        (funcall expect 10 "*** MAXLIST=beI:60")
        (erc-d-t-wait-for 5 (= (pos-bol) (point-min)))
        (should (file-exists-p logserv))))

    (ert-info ("Log file ahead of truncation point")
      ;; Log contains lines still present in buffer.
      (with-temp-buffer
        (insert-file-contents logserv)
        (funcall expect 10 "*** MAXLIST=beI:60")))

    (with-current-buffer (erc-d-t-wait-for 5 (get-buffer "#chan"))
      (funcall expect 10 "please your lordship")
      (should (file-exists-p logchan))
      (funcall expect -0.1 "[07:04:37] alice: Here," (point-min)))

    (ert-info ("Log ahead of truncation point")
      (with-temp-buffer
        (insert-file-contents logchan)
        (funcall expect 1 "You have joined")
        (funcall expect 1 "[07:04:37] alice: Here,")
        (funcall expect 1 "loathed enemy")
        (funcall expect -0.1 "please your lordship")))

    (erc-log-mode -1)
    (erc-truncate-mode -1)
    (when noninteractive (delete-directory tempdir :recursive))))

;;; erc-scenarios-log.el ends here

debug log:

solving 9d3116d3db3 ...
found 9d3116d3db3 in https://yhetil.org/emacs-bugs/8734yak6dr.fsf__37907.4987302133$1697465338$gmane$org@neverwas.me/
found f7e7d61c92e in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 f7e7d61c92e9a5551bfd6058112518a3535b118a	test/lisp/erc/erc-scenarios-log.el

applying [1/1] https://yhetil.org/emacs-bugs/8734yak6dr.fsf__37907.4987302133$1697465338$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-scenarios-log.el b/test/lisp/erc/erc-scenarios-log.el
index f7e7d61c92e..9d3116d3db3 100644

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

index at:
100644 9d3116d3db3a43c38bc42bb5f7e492a41a5fcb26	test/lisp/erc/erc-scenarios-log.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).