Extend tests for shell-command-dont-erase-buffer

* test/lisp/simple-tests.el
(simple-tests-shell-command-dont-erase-buffer): Extend test.

* test/lisp/net/tramp-tests.el
(tramp-test32-shell-command-dont-erase-buffer): Adapt test.  Tag
it :unstable.
This commit is contained in:
Michael Albinus 2020-10-08 11:28:50 +02:00
parent 6fea8699a1
commit c56eeba2ce
2 changed files with 114 additions and 200 deletions

View file

@ -4609,214 +4609,127 @@ INPUT, if non-nil, is a string sent to the process."
;; This test is inspired by Bug#39067. ;; This test is inspired by Bug#39067.
(ert-deftest tramp-test32-shell-command-dont-erase-buffer () (ert-deftest tramp-test32-shell-command-dont-erase-buffer ()
"Check `shell-command-dont-erase-buffer'." "Check `shell-command-dont-erase-buffer'."
:tags '(:expensive-test) ;; As long as Bug#40896 is not solved both in simple.el and Tramp,
;; this test cannot run properly.
:tags '(:expensive-test :unstable)
(skip-unless (tramp--test-enabled)) (skip-unless (tramp--test-enabled))
(skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p))) (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
;; Prior Emacs 27, `shell-command-dont-erase-buffer' wasn't working properly. ;; Prior Emacs 27, `shell-command-dont-erase-buffer' wasn't working properly.
(skip-unless (tramp--test-emacs27-p)) (skip-unless (tramp--test-emacs27-p))
;; (message " s-c-d-e-b current-buffer buffer-string point")
;; (message "===============================================")
;; s-c-d-e-b current-buffer buffer-string point
;; ===============================================
;; nil t foobazzbar 4 x
;; nil nil bazz 5
;; -----------------------------------------------
;; erase t bazz 1 x
;; erase nil bazz 5
;; -----------------------------------------------
;; beg-last-out t foobazzbar 4 x
;; beg-last-out nil foobarbazz 7
;; -----------------------------------------------
;; end-last-out t foobazzbar 4
;; end-last-out nil foobazzbar 11
;; -----------------------------------------------
;; save-point t foobazzbar 4 x
;; save-point nil foobarbazz 4 x
;; -----------------------------------------------
;; random t foobazzbar 4
;; random nil foobazzbar 11
;; -----------------------------------------------
(let (;; Suppress nasty messages.
(inhibit-message t)
buffer kill-buffer-query-functions)
;; We check both the local and remote case, in order to guarantee ;; We check both the local and remote case, in order to guarantee
;; that they behave similar. ;; that they behave similar.
(dolist (default-directory (dolist (default-directory
`(,temporary-file-directory ,tramp-test-temporary-file-directory)) `(,temporary-file-directory ,tramp-test-temporary-file-directory))
(let ((buffer (generate-new-buffer "foo")) ;; These are the possible values of `shell-command-dont-erase-buffer'.
;; Suppress nasty messages. ;; `random' is taken as non-nil value without special meaning.
(inhibit-message t) (dolist (shell-command-dont-erase-buffer
point kill-buffer-query-functions) '(nil erase beg-last-out end-last-out save-point random))
(unwind-protect ;; `shell-command' might work over the current buffer, or not.
(progn (dolist (current '(t nil))
;; Don't erase if buffer is the current one. Point is not moved.
(let (shell-command-dont-erase-buffer)
(with-temp-buffer (with-temp-buffer
(insert "bar") ;; We insert the string "foobar" into an empty buffer.
(setq point (point)) ;; Point is set between "foo" and "bar".
(should (string-equal "bar" (buffer-string))) (setq buffer (current-buffer))
(should (= (point) (point-max))) (insert "foobar")
(shell-command "echo baz" (current-buffer)) (goto-char (- (point) 3))
(should (string-equal "barbaz\n" (buffer-string))) (should (string-equal "foobar" (buffer-string)))
(should (= point (point))) (should (string-equal "foo" (buffer-substring (point-min) (point))))
(should-not (= (point) (point-max))))) (should (string-equal "bar" (buffer-substring (point) (point-max))))
;; Erase if the buffer is not current one. Point is not moved. ;; Apply `shell-command'. It shall output the string
(let (shell-command-dont-erase-buffer) ;; "bazz". Messages in the *Messages* buffer are
(with-current-buffer buffer ;; suppressed.
(erase-buffer) (let (message-log-max)
(insert "bar") (if current
(setq point (point)) (shell-command "echo -n bazz" (current-buffer))
(should (string-equal "bar" (buffer-string))) (with-temp-buffer (shell-command "echo -n bazz" buffer))))
(should (= (point) (point-max)))
(with-temp-buffer
(shell-command "echo baz" buffer))
(should (string-equal "baz\n" (buffer-string)))
(should (= point (point)))
(should-not (= (point) (point-max)))))
;; Erase if buffer is the current one, but ;; (message
;; `shell-command-dont-erase-buffer' is set to `erase'. ;; "%12s %14s %13s %5d"
;; There is no point to check point. ;; shell-command-dont-erase-buffer current (buffer-string) (point))))
(let ((shell-command-dont-erase-buffer 'erase)) ;; (message "-----------------------------------------------")))))
(with-temp-buffer
(insert "bar")
(should (string-equal "bar" (buffer-string)))
(should (= (point) (point-max)))
(shell-command "echo baz" (current-buffer))
(should (string-equal "baz\n" (buffer-string)))
;; In the local case, point is not moved after the
;; inserted text.
(should (= (point)
(if (file-remote-p default-directory)
(point-max) (point-min))))))
;; Don't erase if the buffer is the current one and ;; Check result.
;; `shell-command-dont-erase-buffer' is set to (cond
;; `beg-last-out'. Check point. (current
(let ((shell-command-dont-erase-buffer 'beg-last-out)) ;; String is inserted at point, and point is preserved
(with-temp-buffer ;; unless dictated otherwise.
(insert "bar") (cond
(setq point (point)) ((null shell-command-dont-erase-buffer)
(should (string-equal "bar" (buffer-string))) (should (string-equal "foobazzbar" (buffer-string)))
(should (= (point) (point-max))) (should (= 4 (point))))
(shell-command "echo baz" (current-buffer)) ((eq shell-command-dont-erase-buffer 'erase)
(should (string-equal "barbaz\n" (buffer-string))) (should (string-equal "bazz" (buffer-string)))
;; There is still an error in Tramp. (should (= 1 (point))))
(unless (file-remote-p default-directory) ((eq shell-command-dont-erase-buffer 'beg-last-out)
(should (= point (point))) (should (string-equal "foobazzbar" (buffer-string)))
(should-not (= (point) (point-max)))))) (should (= 4 (point))))
;; Bug#40896
;; ((eq shell-command-dont-erase-buffer 'end-last-out)
;; (should (string-equal "foobazzbar" (buffer-string)))
;; (should (= 7 (point))))
((eq shell-command-dont-erase-buffer 'save-point)
(should (string-equal "foobazzbar" (buffer-string)))
(should (= 4 (point))))
;; Bug#40896
;; ((eq shell-command-dont-erase-buffer 'random)
;; (should (string-equal "foobazzbar" (buffer-string)))
;; (should (= 7 (point))))))
))
;; Don't erase if the buffer is not the current one and (t ;; not current buffer
;; `shell-command-dont-erase-buffer' is set to ;; String is appended, and point is at point-max unless
;; `beg-last-out'. Check point. ;; dictated otherwise.
(let ((shell-command-dont-erase-buffer 'beg-last-out)) (cond
(with-current-buffer buffer ((null shell-command-dont-erase-buffer)
(erase-buffer) (should (string-equal "bazz" (buffer-string)))
(insert "bar") (should (= 5 (point))))
(setq point (point)) ((eq shell-command-dont-erase-buffer 'erase)
(should (string-equal "bar" (buffer-string))) (should (string-equal "bazz" (buffer-string)))
(should (= (point) (point-max))) (should (= 5 (point))))
(with-temp-buffer ((eq shell-command-dont-erase-buffer 'beg-last-out)
(shell-command "echo baz" buffer)) (should (string-equal "foobarbazz" (buffer-string)))
(should (string-equal "barbaz\n" (buffer-string))) (should (= 7 (point))))
;; There is still an error in Tramp. ;; ;; Bug#40896
(unless (file-remote-p default-directory) ;; ((eq shell-command-dont-erase-buffer 'end-last-out)
(should (= point (point))) ;; (should (string-equal "foobarbazz" (buffer-string)))
(should-not (= (point) (point-max)))))) ;; (should (= 11 (point))))
((eq shell-command-dont-erase-buffer 'save-point)
;; Don't erase if the buffer is the current one and (should (string-equal "foobarbazz" (buffer-string)))
;; `shell-command-dont-erase-buffer' is set to (should (= 4 (point))))
;; `end-last-out'. Check point. ;; ;; Bug#40896
(let ((shell-command-dont-erase-buffer 'end-last-out)) ;; ((eq shell-command-dont-erase-buffer 'random)
(with-temp-buffer ;; (should (string-equal "foobarbazz" (buffer-string)))
(insert "bar") ;; (should (= 11 (point)))))))))))))
(setq point (point)) )))))))))
(should (string-equal "bar" (buffer-string)))
(should (= (point) (point-max)))
(shell-command "echo baz" (current-buffer))
(should (string-equal "barbaz\n" (buffer-string)))
;; This does not work as expected in the local case.
;; Therefore, we negate the test for the time being.
(should-not
(funcall (if (file-remote-p default-directory) #'identity #'not)
(= point (point))))
(should
(funcall (if (file-remote-p default-directory) #'identity #'not)
(= (point) (point-max))))))
;; Don't erase if the buffer is not the current one and
;; `shell-command-dont-erase-buffer' is set to
;; `end-last-out'. Check point.
(let ((shell-command-dont-erase-buffer 'end-last-out))
(with-current-buffer buffer
(erase-buffer)
(insert "bar")
(setq point (point))
(should (string-equal "bar" (buffer-string)))
(should (= (point) (point-max)))
(with-temp-buffer
(shell-command "echo baz" buffer))
(should (string-equal "barbaz\n" (buffer-string)))
;; There is still an error in Tramp.
(unless (file-remote-p default-directory)
(should-not (= point (point)))
(should (= (point) (point-max))))))
;; Don't erase if the buffer is the current one and
;; `shell-command-dont-erase-buffer' is set to
;; `save-point'. Check point.
(let ((shell-command-dont-erase-buffer 'save-point))
(with-temp-buffer
(insert "bar")
(goto-char (1- (point-max)))
(setq point (point))
(should (string-equal "bar" (buffer-string)))
(should (= (point) (1- (point-max))))
(shell-command "echo baz" (current-buffer))
(should (string-equal "babaz\nr" (buffer-string)))
;; There is still an error in Tramp.
(unless (file-remote-p default-directory)
(should (= point (point)))
(should-not (= (point) (point-max))))))
;; Don't erase if the buffer is not the current one and
;; `shell-command-dont-erase-buffer' is set to
;; `save-point'. Check point.
(let ((shell-command-dont-erase-buffer 'save-point))
(with-current-buffer buffer
(erase-buffer)
(insert "bar")
(goto-char (1- (point-max)))
(setq point (point))
(should (string-equal "bar" (buffer-string)))
(should (= (point) (1- (point-max))))
(with-temp-buffer
(shell-command "echo baz" buffer))
;; This does not work as expected. Therefore, we
;; use the "wrong" string.
(should (string-equal "barbaz\n" (buffer-string)))
;; There is still an error in Tramp.
(unless (file-remote-p default-directory)
(should (= point (point)))
(should-not (= (point) (point-max))))))
;; Don't erase if the buffer is the current one and
;; `shell-command-dont-erase-buffer' is set to a random
;; value. Check point.
(let ((shell-command-dont-erase-buffer 'random))
(with-temp-buffer
(insert "bar")
(setq point (point))
(should (string-equal "bar" (buffer-string)))
(should (= (point) (point-max)))
(shell-command "echo baz" (current-buffer))
(should (string-equal "barbaz\n" (buffer-string)))
;; This does not work as expected in the local case.
;; Therefore, we negate the test for the time being.
(should-not
(funcall (if (file-remote-p default-directory) #'identity #'not)
(= point (point))))
(should
(funcall (if (file-remote-p default-directory) #'identity #'not)
(= (point) (point-max))))))
;; Don't erase if the buffer is not the current one and
;; `shell-command-dont-erase-buffer' is set to a random
;; value. Check point.
(let ((shell-command-dont-erase-buffer 'random))
(with-current-buffer buffer
(erase-buffer)
(insert "bar")
(setq point (point))
(should (string-equal "bar" (buffer-string)))
(should (= (point) (point-max)))
(with-temp-buffer
(shell-command "echo baz" buffer))
(should (string-equal "barbaz\n" (buffer-string)))
;; There is still an error in Tramp.
(unless (file-remote-p default-directory)
(should-not (= point (point)))
(should (= (point) (point-max)))))))
;; Cleanup.
(ignore-errors (kill-buffer buffer))))))
;; This test is inspired by Bug#23952. ;; This test is inspired by Bug#23952.
(ert-deftest tramp-test33-environment-variables () (ert-deftest tramp-test33-environment-variables ()

View file

@ -760,11 +760,12 @@ See Bug#21722."
(let* ((str "foo\\n") (let* ((str "foo\\n")
(expected-point `((beg-last-out . ,(1+ (length str))) (expected-point `((beg-last-out . ,(1+ (length str)))
(end-last-out . ,(1+ (* 2 (length str)))) (end-last-out . ,(1+ (* 2 (length str))))
(save-point . 1)))) (save-point . 1)
(erase . ,(1+ (length str)))
(nil . ,(1+ (length str))))))
(dolist (output-buffer-is-current '(nil)) (dolist (output-buffer-is-current '(nil))
(with-shell-command-dont-erase-buffer str output-buffer-is-current (with-shell-command-dont-erase-buffer str output-buffer-is-current
(when (memq shell-command-dont-erase-buffer '(beg-last-out end-last-out save-point)) (should (= (point) (alist-get shell-command-dont-erase-buffer expected-point)))))))
(should (= (point) (alist-get shell-command-dont-erase-buffer expected-point))))))))
(provide 'simple-test) (provide 'simple-test)