"Temporary directory for Tramp tests.")
(setq password-cache-expiry nil
+ shadow-debug nil
tramp-verbose 0
tramp-message-show-message nil)
(expand-file-name "shadow_todo_test" temporary-file-directory)
"File to store the list of uncopied shadows in during tests.")
+(defun shadow--tests-cleanup ()
+ "Reset all `shadowfile' internals."
+ ;; Delete auto-saved files.
+ (with-current-buffer (find-file-noselect shadow-info-file 'nowarn)
+ (ignore-errors (delete-file (make-auto-save-file-name)))
+ (set-buffer-modified-p nil)
+ (kill-buffer))
+ (with-current-buffer (find-file-noselect shadow-todo-file 'nowarn)
+ (ignore-errors (delete-file (make-auto-save-file-name)))
+ (set-buffer-modified-p nil)
+ (kill-buffer))
+ ;; Delete buffers.
+ (when (buffer-live-p shadow-info-buffer)
+ (with-current-buffer shadow-info-buffer
+ (set-buffer-modified-p nil)
+ (kill-buffer)))
+ (when (buffer-live-p shadow-todo-buffer)
+ (with-current-buffer shadow-todo-buffer
+ (set-buffer-modified-p nil)
+ (kill-buffer)))
+ ;; Delete files.
+ (ignore-errors (delete-file shadow-info-file))
+ (ignore-errors (delete-file shadow-todo-file))
+ ;; Reset variables.
+ (setq shadow-info-buffer nil
+ shadow-hashtable nil
+ shadow-todo-buffer nil
+ shadow-files-to-copy nil))
+
(ert-deftest shadow-test00-clusters ()
"Check cluster definitions.
Per definition, all files are identical on the different hosts of
((symbol-function 'read-string)
(lambda (&rest args) (pop mocked-input))))
- ;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
+ ;; Cleanup.
+ (shadow--tests-cleanup)
;; Define a cluster.
(setq cluster "cluster"
;; Cleanup.
(with-current-buffer (messages-buffer) (widen))
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file)))))
+ (shadow--tests-cleanup))))
(ert-deftest shadow-test01-sites ()
"Check site definitions.
(lambda (&rest args) (pop mocked-input))))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
+ (shadow--tests-cleanup)
;; Define a cluster.
(setq cluster1 "cluster1"
(shadow-site-match (shadow-site-primary cluster1) cluster2)))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file)))))
+ (shadow--tests-cleanup))))
(ert-deftest shadow-test02-files ()
"Check file manipulation functions."
(unwind-protect
(progn
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
+ (shadow--tests-cleanup)
;; Define a cluster.
(setq cluster "cluster"
(should-not (shadow-local-file nil)))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file)))))
+ (shadow--tests-cleanup))))
(ert-deftest shadow-test03-expand-cluster-in-file-name ()
"Check canonical file name of a cluster or site."
(unwind-protect
(progn
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
+ (shadow--tests-cleanup)
;; Define a cluster.
(setq cluster "cluster"
(concat primary file1))))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file)))))
+ (shadow--tests-cleanup))))
(ert-deftest shadow-test04-contract-file-name ()
"Check canonical file name of a cluster or site."
(unwind-protect
(progn
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
+ (shadow--tests-cleanup)
;; Define a cluster.
(setq cluster "cluster"
(concat "/cluster:" file))))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file)))))
+ (shadow--tests-cleanup))))
(ert-deftest shadow-test05-file-match ()
"Check `shadow-same-site' and `shadow-file-match'."
(unwind-protect
(progn
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
+ (shadow--tests-cleanup)
;; Define a cluster.
(setq cluster "cluster"
file)))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file)))))
+ (shadow--tests-cleanup))))
(ert-deftest shadow-test06-literal-groups ()
"Check literal group definitions."
(lambda (&rest args) (pop mocked-input))))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
+ (shadow--tests-cleanup)
;; Define clusters.
(setq cluster1 "cluster1"
mocked-input `(,cluster1 ,file1 ,cluster2 ,file2 ,(kbd "RET")))
(with-temp-buffer
(set-visited-file-name file1)
- (call-interactively 'shadow-define-literal-group))
+ (call-interactively 'shadow-define-literal-group)
+ (set-buffer-modified-p nil))
;; `shadow-literal-groups' is a list of lists.
(should (consp shadow-literal-groups))
(car shadow-literal-groups))))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file)))))
+ (shadow--tests-cleanup))))
(ert-deftest shadow-test07-regexp-groups ()
"Check regexp group definitions."
(lambda (&rest args) (pop mocked-input))))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
+ (shadow--tests-cleanup)
;; Define clusters.
(setq cluster1 "cluster1"
(car shadow-regexp-groups))))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file)))))
+ (shadow--tests-cleanup))))
(ert-deftest shadow-test08-shadow-todo ()
"Check that needed shadows are added to todo."
(unwind-protect
(progn
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
+ (shadow--tests-cleanup)
;; Define clusters.
(setq cluster1 "cluster1"
primary shadow-system-name
regexp (shadow-regexp-superquote primary))
(shadow-set-cluster cluster1 primary regexp)
+ (when shadow-debug
+ (message "%s %s %s %s" cluster1 primary regexp shadow-clusters))
(setq cluster2 "cluster2"
primary
(file-remote-p shadow-test-remote-temporary-file-directory)
regexp (shadow-regexp-superquote primary))
(shadow-set-cluster cluster2 primary regexp)
+ (when shadow-debug
+ (message "%s %s %s %s" cluster2 primary regexp shadow-clusters))
;; Define a literal group.
(setq file
(expand-file-name "shadowfile-tests" temporary-file-directory))
shadow-literal-groups
`((,(concat "/cluster1:" file) ,(concat "/cluster2:" file))))
+ (when shadow-debug
+ (message "%s %s" file shadow-literal-groups))
;; Save file from "cluster1" definition.
(with-temp-buffer
(set-visited-file-name file)
(insert "foo")
(save-buffer))
+ (when shadow-debug
+ (message
+ "%s %s"
+ (cons file (shadow-contract-file-name (concat "/cluster2:" file)))
+ shadow-files-to-copy))
(should
(member
(cons file (shadow-contract-file-name (concat "/cluster2:" file)))
(set-visited-file-name (concat (shadow-site-primary cluster2) file))
(insert "foo")
(save-buffer))
+ (when shadow-debug
+ (message
+ "%s %s"
+ (cons
+ (concat (shadow-site-primary cluster2) file)
+ (shadow-contract-file-name (concat "/cluster1:" file)))
+ shadow-files-to-copy))
(should
(member
(cons
(shadow-regexp-superquote file))
,(concat (shadow-site-primary cluster2)
(shadow-regexp-superquote file)))))
+ (when shadow-debug
+ (message "%s %s" file shadow-regexp-groups))
;; Save file from "cluster1" definition.
(with-temp-buffer
(set-visited-file-name file)
(insert "foo")
(save-buffer))
+ (when shadow-debug
+ (message
+ "%s %s"
+ (cons file (shadow-contract-file-name (concat "/cluster2:" file)))
+ shadow-files-to-copy))
(should
(member
(cons file (shadow-contract-file-name (concat "/cluster2:" file)))
(set-visited-file-name (concat (shadow-site-primary cluster2) file))
(insert "foo")
(save-buffer))
+ (when shadow-debug
+ (message
+ "%s %s"
+ (cons
+ (concat (shadow-site-primary cluster2) file)
+ (shadow-contract-file-name (concat "/cluster1:" file)))
+ shadow-files-to-copy))
(should
(member
(cons
shadow-files-to-copy)))
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
- (ignore-errors
- (when (file-exists-p file)
- (delete-file file)))
- (ignore-errors
- (when (file-exists-p (concat (shadow-site-primary cluster2) file))
- (delete-file (concat (shadow-site-primary cluster2) file)))))))
+ (ignore-errors (delete-file file))
+ (ignore-errors (delete-file (concat (shadow-site-primary cluster2) file)))
+ (shadow--tests-cleanup))))
(ert-deftest shadow-test09-shadow-copy-files ()
"Check that needed shadow files are copied."
(unwind-protect
(progn
;; Cleanup.
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
- (when (buffer-live-p shadow-todo-buffer)
- (with-current-buffer shadow-todo-buffer (erase-buffer)))
+ (shadow--tests-cleanup)
;; Define clusters.
(setq cluster1 "cluster1"
;; Cleanup.
(remove-function (symbol-function 'write-region) "write-region-mock")
- (when (file-exists-p shadow-info-file)
- (delete-file shadow-info-file))
- (when (file-exists-p shadow-todo-file)
- (delete-file shadow-todo-file))
- (ignore-errors
- (when (file-exists-p file)
- (delete-file file)))
- (ignore-errors
- (when (file-exists-p (concat (shadow-site-primary cluster2) file))
- (delete-file (concat (shadow-site-primary cluster2) file)))))))
+ (ignore-errors (delete-file file))
+ (ignore-errors (delete-file (concat (shadow-site-primary cluster2) file)))
+ (shadow--tests-cleanup))))
(defun shadowfile-test-all (&optional interactive)
"Run all tests for \\[shadowfile]."
(let ((shadow-info-file shadow-test-info-file)
(shadow-todo-file shadow-test-todo-file))
+ (shadow--tests-cleanup)
(shadow-initialize))
(provide 'shadowfile-tests)