1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-29 07:58:28 +00:00

* automated/tramp-tests.el (tramp--test-enabled): Move connection

cleanup into this function.  Remove respective code from all test cases.
(tramp--instrument-test-case): Declare `indent' and `debug'.
Handle other errors as well.
(tramp-test14-delete-directory): Check for `file-error' error.
(tramp-test15-copy-directory): Ignore return value of
`copy-directory'.  It's too much hassle to handle it for tramp-adb.el.
(tramp-test19-directory-files-and-attributes): Take care of
timestamp of "../".
(tramp-test20-file-modes, tramp-test27-start-file-process)
(tramp-test28-shell-command): Skip for tramp-adb.el.
(tramp-test21-file-links): `file-truename' shall preserve trailing
link of directories.
(tramp-test22-file-times): Skip if `set-file-times' returns nil.
(tramp-test26-process-file, tramp-test28-shell-command): Let-bind
`kill-buffer-query-functions' to nil.
(tramp-test28-shell-command): Run `async-shell-command' with timeouts.
This commit is contained in:
Michael Albinus 2014-02-27 13:07:10 +01:00
parent 6be7660863
commit 154ba7966c
2 changed files with 107 additions and 119 deletions

View File

@ -1,3 +1,24 @@
2014-02-27 Michael Albinus <michael.albinus@gmx.de>
* automated/tramp-tests.el (tramp--test-enabled): Move connection
cleanup into this function. Remove respective code from all test
cases.
(tramp--instrument-test-case): Declare `indent' and `debug'.
Handle other errors as well.
(tramp-test14-delete-directory): Check for `file-error' error.
(tramp-test15-copy-directory): Ignore return value of
`copy-directory'. It's too much hassle to handle it for tramp-adb.el.
(tramp-test19-directory-files-and-attributes): Take care of
timestamp of "../".
(tramp-test20-file-modes, tramp-test27-start-file-process)
(tramp-test28-shell-command): Skip for tramp-adb.el.
(tramp-test21-file-links): `file-truename' shall preserve trailing
link of directories.
(tramp-test22-file-times): Skip if `set-file-times' returns nil.
(tramp-test26-process-file, tramp-test28-shell-command): Let-bind
`kill-buffer-query-functions' to nil.
(tramp-test28-shell-command): Run `async-shell-command' with timeouts.
2014-02-21 Michael Albinus <michael.albinus@gmx.de>
* automated/tramp-tests.el

View File

@ -81,6 +81,17 @@ being the result.")
(file-remote-p tramp-test-temporary-file-directory)
(file-directory-p tramp-test-temporary-file-directory)
(file-writable-p tramp-test-temporary-file-directory))))))
(when (and (cdr tramp--test-enabled-checked)
(not (eq (tramp-find-foreign-file-name-handler
tramp-test-temporary-file-directory)
'tramp-adb-file-name-handler)))
;; Cleanup connection. We don't cleanup for adb, because it
;; doesn't behave well when is disconnect several times.
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password))
;; Return result.
(cdr tramp--test-enabled-checked))
@ -93,15 +104,21 @@ being the result.")
"Run BODY with `tramp-verbose' equal VERBOSE.
Print the the content of the Tramp debug buffer, if BODY does not
eval properly in `should', `should-not' or `should-error'."
`(let ((tramp-verbose ,verbose))
(declare (indent 1) (debug (natnump body)))
`(let ((tramp-verbose ,verbose)
(tramp-debug-on-error t))
(condition-case err
(progn ,@body)
(ert-test-failed
(ert-test-skipped
(signal (car err) (cdr err)))
(error
(with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
(with-current-buffer (tramp-get-connection-buffer v)
(message "%s" (buffer-string)))
(with-current-buffer (tramp-get-debug-buffer v)
(message "%s" (buffer-string))))
(message "%s" err)
(signal (car err) (cdr err))))))
(put 'tramp--instrument-test-case 'lisp-indent-function 1)
(ert-deftest tramp-test00-availability ()
"Test availability of Tramp functions."
@ -571,9 +588,6 @@ and `file-name-nondirectory'."
(ert-deftest tramp-test07-file-exists-p ()
"Check `file-exist-p', `write-region' and `delete-file'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name)))
(should-not (file-exists-p tmp-name))
@ -585,9 +599,6 @@ and `file-name-nondirectory'."
(ert-deftest tramp-test08-file-local-copy ()
"Check `file-local-copy'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name1 (tramp--test-make-temp-name))
tmp-name2)
@ -605,9 +616,6 @@ and `file-name-nondirectory'."
(ert-deftest tramp-test09-insert-file-contents ()
"Check `insert-file-contents'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name)))
(unwind-protect
@ -629,9 +637,6 @@ and `file-name-nondirectory'."
(ert-deftest tramp-test10-write-region ()
"Check `write-region'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name)))
(unwind-protect
@ -666,9 +671,6 @@ and `file-name-nondirectory'."
(ert-deftest tramp-test11-copy-file ()
"Check `copy-file'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name1 (tramp--test-make-temp-name))
(tmp-name2 (tramp--test-make-temp-name)))
@ -687,9 +689,6 @@ and `file-name-nondirectory'."
(ert-deftest tramp-test12-rename-file ()
"Check `rename-file'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name1 (tramp--test-make-temp-name))
(tmp-name2 (tramp--test-make-temp-name)))
@ -708,9 +707,6 @@ and `file-name-nondirectory'."
"Check `make-directory'.
This tests also `file-directory-p' and `file-accessible-directory-p'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name)))
(unwind-protect
@ -723,9 +719,6 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
(ert-deftest tramp-test14-delete-directory ()
"Check `delete-directory'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name)))
;; Delete empty directory.
@ -736,16 +729,13 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
;; Delete non-empty directory.
(make-directory tmp-name)
(write-region "foo" nil (expand-file-name "bla" tmp-name))
(should-error (delete-directory tmp-name))
(should-error (delete-directory tmp-name) :type 'file-error)
(delete-directory tmp-name 'recursive)
(should-not (file-directory-p tmp-name))))
(ert-deftest tramp-test15-copy-directory ()
"Check `copy-directory'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let* ((tmp-name1 (tramp--test-make-temp-name))
(tmp-name2 (tramp--test-make-temp-name))
@ -761,11 +751,14 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
(write-region "foo" nil tmp-name4)
(should (file-directory-p tmp-name1))
(should (file-exists-p tmp-name4))
(copy-directory tmp-name1 tmp-name2)
;; We do not care, whether file permissions and time stamps
;; are correct. Sometimes, it is not possible to manage
;; them, for example in tramp-adb.el.
(ignore-errors (copy-directory tmp-name1 tmp-name2))
(should (file-directory-p tmp-name2))
(should (file-exists-p tmp-name5))
;; Target directory does exist already.
(copy-directory tmp-name1 tmp-name2)
(ignore-errors (copy-directory tmp-name1 tmp-name2))
(should (file-directory-p tmp-name3))
(should (file-exists-p tmp-name6)))
(ignore-errors
@ -775,9 +768,6 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
(ert-deftest tramp-test16-directory-files ()
"Check `directory-files'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let* ((tmp-name1 (tramp--test-make-temp-name))
(tmp-name2 (expand-file-name "bla" tmp-name1))
@ -806,9 +796,6 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
(ert-deftest tramp-test17-insert-directory ()
"Check `insert-directory'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let* ((tmp-name1 (tramp--test-make-temp-name))
(tmp-name2 (expand-file-name "foo" tmp-name1)))
@ -844,9 +831,6 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
"Check `file-attributes'.
This tests also `file-readable-p' and `file-regular-p'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name))
attr)
@ -889,39 +873,35 @@ This tests also `file-readable-p' and `file-regular-p'."
(ert-deftest tramp-test19-directory-files-and-attributes ()
"Check `directory-files-and-attributes'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(tramp--instrument-test-case 10
(let ((tmp-name (tramp--test-make-temp-name))
attr)
;; `directory-files-and-attributes' contains also values for "../".
;; We must nesure, that this doesn't change during tests, for
;; example due to handling temporary files.
(let* ((tmp-name1 (tramp--test-make-temp-name))
(tmp-name2 (expand-file-name "bla" tmp-name1))
attr)
(unwind-protect
(progn
(make-directory tmp-name)
(should (file-directory-p tmp-name))
(write-region "foo" nil (expand-file-name "foo" tmp-name))
(write-region "bar" nil (expand-file-name "bar" tmp-name))
(write-region "boz" nil (expand-file-name "boz" tmp-name))
(setq attr (directory-files-and-attributes tmp-name))
(make-directory tmp-name1)
(should (file-directory-p tmp-name1))
(make-directory tmp-name2)
(should (file-directory-p tmp-name2))
(write-region "foo" nil (expand-file-name "foo" tmp-name2))
(write-region "bar" nil (expand-file-name "bar" tmp-name2))
(write-region "boz" nil (expand-file-name "boz" tmp-name2))
(setq attr (directory-files-and-attributes tmp-name2))
(should (consp attr))
(dolist (elt attr)
;; We cannot include "." and "..". They might have
;; changed their timestamp already.
(when (string-match "foo$\\|bar$\\|baz$" (car elt))
(should
(equal (file-attributes (expand-file-name (car elt) tmp-name))
(cdr elt)))))
(setq attr (directory-files-and-attributes tmp-name 'full))
(should
(equal (file-attributes (expand-file-name (car elt) tmp-name2))
(cdr elt))))
(setq attr (directory-files-and-attributes tmp-name2 'full))
(dolist (elt attr)
;; We cannot include "." and "..". They might have
;; changed their timestamp already.
(when (string-match "foo$\\|bar$\\|baz$" (car elt))
(should
(equal (file-attributes (car elt)) (cdr elt)))))
(setq attr (directory-files-and-attributes tmp-name nil "^b"))
(should
(equal (file-attributes (car elt)) (cdr elt))))
(setq attr (directory-files-and-attributes tmp-name2 nil "^b"))
(should (equal (mapcar 'car attr) '("bar" "boz"))))
(ignore-errors (delete-directory tmp-name 'recursive))))))
(ignore-errors (delete-directory tmp-name1 'recursive)))))
(ert-deftest tramp-test20-file-modes ()
"Check `file-modes'.
@ -931,10 +911,9 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
(not
(memq
(tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
'(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
'(tramp-adb-file-name-handler
tramp-gvfs-file-name-handler
tramp-smb-file-name-handler))))
(let ((tmp-name (tramp--test-make-temp-name)))
(unwind-protect
@ -949,8 +928,7 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
(should (= (file-modes tmp-name) #o444))
(should-not (file-executable-p tmp-name))
;; A file is always writable for user "root".
(when (and (stringp (file-remote-p tmp-name 'user))
(not (string-equal (file-remote-p tmp-name 'user) "root")))
(when (not (string-equal (file-remote-p tmp-name 'user) "root"))
(should-not (file-writable-p tmp-name))))
(ignore-errors (delete-file tmp-name)))))
@ -958,9 +936,6 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
"Check `file-symlink-p'.
This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name1 (tramp--test-make-temp-name))
(tmp-name2 (tramp--test-make-temp-name))
@ -1014,7 +989,13 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(string-equal (file-truename tmp-name1) (file-truename tmp-name2))))
(ignore-errors
(delete-file tmp-name1)
(delete-file tmp-name2)))))
(delete-file tmp-name2)))
;; `file-truename' shall preserve trailing link of directories.
(let* ((dir1 (directory-file-name tramp-test-temporary-file-directory))
(dir2 (file-name-as-directory dir1)))
(should (string-equal (file-truename dir1) (expand-file-name dir1)))
(should (string-equal (file-truename dir2) (expand-file-name dir2))))))
(ert-deftest tramp-test22-file-times ()
"Check `set-file-times' and `file-newer-than-file-p'."
@ -1024,9 +1005,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(memq
(tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
'(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name1 (tramp--test-make-temp-name))
(tmp-name2 (tramp--test-make-temp-name))
@ -1036,8 +1014,11 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(write-region "foo" nil tmp-name1)
(should (file-exists-p tmp-name1))
(should (consp (nth 5 (file-attributes tmp-name1))))
;; '(0 0) means don't know, and will be replaced by `current-time'.
(set-file-times tmp-name1 '(0 1))
;; '(0 0) means don't know, and will be replaced by
;; `current-time'. Therefore, we use '(0 1).
;; We skip the test, if the remote handler is not able to
;; set the correct time.
(skip-unless (set-file-times tmp-name1 '(0 1)))
;; Dumb busyboxes are not able to return the date correctly.
;; They say "don't know.
(skip-unless (not (equal (nth 5 (file-attributes tmp-name1)) '(0 0))))
@ -1055,9 +1036,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(ert-deftest tramp-test23-visited-file-modtime ()
"Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name)))
(unwind-protect
@ -1075,9 +1053,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(ert-deftest tramp-test24-file-name-completion ()
"Check `file-name-completion' and `file-name-all-completions'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name)))
(unwind-protect
@ -1100,9 +1075,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(ert-deftest tramp-test25-load ()
"Check `load'."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name)))
(unwind-protect
@ -1126,12 +1098,10 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(memq
(tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
'(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name))
(default-directory tramp-test-temporary-file-directory))
(default-directory tramp-test-temporary-file-directory)
kill-buffer-query-functions)
(unwind-protect
(progn
;; We cannot use "/bin/true" and "/bin/false"; those paths
@ -1162,10 +1132,9 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(not
(memq
(tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
'(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
'(tramp-adb-file-name-handler
tramp-gvfs-file-name-handler
tramp-smb-file-name-handler))))
(let ((default-directory tramp-test-temporary-file-directory)
(tmp-name (tramp--test-make-temp-name))
@ -1215,13 +1184,13 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(not
(memq
(tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
'(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
'(tramp-adb-file-name-handler
tramp-gvfs-file-name-handler
tramp-smb-file-name-handler))))
(let ((tmp-name (tramp--test-make-temp-name))
(default-directory tramp-test-temporary-file-directory))
(default-directory tramp-test-temporary-file-directory)
kill-buffer-query-functions)
(unwind-protect
(with-temp-buffer
(write-region "foo" nil tmp-name)
@ -1244,10 +1213,12 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(async-shell-command
(format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
(accept-process-output (get-buffer-process (current-buffer)) 1)
(while (ignore-errors
(memq (process-status (get-buffer-process (current-buffer)))
'(run open)))
(accept-process-output (get-buffer-process (current-buffer)) 1))
(with-timeout (10 (ert-fail "`async-shell-command' timed out"))
(while
(ignore-errors
(memq (process-status (get-buffer-process (current-buffer)))
'(run open)))
(accept-process-output (get-buffer-process (current-buffer)) 1)))
;; `ls' could produce colorized output.
(goto-char (point-min))
(while (re-search-forward tramp-color-escape-sequence-regexp nil t)
@ -1266,10 +1237,12 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(get-buffer-process (current-buffer))
(format "%s\n" (file-name-nondirectory tmp-name)))
(accept-process-output (get-buffer-process (current-buffer)) 1)
(while (ignore-errors
(memq (process-status (get-buffer-process (current-buffer)))
'(run open)))
(accept-process-output (get-buffer-process (current-buffer)) 1))
(with-timeout (10 (ert-fail "`async-shell-command' timed out"))
(while
(ignore-errors
(memq (process-status (get-buffer-process (current-buffer)))
'(run open)))
(accept-process-output (get-buffer-process (current-buffer)) 1)))
(should
(string-equal
(format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
@ -1282,9 +1255,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(eq
(tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
'tramp-sh-file-name-handler))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let* ((default-directory tramp-test-temporary-file-directory)
(tmp-name1 (tramp--test-make-temp-name))
@ -1326,9 +1296,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(ert-deftest tramp-test30-utf8 ()
"Check UTF8 encoding in file names and file contents."
(skip-unless (tramp--test-enabled))
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
nil 'keep-password)
(let ((tmp-name (tramp--test-make-temp-name))
(coding-system-for-read 'utf-8)