From 4f2b41503b06f65f8c2789dfcd32d39e5172554d Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Mon, 6 Jan 2020 12:24:16 +0100 Subject: [PATCH] ; Adapt tramp-tests.el * test/lisp/net/tramp-tests.el (tramp-test30-make-process): (tramp-test32-shell-command): Extend for asynchronous stderr. --- test/lisp/net/tramp-tests.el | 92 ++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 20 deletions(-) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 47d51767c5c..2e4188ab76c 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -4248,7 +4248,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) (let ((default-directory tramp-test-temporary-file-directory) - (tmp-name (tramp--test-make-temp-name nil quoted)) + (tmp-name1 (tramp--test-make-temp-name nil quoted)) + (tmp-name2 (tramp--test-make-temp-name 'local quoted)) kill-buffer-query-functions proc) (with-no-warnings (should-not (make-process))) @@ -4278,13 +4279,13 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." ;; Simple process using a file. (unwind-protect (with-temp-buffer - (write-region "foo" nil tmp-name) - (should (file-exists-p tmp-name)) + (write-region "foo" nil tmp-name1) + (should (file-exists-p tmp-name1)) (setq proc (with-no-warnings (make-process :name "test2" :buffer (current-buffer) - :command `("cat" ,(file-name-nondirectory tmp-name)) + :command `("cat" ,(file-name-nondirectory tmp-name1)) :file-handler t))) (should (processp proc)) ;; Read output. @@ -4296,7 +4297,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." ;; Cleanup. (ignore-errors (delete-process proc) - (delete-file tmp-name))) + (delete-file tmp-name1))) ;; Process filter. (unwind-protect @@ -4351,7 +4352,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." ;; Cleanup. (ignore-errors (delete-process proc))) - ;; Process with stderr. tramp-adb.el doesn't support it (yet). + ;; Process with stderr buffer. tramp-adb.el doesn't support it (yet). (unless (tramp--test-adb-p) (let ((stderr (generate-new-buffer "*stderr*"))) (unwind-protect @@ -4365,16 +4366,42 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." :file-handler t))) (should (processp proc)) ;; Read stderr. + (with-timeout (10 (tramp--test-timeout-handler)) + (while (accept-process-output proc 0 nil t))) + (delete-process proc) (with-current-buffer stderr - (with-timeout (10 (tramp--test-timeout-handler)) - (while (= (point-min) (point-max)) - (while (accept-process-output proc 0 nil t)))) (should - (string-match "^cat:.* Is a directory" (buffer-string))))) + (string-match "cat:.* Is a directory" (buffer-string))))) + + ;; Cleanup. + (ignore-errors (delete-process proc))) + (ignore-errors (kill-buffer stderr)))) + + ;; Process with stderr file. tramp-adb.el doesn't support it (yet). + (unless (tramp--test-adb-p) + (dolist (tmpfile `(,tmp-name1 ,tmp-name2)) + (unwind-protect + (with-temp-buffer + (setq proc + (with-no-warnings + (make-process + :name "test6" :buffer (current-buffer) + :command '("cat" "/") + :stderr tmpfile + :file-handler t))) + (should (processp proc)) + ;; Read stderr. + (with-timeout (10 (tramp--test-timeout-handler)) + (while (accept-process-output proc nil nil t))) + (delete-process proc) + (with-temp-buffer + (insert-file-contents tmpfile) + (should + (string-match "cat:.* Is a directory" (buffer-string))))) ;; Cleanup. (ignore-errors (delete-process proc)) - (ignore-errors (kill-buffer stderr)))))))) + (ignore-errors (delete-file tmpfile)))))))) (ert-deftest tramp-test31-interrupt-process () "Check `interrupt-process'." @@ -4460,12 +4487,11 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (let ((stderr (generate-new-buffer "*stderr*"))) (unwind-protect (with-temp-buffer - (shell-command "error" (current-buffer) stderr) + (shell-command "cat /" (current-buffer) stderr) (should (= (point-min) (point-max))) - (should - (string-match - "error:.+not found" - (with-current-buffer stderr (buffer-string))))) + (with-current-buffer stderr + (should + (string-match "cat:.* Is a directory" (buffer-string))))) ;; Cleanup. (ignore-errors (kill-buffer stderr)))) @@ -4495,6 +4521,26 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." ;; Cleanup. (ignore-errors (delete-file tmp-name))) + ;; Test `async-shell-command' with error buffer. tramp-adb.el + ;; doesn't support it (yet). + (unless (tramp--test-adb-p) + (let ((stderr (generate-new-buffer "*stderr*")) proc) + (unwind-protect + (with-temp-buffer + (async-shell-command "cat /; sleep 1" (current-buffer) stderr) + (setq proc (get-buffer-process (current-buffer))) + ;; Read stderr. + (when (processp proc) + (with-timeout (10 (tramp--test-timeout-handler)) + (while (accept-process-output proc nil nil t))) + (delete-process proc)) + (with-current-buffer stderr + (should + (string-match "cat:.* Is a directory" (buffer-string))))) + + ;; Cleanup. + (ignore-errors (kill-buffer stderr))))) + ;; Test sending string to `async-shell-command'. (unwind-protect (with-temp-buffer @@ -4513,11 +4559,15 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (while (re-search-forward tramp-display-escape-sequence-regexp nil t) (replace-match "" nil nil)) - ;; We cannot use `string-equal', because tramp-adb.el - ;; echoes also the sent string. (should - (string-match - (format "\\`%s" (regexp-quote (file-name-nondirectory tmp-name))) + (string-equal + ;; tramp-adb.el echoes, so we must add the string. + (if (tramp--test-adb-p) + (format + "%s\n%s\n" + (file-name-nondirectory tmp-name) + (file-name-nondirectory tmp-name)) + (format "%s\n" (file-name-nondirectory tmp-name))) (buffer-string)))) ;; Cleanup. @@ -6193,6 +6243,8 @@ If INTERACTIVE is non-nil, the tests are run interactively." ;; do not work properly for `nextcloud'. ;; * Fix `tramp-test29-start-file-process' and ;; `tramp-test30-make-process' on MS Windows (`process-send-eof'?). +;; * Implement stderr for `adb' in `tramp-test30-make-process' and +;; `tramp-test32-shell-command'. ;; * Implement `tramp-test31-interrupt-process' for `adb'. ;; * Fix Bug#16928 in `tramp-test43-asynchronous-requests'. A remote ;; file name operation cannot run in the timer. Remove `:unstable' tag? -- 2.39.2