Commit db5d38dd authored by Tino Calancha's avatar Tino Calancha
Browse files

Fix 2 tests that fail in MS-Windows
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug26084):
Add comments to explain the test logic.
Pass '--binary' option to 'patch' program in windows environments.
Check explicitely that a backup is created before compare file contents.

* test/lisp/dired-tests.el (dired-test-bug25609):
Declare variable 'dired-dwim-target' right before the test.
Add comments to explain the test logic.
Ensure, before test the bug condition, that we are displaying the
2 dired buffers created in this test, and no other dired buffer
is shown.
parent 28e00043
......@@ -54,6 +54,7 @@
(when (buffer-live-p buf) (kill-buffer buf)))
(delete-directory dir 'recursive))))
(defvar dired-dwim-target)
(ert-deftest dired-test-bug25609 ()
"Test for ."
(let* ((from (make-temp-file "foo" 'dir))
......@@ -67,20 +68,30 @@
(lambda (_sym _prompt &rest _args) (setq dired-query t))
'((name . "advice-dired-query")))
(advice-add 'completing-read ; Just return init.
(advice-add 'completing-read ; Don't prompt me: just return init.
(lambda (_prompt _coll &optional _pred _match init _hist _def _inherit _keymap)
'((name . "advice-completing-read")))
(delete-other-windows) ; We don't want to display any other dired buffers.
(push (dired to) buffers)
(push (dired-other-window temporary-file-directory) buffers)
(dired-goto-file from)
(dired-do-copy); Again.
(should (file-exists-p target))
(should-not (file-exists-p nested)))
(let ((ok-fn
(lambda ()
(let ((win-buffers (mapcar #'window-buffer (window-list))))
(and (memq (car buffers) win-buffers)
(memq (cadr buffers) win-buffers))))))
(dired-goto-file from)
;; Right before `dired-do-copy' call, to reproduce the bug conditions,
;; ensure we have windows displaying the two dired buffers.
(and (funcall ok-fn) (dired-do-copy))
;; Call `dired-do-copy' again: this must overwrite `target'; if the bug
;; still exists, then it creates `nested' instead.
(when (funcall ok-fn)
(should (file-exists-p target))
(should-not (file-exists-p nested))))
(dolist (buf buffers)
(when (buffer-live-p buf) (kill-buffer buf)))
(delete-directory from 'recursive)
......@@ -66,41 +66,55 @@ index 6a07f80..6e8e947 100644
(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))
(car (nth 3 (car info)))
(car (nth 4 (car info)))))
(car (nth 3 (cadr info)))
(car (nth 4 (cadr info))))))
;; Apply both patches.
(dolist (x (list (cons patch1 bar) (cons patch2 qux)))
(dolist (x (list (cons patch-bar bar) (cons patch-qux qux)))
(insert (car x))
(call-process-region (point-min)
nil nil nil
"-b" (cdr x))))
;; Check backup files were saved correctly.
;; 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)
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
tmpdir 'full
(concat (file-name-nondirectory x) ".")))))
(string= (with-temp-buffer
(insert-file-contents x)
(insert-file-contents backup)
;; Compare files only if the backup has being created.
(when backup
(string= (with-temp-buffer
(insert-file-contents x)
(insert-file-contents backup)
(delete-directory tmpdir 'recursive)
(delete-file patch)))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment