Add test for handling environment variables in Tramp

* test/automatedtramp-tests.el
(tramp-test--shell-command-to-string-asynchronously): New defun.
(tramp-test29-environment-variables): New test.
(tramp-test30-vc-registered)
(tramp-test31-make-auto-save-file-name)
(tramp-test32-special-characters)
(tramp-test32-special-characters-with-stat)
(tramp-test32-special-characters-with-perl)
(tramp-test32-special-characters-with-ls, tramp-test33-utf8)
(tramp-test33-utf8-with-stat, tramp-test33-utf8-with-perl)
(tramp-test33-utf8-with-ls)
(tramp-test34-asynchronous-requests)
(tramp-test35-recursive-load, tramp-test36-unload): Rename.
This commit is contained in:
Michael Albinus 2016-07-14 10:10:53 +02:00
parent e393d4f4ce
commit 05ba7a0f83

View file

@ -1598,7 +1598,103 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
;; Cleanup. ;; Cleanup.
(ignore-errors (delete-file tmp-name))))) (ignore-errors (delete-file tmp-name)))))
(ert-deftest tramp-test29-vc-registered () (defun tramp-test--shell-command-to-string-asynchronously (command)
"Like `shell-command-to-string', but for asynchronous processes."
(with-temp-buffer
(async-shell-command command (current-buffer))
;; Suppress nasty messages.
(set-process-sentinel (get-buffer-process (current-buffer)) nil)
(while
(and (get-buffer-process (current-buffer))
(eq (process-status (get-buffer-process (current-buffer))) 'run))
(accept-process-output (get-buffer-process (current-buffer)) 1))
(buffer-substring-no-properties (point-min) (point-max))))
;; This test is inspired by Bug#23952.
(ert-deftest tramp-test29-environment-variables ()
"Check that remote processes set / unset environment variables properly."
:tags '(:expensive-test)
(skip-unless (tramp--test-enabled))
(skip-unless
(eq
(tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
'tramp-sh-file-name-handler))
;; Implementation note: There is a "sleep 1" at the end of every
;; test. Otherwise, the scripts could return too early, without
;; expected output.
(dolist (this-shell-command-to-string
'(;; Synchronously.
shell-command-to-string
;; Asynchronously.
tramp-test--shell-command-to-string-asynchronously))
(let ((default-directory tramp-test-temporary-file-directory)
(shell-file-name "/bin/sh")
(envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
kill-buffer-query-functions)
(unwind-protect
;; Set a value.
(let ((process-environment
(cons (concat envvar "=foo") process-environment)))
;; Default value.
(should
(string-match
"foo"
(funcall
this-shell-command-to-string
(format "echo -n ${%s:?bla}; sleep 1" envvar))))))
(unwind-protect
;; Set the empty value.
(let ((process-environment
(cons (concat envvar "=") process-environment)))
;; Value is null.
(should
(string-match
"bla"
(funcall
this-shell-command-to-string
(format "echo -n ${%s:?bla}; sleep 1" envvar))))
;; Variable is set.
(should
(string-match
(regexp-quote envvar)
(funcall this-shell-command-to-string "set; sleep 1")))))
;; We force a reconnect, in order to have a clean environment.
(tramp-cleanup-connection
(tramp-dissect-file-name tramp-test-temporary-file-directory)
'keep-debug 'keep-password)
(unwind-protect
;; Unset the variable.
(let ((tramp-remote-process-environment
(cons (concat envvar "=foo")
tramp-remote-process-environment)))
;; Set the initial value, we want to unset below.
(should
(string-match
"foo"
(funcall
this-shell-command-to-string
(format "echo -n ${%s:?bla}; sleep 1" envvar))))
(let ((process-environment
(cons envvar process-environment)))
;; Variable is unset.
(should
(string-match
"bla"
(funcall
this-shell-command-to-string
(format "echo -n ${%s:?bla}; sleep 1" envvar))))
;; Variable is unset.
(should-not
(string-match
(regexp-quote envvar)
(funcall this-shell-command-to-string "set; sleep 1")))))))))
(ert-deftest tramp-test30-vc-registered ()
"Check `vc-registered'." "Check `vc-registered'."
:tags '(:expensive-test) :tags '(:expensive-test)
(skip-unless (tramp--test-enabled)) (skip-unless (tramp--test-enabled))
@ -1667,7 +1763,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
;; Cleanup. ;; Cleanup.
(ignore-errors (delete-directory tmp-name1 'recursive))))) (ignore-errors (delete-directory tmp-name1 'recursive)))))
(ert-deftest tramp-test30-make-auto-save-file-name () (ert-deftest tramp-test31-make-auto-save-file-name ()
"Check `make-auto-save-file-name'." "Check `make-auto-save-file-name'."
(skip-unless (tramp--test-enabled)) (skip-unless (tramp--test-enabled))
@ -1921,7 +2017,7 @@ Several special characters do not work properly there."
(ignore-errors (delete-directory tmp-name2 'recursive))))) (ignore-errors (delete-directory tmp-name2 'recursive)))))
(defun tramp--test-special-characters () (defun tramp--test-special-characters ()
"Perform the test in `tramp-test31-special-characters*'." "Perform the test in `tramp-test32-special-characters*'."
;; Newlines, slashes and backslashes in file names are not ;; Newlines, slashes and backslashes in file names are not
;; supported. So we don't test. And we don't test the tab ;; supported. So we don't test. And we don't test the tab
;; character on Windows or Cygwin, because the backslash is ;; character on Windows or Cygwin, because the backslash is
@ -1962,13 +2058,13 @@ Several special characters do not work properly there."
"{foo}bar{baz}")) "{foo}bar{baz}"))
;; These tests are inspired by Bug#17238. ;; These tests are inspired by Bug#17238.
(ert-deftest tramp-test31-special-characters () (ert-deftest tramp-test32-special-characters ()
"Check special characters in file names." "Check special characters in file names."
(skip-unless (tramp--test-enabled)) (skip-unless (tramp--test-enabled))
(tramp--test-special-characters)) (tramp--test-special-characters))
(ert-deftest tramp-test31-special-characters-with-stat () (ert-deftest tramp-test32-special-characters-with-stat ()
"Check special characters in file names. "Check special characters in file names.
Use the `stat' command." Use the `stat' command."
:tags '(:expensive-test) :tags '(:expensive-test)
@ -1987,7 +2083,7 @@ Use the `stat' command."
tramp-connection-properties))) tramp-connection-properties)))
(tramp--test-special-characters))) (tramp--test-special-characters)))
(ert-deftest tramp-test31-special-characters-with-perl () (ert-deftest tramp-test32-special-characters-with-perl ()
"Check special characters in file names. "Check special characters in file names.
Use the `perl' command." Use the `perl' command."
:tags '(:expensive-test) :tags '(:expensive-test)
@ -2009,7 +2105,7 @@ Use the `perl' command."
tramp-connection-properties))) tramp-connection-properties)))
(tramp--test-special-characters))) (tramp--test-special-characters)))
(ert-deftest tramp-test31-special-characters-with-ls () (ert-deftest tramp-test32-special-characters-with-ls ()
"Check special characters in file names. "Check special characters in file names.
Use the `ls' command." Use the `ls' command."
:tags '(:expensive-test) :tags '(:expensive-test)
@ -2032,7 +2128,7 @@ Use the `ls' command."
(tramp--test-special-characters))) (tramp--test-special-characters)))
(defun tramp--test-utf8 () (defun tramp--test-utf8 ()
"Perform the test in `tramp-test32-utf8*'." "Perform the test in `tramp-test33-utf8*'."
(let* ((utf8 (if (and (eq system-type 'darwin) (let* ((utf8 (if (and (eq system-type 'darwin)
(memq 'utf-8-hfs (coding-system-list))) (memq 'utf-8-hfs (coding-system-list)))
'utf-8-hfs 'utf-8)) 'utf-8-hfs 'utf-8))
@ -2046,13 +2142,13 @@ Use the `ls' command."
"银河系漫游指南系列" "银河系漫游指南系列"
"Автостопом по гала́ктике"))) "Автостопом по гала́ктике")))
(ert-deftest tramp-test32-utf8 () (ert-deftest tramp-test33-utf8 ()
"Check UTF8 encoding in file names and file contents." "Check UTF8 encoding in file names and file contents."
(skip-unless (tramp--test-enabled)) (skip-unless (tramp--test-enabled))
(tramp--test-utf8)) (tramp--test-utf8))
(ert-deftest tramp-test32-utf8-with-stat () (ert-deftest tramp-test33-utf8-with-stat ()
"Check UTF8 encoding in file names and file contents. "Check UTF8 encoding in file names and file contents.
Use the `stat' command." Use the `stat' command."
:tags '(:expensive-test) :tags '(:expensive-test)
@ -2071,7 +2167,7 @@ Use the `stat' command."
tramp-connection-properties))) tramp-connection-properties)))
(tramp--test-utf8))) (tramp--test-utf8)))
(ert-deftest tramp-test32-utf8-with-perl () (ert-deftest tramp-test33-utf8-with-perl ()
"Check UTF8 encoding in file names and file contents. "Check UTF8 encoding in file names and file contents.
Use the `perl' command." Use the `perl' command."
:tags '(:expensive-test) :tags '(:expensive-test)
@ -2093,7 +2189,7 @@ Use the `perl' command."
tramp-connection-properties))) tramp-connection-properties)))
(tramp--test-utf8))) (tramp--test-utf8)))
(ert-deftest tramp-test32-utf8-with-ls () (ert-deftest tramp-test33-utf8-with-ls ()
"Check UTF8 encoding in file names and file contents. "Check UTF8 encoding in file names and file contents.
Use the `ls' command." Use the `ls' command."
:tags '(:expensive-test) :tags '(:expensive-test)
@ -2116,7 +2212,7 @@ Use the `ls' command."
(tramp--test-utf8))) (tramp--test-utf8)))
;; This test is inspired by Bug#16928. ;; This test is inspired by Bug#16928.
(ert-deftest tramp-test33-asynchronous-requests () (ert-deftest tramp-test34-asynchronous-requests ()
"Check parallel asynchronous requests. "Check parallel asynchronous requests.
Such requests could arrive from timers, process filters and Such requests could arrive from timers, process filters and
process sentinels. They shall not disturb each other." process sentinels. They shall not disturb each other."
@ -2206,7 +2302,7 @@ process sentinels. They shall not disturb each other."
(dolist (buf buffers) (dolist (buf buffers)
(ignore-errors (kill-buffer buf))))))) (ignore-errors (kill-buffer buf)))))))
(ert-deftest tramp-test34-recursive-load () (ert-deftest tramp-test35-recursive-load ()
"Check that Tramp does not fail due to recursive load." "Check that Tramp does not fail due to recursive load."
(skip-unless (tramp--test-enabled)) (skip-unless (tramp--test-enabled))
@ -2229,7 +2325,7 @@ process sentinels. They shall not disturb each other."
(mapconcat 'shell-quote-argument load-path " -L ") (mapconcat 'shell-quote-argument load-path " -L ")
(shell-quote-argument code))))))) (shell-quote-argument code)))))))
(ert-deftest tramp-test35-unload () (ert-deftest tramp-test36-unload ()
"Check that Tramp and its subpackages unload completely. "Check that Tramp and its subpackages unload completely.
Since it unloads Tramp, it shall be the last test to run." Since it unloads Tramp, it shall be the last test to run."
;; Mark as failed until all symbols are unbound. ;; Mark as failed until all symbols are unbound.
@ -2277,8 +2373,8 @@ Since it unloads Tramp, it shall be the last test to run."
;; * Fix `tramp-test15-copy-directory' for `smb'. Using tar in a pipe ;; * Fix `tramp-test15-copy-directory' for `smb'. Using tar in a pipe
;; doesn't work well when an interactive password must be provided. ;; doesn't work well when an interactive password must be provided.
;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?). ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
;; * Fix Bug#16928. Set expected error of `tramp-test33-asynchronous-requests'. ;; * Fix Bug#16928. Set expected error of `tramp-test34-asynchronous-requests'.
;; * Fix `tramp-test35-unload' (Not all symbols are unbound). Set ;; * Fix `tramp-test36-unload' (Not all symbols are unbound). Set
;; expected error. ;; expected error.
(defun tramp-test-all (&optional interactive) (defun tramp-test-all (&optional interactive)