unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 126a1b5287b71215fff2ebf8bb076743ec87c471 6812 bytes (raw)
name: test/lisp/erc/erc-dcc-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
 
;;; erc-dcc-tests.el --- Tests for erc-dcc  -*- lexical-binding:t -*-

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

(ert-deftest erc-dcc-ctcp-query-send-regexp ()
  (let ((s "DCC SEND \"file name\" 2130706433 9899 1405135128"))
    (should (string-match erc-dcc-ctcp-query-send-regexp s))
    (should-not (match-string 2 s))
    (should (string= "file name" (match-string 1 s)))
    (should (string= "SEND" (match-string 6 s))))
  (let ((s "DCC SEND \"file \\\" name\" 2130706433 9899 1405135128"))
    (should (string-match erc-dcc-ctcp-query-send-regexp s))
    (should-not (match-string 2 s))
    (should (string= "SEND" (match-string 6 s)))
    (should (string= "file \" name"
                     (erc-dcc-unquote-filename (match-string 1 s)))))
  (let ((s "DCC SEND filename 2130706433 9899 1405135128"))
    (should (string-match erc-dcc-ctcp-query-send-regexp s))
    (should (string= "filename" (match-string 2 s)))
    (should (string= "2130706433" (match-string 3 s)))
    (should (string= "9899" (match-string 4 s)))
    (should (string= "1405135128" (match-string 5 s))))
  (let ((s "DCC TSEND filename 2130706433 9899 1405135128"))
    (should (string-match erc-dcc-ctcp-query-send-regexp s))
    (should (string= "TSEND" (match-string 6 s)))))

;; This also indirectly tests base functionality for
;; `erc-dcc-do-LIST-command'

(defun erc-dcc-tests--dcc-handle-ctcp-send (turbo)
  (with-current-buffer (get-buffer-create "fake-server")
    (erc-mode)
    (setq erc-server-process
          (start-process "fake" (current-buffer) "sleep" "1")
          erc-input-marker (make-marker)
          erc-insert-marker (make-marker)
          erc-server-current-nick "dummy")
    (set-process-query-on-exit-flag erc-server-process nil)
    (should-not erc-dcc-list)
    (erc-ctcp-query-DCC erc-server-process
                        "tester"
                        "~tester"
                        "fake.irc"
                        "dummy"
                        (concat "DCC " (if turbo "TSEND" "SEND")
                                " foo 2130706433 9899 1405135128"))
    (should-not (cdr erc-dcc-list))
    (should (equal (plist-put (car erc-dcc-list) :parent 'fake)
                   `(:nick "tester!~tester@fake.irc"
                           :type GET
                           :peer nil
                           :parent fake
                           :ip "127.0.0.1"
                           :port "9899"
                           :file "foo"
                           :size 1405135128
                           :turbo ,(and turbo t)
                           :secure nil)))
    (goto-char (point-min))
    (should (search-forward "file foo offered by tester" nil t))
    (erc-dcc-do-LIST-command erc-server-process)
    (should (search-forward-regexp (concat
                                    "GET +no +1405135128 +foo"
                                    (and turbo " +(T)") "$")
                                   nil t))
    (when noninteractive
      (let (erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
        (kill-buffer))))
  ;; `erc-dcc-list' is global; must leave it empty
  (should erc-dcc-list)
  (setq erc-dcc-list nil))

(ert-deftest erc-dcc-handle-ctcp-send--base ()
  (erc-dcc-tests--dcc-handle-ctcp-send nil))

(ert-deftest erc-dcc-handle-ctcp-send--turbo ()
  (erc-dcc-tests--dcc-handle-ctcp-send t))

(ert-deftest erc-dcc-do-GET-command ()
  (with-temp-buffer
    (let* ((proc (start-process "fake" (current-buffer) "sleep" "1"))
           erc-accidental-paste-threshold-seconds
           erc-send-completed-hook
           erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook
           (elt `(:nick "tester!~tester@fake.irc"
                        :type GET
                        :peer nil
                        :parent ,proc
                        :ip "127.0.0.1"
                        :port "9899"
                        :file "foo.bin"
                        :size 1405135128))
           (erc-dcc-list (list elt))
           ;;
           calls)
      (erc-mode)
      (setq erc-server-process proc
            erc-input-marker (make-marker)
            erc-insert-marker (make-marker)
            erc-server-current-nick "dummy")
      (set-process-query-on-exit-flag proc nil)
      (cl-letf (((symbol-function 'read-file-name)
                 (lambda (&rest _) "foo.bin"))
                ((symbol-function 'erc-dcc-get-file)
                 (lambda (&rest r) (push r calls))))
        (goto-char (point-max))
        (set-marker erc-insert-marker (point-max))
        (erc-display-prompt)

        (ert-info ("No turbo")
          (should-not (plist-member elt :turbo))
          (goto-char erc-input-marker)
          (insert "/dcc GET tester foo.bin")
          (erc-send-current-line)
          (should-not (plist-member (car erc-dcc-list) :turbo))
          (should (equal (pop calls) (list elt "foo.bin" proc))))

        (ert-info ("Arg turbo in pos 2")
          (should-not (plist-member elt :turbo))
          (goto-char erc-input-marker)
          (insert "/dcc GET -t tester foo.bin")
          (erc-send-current-line)
          (should (eq t (plist-get (car erc-dcc-list) :turbo)))
          (should (equal (pop calls) (list elt "foo.bin" proc))))

        (ert-info ("Arg turbo in pos 4")
          (setq elt (plist-put elt :turbo nil)
                erc-dcc-list (list elt))
          (goto-char erc-input-marker)
          (insert "/dcc GET tester -t foo.bin")
          (erc-send-current-line)
          (should (eq t (plist-get (car erc-dcc-list) :turbo)))
          (should (equal (pop calls) (list elt "foo.bin" proc))))

        (ert-info ("Arg turbo in pos 6")
          (setq elt (plist-put elt :turbo nil)
                erc-dcc-list (list elt))
          (goto-char erc-input-marker)
          (insert "/dcc GET tester foo.bin -t")
          (erc-send-current-line)
          (should (eq t (plist-get (car erc-dcc-list) :turbo)))
          (should (equal (pop calls) (list elt "foo.bin" proc))))))))

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

