all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 74db053c97e01dabc210501fa2b18d6b5f589692 11510 bytes (raw)
name: test/lisp/vc/ediff-ptch-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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
 
;;; ediff-ptch-tests.el --- Tests for ediff-ptch.el

;; Copyright (C) 2016-2017 Free Software Foundation, Inc.

;; Author: Tino Calancha <tino.calancha@gmail.com>

;; This program 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.
;;
;; This program 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 this program.  If not, see `http://www.gnu.org/licenses/'.

;;; Code:

(require 'ert)
(require 'ediff-ptch)
(require 'ediff-diff) ; For `ediff-diff-program'.
(eval-when-compile (require 'cl-lib))

(ert-deftest ediff-ptch-test-bug25010 ()
  "Test for http://debbugs.gnu.org/25010 ."
  (with-temp-buffer
    (insert "diff --git a/lisp/vc/ediff-ptch.el b/lisp/vc/ediff-ptch.el
index 6a07f80..6e8e947 100644
--- a/lisp/vc/ediff-ptch.el
+++ b/lisp/vc/ediff-ptch.el
@@ -120,11 +120,12 @@ ediff-patch-default-directory
")
    (goto-char (point-min))
    (let ((filename
           (progn
             (re-search-forward ediff-context-diff-label-regexp nil t)
             (match-string 1))))
      (should-not (string-suffix-p "@@" filename)))))


(ert-deftest ediff-ptch-test-bug26084 ()
  "Test for http://debbugs.gnu.org/26084 ."
  (skip-unless (executable-find "git"))
  (skip-unless (executable-find ediff-patch-program))
  (let* ((tmpdir (make-temp-file "ediff-ptch-test" t))
         (default-directory (file-name-as-directory tmpdir))
         (patch (make-temp-file "ediff-ptch-test"))
         (qux (expand-file-name "qux.txt" tmpdir))
         (bar (expand-file-name "bar.txt" tmpdir))
         (git-program (executable-find "git")))
    ;; Create repository.
    (with-temp-buffer
      (insert "qux here\n")
      (write-region nil nil qux nil 'silent)
      (erase-buffer)
      (insert "bar here\n")
      (write-region nil nil bar nil 'silent))
    (call-process git-program nil nil nil "init")
    (call-process git-program nil nil nil "add" ".")
    (call-process git-program nil nil nil "commit" "-m" "Test repository.")
    ;; Update repo., save the diff and reset to initial state.
    (with-temp-buffer
      (insert "foo here\n")
      (write-region nil nil qux nil 'silent)
      (write-region nil nil bar nil 'silent))
    (call-process git-program nil `(:file ,patch) nil "diff")
    (call-process git-program nil nil nil "reset" "--hard" "HEAD")
    (find-file patch)
    (unwind-protect
        (let* ((info
                (progn (ediff-map-patch-buffer (current-buffer)) ediff-patch-map))
               (patch1
                (buffer-substring-no-properties
                 (car (nth 3 (car info)))
                 (car (nth 4 (car info)))))
               (patch2
                (buffer-substring-no-properties
                 (car (nth 3 (cadr info)))
                 (car (nth 4 (cadr info))))))
          ;; Apply both patches.
          (dolist (x (list (cons patch1 bar) (cons patch2 qux)))
            (with-temp-buffer
              (insert (car x))
              (call-process-region (point-min)
                                   (point-max)
                                   ediff-patch-program
                                   nil nil nil
                                   "-b" (cdr x))))
          ;; Check backup files were saved correctly.
          (dolist (x (list qux bar))
            (let ((backup
                   (car
                    (directory-files
                     tmpdir 'full
                     (concat (file-name-nondirectory x) ".")))))
              (should-not
               (string= (with-temp-buffer
                          (insert-file-contents x)
                          (buffer-string))
                        (with-temp-buffer
                          (insert-file-contents backup)
                          (buffer-string))))))
          (delete-directory tmpdir 'recursive)
          (delete-file patch)))))

(ert-deftest ediff-ptch-test-bug26028 ()
  "Test for http://debbugs.gnu.org/26028 ."
  (skip-unless (executable-find "git"))
  (skip-unless (executable-find ediff-patch-program))
  (skip-unless (executable-find ediff-diff-program))
  (let ((git-program (executable-find "git"))
        (default-dir default-directory)
        tmpdir buffers)
    ;;; Simple patch: old/src/hello.c /new/src/hello.c
    (unwind-protect
        (let* ((dir (make-temp-file "multipatch-test" t))
               (file1 (expand-file-name "old/src/hello.c" dir))
               (file2 (expand-file-name "new/src/hello.c" dir))
               (patch (expand-file-name "tmp.patch" dir))
               (default-directory (file-name-as-directory dir)))
          (setq tmpdir dir)
          (make-directory (expand-file-name "old/src/" dir) 'parents)
          (make-directory (expand-file-name "new/src/" dir) 'parents)
          (with-temp-buffer
            (insert "void main() { }\n")
            (write-region nil nil file1 nil 'silent)
            (erase-buffer)
            (insert "int main() { return 0; }\n")
            (write-region nil nil file2 nil 'silent)
            (erase-buffer)
            (call-process ediff-diff-program nil t nil "-cr" "old" "new")
            (write-region nil nil patch nil 'silent)
            (cl-letf (((symbol-function 'y-or-n-p) (lambda (x) nil))
                      ((symbol-function 'ediff-prompt-for-patch-file)
                       (lambda (&rest x) (find-file-noselect patch)))
                      ((symbol-function 'read-file-name) (lambda (x1 x2 x3 x4 x5) x5))
                      ((symbol-function 'ediff-dispatch-file-patching-job)
                       (lambda (x y) y)))
              (should (equal (file-relative-name file1) (epatch nil patch)))
              (push (get-file-buffer patch) buffers))))
      (when (file-exists-p tmpdir)
        (setq default-directory default-dir)
        (delete-directory tmpdir 'recursive))
      (mapc (lambda (b)
              (when (buffer-live-p b) (kill-buffer b)))
            buffers)
      (setq buffers nil))
    ;;; Simple Git patch: proj/src/hello.c
    (unwind-protect
        (let* ((dir (make-temp-file "multipatch-test" t))
               (rootdir (expand-file-name "proj/src/" dir))
               (file (expand-file-name "hello.c" rootdir))
               (patch (expand-file-name "tmp.patch" dir))
               (default-directory (file-name-as-directory rootdir)))
          (make-directory rootdir 'parents)
          (setq tmpdir dir)
          (with-temp-buffer
            (insert "void main() { }\n")
            (write-region nil nil file nil 'silent)
            (call-process git-program nil nil nil "init")
            (call-process git-program nil nil nil "add" ".")
            (call-process git-program nil nil nil "commit" "-m" "test repository.")
            (erase-buffer)
            (insert "int main() { return 0; }\n")
            (write-region nil nil file nil 'silent)
            (call-process git-program nil `(:file ,patch) nil "diff")
            (call-process git-program nil nil nil "reset" "--hard" "head")
            (cl-letf (((symbol-function 'y-or-n-p) (lambda (x) nil))
                      ((symbol-function 'ediff-prompt-for-patch-file)
                       (lambda (&rest x) (find-file-noselect patch)))
                      ((symbol-function 'read-file-name) (lambda (&rest x) file))
                      ((symbol-function 'read-file-name) (lambda (x1 x2 x3 x4 x5) x5))
                      ((symbol-function 'ediff-dispatch-file-patching-job)
                       (lambda (x y) y)))
              (should (equal file (epatch nil patch)))))
          (push (get-file-buffer patch) buffers))
      ;; clean up
      (when (file-exists-p tmpdir)
        (setq default-directory default-dir)
        (delete-directory tmpdir 'recursive))
      (mapc (lambda (b)
              (when (buffer-live-p b) (kill-buffer b)))
            buffers)
      (setq buffers nil))
    ;;; Git multipatch.
    (unwind-protect
        (let* ((dir (make-temp-file "multipatch-test" t))
               (file1 (expand-file-name "proj/src/hello.c" dir))
               (file2 (expand-file-name "proj/src/bye.c" dir))
               (file3 (expand-file-name "proj/lisp/foo.el" dir))
               (file4 (expand-file-name "proj/lisp/bar.el" dir))
               (file5 (expand-file-name "proj/etc/news" dir))
               (patch (expand-file-name "tmp.patch" dir))
               (default-directory (expand-file-name "proj" dir)))
          (setq tmpdir dir)
          (dolist (d '("src" "lisp" "etc"))
            (setq rootdir (expand-file-name (concat "proj/" d) dir))
            (make-directory rootdir 'parents))
          (with-temp-buffer
            (insert "void main() { }\n")
            (write-region nil nil file1 nil 'silent)
            (write-region nil nil file2 nil 'silent)
            (erase-buffer)
            (insert "(defun foo () nil)\n")
            (write-region nil nil file3 nil 'silent)
            (erase-buffer)
            (insert "(defun bar () nil)\n")
            (write-region nil nil file4 nil 'silent)
            (erase-buffer)
            (insert "new functions 'foo' and 'bar'\n")
            (write-region nil nil file5 nil 'silent)
            (call-process git-program nil nil nil "init")
            (call-process git-program nil nil nil "add" "src" "lisp" "etc")
            (call-process git-program nil nil nil "commit" "-m" "test repository.");)
            (erase-buffer)
            (insert "int main() { return 0;}\n")
            (write-region nil nil file1 nil 'silent)
            (write-region nil nil file2 nil 'silent)
            (erase-buffer)
            (insert "(defun qux () nil)\n")
            (write-region nil nil file3 nil 'silent)
            (erase-buffer)
            (insert "(defun quux () nil)\n")
            (write-region nil nil file4 nil 'silent)
            (erase-buffer)
            (insert "new functions 'qux' and 'quux'\n")
            (write-region nil nil file5 nil 'silent)
            (call-process git-program nil `(:file ,patch) nil "diff")
            (call-process git-program nil nil nil "reset" "--hard" "head"))
          (cl-letf (((symbol-function 'y-or-n-p) (lambda (x) nil))
                    ((symbol-function 'ediff-get-patch-file) (lambda (&rest x) patch))
                    ((symbol-function 'read-file-name) (lambda (&rest x) patch)))
            (epatch nil patch)
            (with-current-buffer "*Ediff Session Group Panel*"
              (push (get-file-buffer patch) buffers)
              (should (= 5 (length (cdr ediff-meta-list))))
              ;; don't ask confirmation to exit.
              (cl-letf (((symbol-function 'y-or-n-p) (lambda (x) t)))
                (ediff-quit-meta-buffer)))))
      ;; clean up
      (when (file-exists-p tmpdir)
        (setq default-directory default-dir)
        (delete-directory tmpdir 'recursive))
      (when ediff-registry-buffer
        (push ediff-registry-buffer buffers))
      (mapc (lambda (b)
              (when (buffer-live-p b) (kill-buffer b)))
            buffers)
      (setq buffers nil))))


(provide 'ediff-ptch-tests)
;;; ediff-ptch-tests.el ends here

debug log:

solving 74db053c97 ...
found 74db053c97 in https://yhetil.org/emacs/871srfbyps.fsf@calancha-pc/
found 387786ced0 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 387786ced06e7d521c12f32f8675b57e2aadc9f1	test/lisp/vc/ediff-ptch-tests.el

applying [1/1] https://yhetil.org/emacs/871srfbyps.fsf@calancha-pc/
diff --git a/test/lisp/vc/ediff-ptch-tests.el b/test/lisp/vc/ediff-ptch-tests.el
index 387786ced0..74db053c97 100644

Checking patch test/lisp/vc/ediff-ptch-tests.el...
Applied patch test/lisp/vc/ediff-ptch-tests.el cleanly.

index at:
100644 74db053c97e01dabc210501fa2b18d6b5f589692	test/lisp/vc/ediff-ptch-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 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.