summaryrefslogtreecommitdiff
path: root/test/lisp/vc/ediff-ptch-tests.el
blob: aecfe30d9470096ab6ffe3bb0f900ec9efdbb102 (plain)
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
;;; 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)

(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)))
    (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" nil nil nil "init")
    (call-process "git" nil nil nil "add" ".")
    (call-process "git" nil nil nil "commit" "-m" "Test repository.")
    (with-temp-buffer
      (insert "foo here\n")
      (write-region nil nil qux nil 'silent)
      (write-region nil nil bar nil 'silent))
    (call-process "git" nil `(:file ,patch) nil "diff")
    (call-process "git" 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-shell-region (point-min)
                                 (point-max)
                                 (format "%s %s %s %s"
                                         ediff-patch-program
                                         ediff-patch-options
                                         ediff-backup-specs
                                         (cdr x)))))
          ;; Check backup files were saved correctly.
          (dolist (x (list qux bar))
            (should-not (string= (with-temp-buffer
                                   (insert-file-contents x)
                                   (buffer-string))
                                 (with-temp-buffer
                                   (insert-file-contents (concat x ediff-backup-extension))
                                   (buffer-string))))))
      (delete-directory tmpdir 'recursive)
      (delete-file patch))))


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