debug log:

solving 126a1b5287 ...
found 126a1b5287 in https://yhetil.org/emacs-bugs/874k22zu7s.fsf__15427.6849397988$1651842659$gmane$org@neverwas.me/
found 64ca3363c7 in https://yhetil.org/emacs-bugs/87ilqqy9km.fsf__3168.70862604759$1651328077$gmane$org@neverwas.me/

applying [1/2] https://yhetil.org/emacs-bugs/87ilqqy9km.fsf__3168.70862604759$1651328077$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-dcc-tests.el b/test/lisp/erc/erc-dcc-tests.el
new file mode 100644
index 0000000000..64ca3363c7

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

skipping https://yhetil.org/emacs-bugs/87ilqqy9km.fsf__3168.70862604759$1651328077$gmane$org@neverwas.me/ for 64ca3363c7
index at:
100644 64ca3363c783c0ea9642efc0c9bc1ffe3489969b	test/lisp/erc/erc-dcc-tests.el

applying [2/2] https://yhetil.org/emacs-bugs/874k22zu7s.fsf__15427.6849397988$1651842659$gmane$org@neverwas.me/
diff --git a/test/lisp/erc/erc-dcc-tests.el b/test/lisp/erc/erc-dcc-tests.el
index 64ca3363c7..126a1b5287 100644

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

skipping https://yhetil.org/emacs-bugs/874k22zu7s.fsf__15427.6849397988$1651842659$gmane$org@neverwas.me/ for 126a1b5287
index at:
100644 126a1b5287b71215fff2ebf8bb076743ec87c471	test/lisp/erc/erc-dcc-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).