all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 935046198f3c7e7456e174d8f1df6f36b8484eb6 5202 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
 
;;; ediff-ptch-tests.el --- Tests for ediff-ptch.el  -*- lexical-binding:t -*-

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

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

;; 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)
(require 'ert-x)
(require 'ediff-ptch)

(ert-deftest ediff-ptch-test-bug25010 ()
  "Test for https://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 https://debbugs.gnu.org/26084 ."
  (skip-unless (executable-find "git"))
  (skip-unless (executable-find ediff-patch-program))
  (ert-with-temp-directory tmpdir
    (ert-with-temp-file patch
      (let* ((default-directory (file-name-as-directory tmpdir))
             (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")
        ;; Visit the diff file i.e., patch; extract from it the parts
        ;; affecting just each of the files: store in patch-bar the part
        ;; affecting 'bar', and in patch-qux the part affecting 'qux'.
        (find-file patch)
        (let* ((info
                (progn (ediff-map-patch-buffer (current-buffer)) ediff-patch-map))
               (patch-bar
                (buffer-substring-no-properties
                 (car (nth 3 (car info)))
                 (car (nth 4 (car info)))))
               (patch-qux
                (buffer-substring-no-properties
                 (car (nth 3 (cadr info)))
                 (car (nth 4 (cadr info))))))
          ;; Apply both patches.
          (dolist (x (list (cons patch-bar bar) (cons patch-qux qux)))
            (with-temp-buffer
              ;; Some windows variants require the option '--binary'
              ;; in order to 'patch' create backup files.
              (let ((opts (format "--backup%s"
                                  (if (memq system-type '(windows-nt ms-dos))
                                      " --binary" ""))))
                (insert (car x))
                (call-process-region (point-min)
                                     (point-max)
                                     ediff-patch-program
                                     nil nil nil
                                     opts (cdr x)))))
          ;; Check backup files were saved correctly; in Bug#26084 some
          ;; of the backup files are overwritten with the actual content
          ;; of the updated file.  To ensure that the bug is fixed we just
          ;; need to check that every backup file produced has different
          ;; content that the current updated file.
          (dolist (x (list qux bar))
            (let ((backup
                   (car
                    (directory-files
                     tmpdir 'full
                     (concat (file-name-nondirectory x) ".")))))
              ;; Compare files only if the backup has being created.
              (when backup
                (should-not
                 (string= (with-temp-buffer
                            (insert-file-contents x)
                            (buffer-string))
                          (with-temp-buffer
                            (insert-file-contents backup)
                            (buffer-string))))))))))))


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

debug log:

solving 935046198f ...
found 935046198f in https://git.savannah.gnu.org/cgit/emacs.git

(*) 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.