summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/lisp/shell-tests.el10
-rw-r--r--test/lisp/simple-tests.el56
2 files changed, 65 insertions, 1 deletions
diff --git a/test/lisp/shell-tests.el b/test/lisp/shell-tests.el
index 7113cb941c1..606de15c9a6 100644
--- a/test/lisp/shell-tests.el
+++ b/test/lisp/shell-tests.el
@@ -34,7 +34,15 @@
(with-temp-buffer
(shell-mode)
(insert "cd ba;")
+ (forward-char -1)
(should (equal (shell--parse-pcomplete-arguments)
- '(("cd" "ba" "") 1 4)))))
+ '(("cd" "ba") 1 4)))))
+
+(ert-deftest shell-tests-completion-after-semi ()
+ (with-temp-buffer
+ (shell-mode)
+ (insert "cd ba;")
+ (should (equal (shell--parse-pcomplete-arguments)
+ '(("cd" "ba" "") 1 4 7)))))
;;; shell-tests.el ends here
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index 2611519d074..276df795fca 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -711,5 +711,61 @@ See Bug#21722."
(when process (delete-process process))
(when buffer (kill-buffer buffer)))))))
+
+;;; Tests for shell-command-dont-erase-buffer
+
+(defmacro with-shell-command-dont-erase-buffer (str output-buffer-is-current &rest body)
+ (declare (debug (form &body)) (indent 2))
+ (let ((expected (make-symbol "expected"))
+ (command (make-symbol "command"))
+ (caller-buf (make-symbol "caller-buf"))
+ (output-buf (make-symbol "output-buf")))
+ `(let* ((,caller-buf (generate-new-buffer "caller-buf"))
+ (,output-buf (if ,output-buffer-is-current ,caller-buf
+ (generate-new-buffer "output-buf")))
+ (emacs (expand-file-name invocation-name invocation-directory))
+ (,command (format "%s -Q --batch --eval '(princ \"%s\")'"
+ emacs ,str))
+ (inhibit-message t))
+ (unwind-protect
+ ;; Feature must work the same regardless how we specify the 2nd arg of `shell-command', ie,
+ ;; as a buffer, buffer name (or t, if the output must go to the current buffer).
+ (dolist (output (append (list ,output-buf (buffer-name ,output-buf))
+ (if ,output-buffer-is-current '(t) nil)))
+ (dolist (save-pos '(erase nil beg-last-out end-last-out save-point))
+ (let ((shell-command-dont-erase-buffer save-pos))
+ (with-current-buffer ,output-buf (erase-buffer))
+ (with-current-buffer ,caller-buf
+ (dotimes (_ 2) (shell-command ,command output)))
+ (with-current-buffer ,output-buf
+ ,@body))))
+ (kill-buffer ,caller-buf)
+ (when (buffer-live-p ,output-buf)
+ (kill-buffer ,output-buf))))))
+
+(ert-deftest simple-tests-shell-command-39067 ()
+ "The output buffer is erased or not according to `shell-command-dont-erase-buffer'."
+ (let ((str "foo\n"))
+ (dolist (output-current '(t nil))
+ (with-shell-command-dont-erase-buffer str output-current
+ (let ((expected (cond ((eq shell-command-dont-erase-buffer 'erase) str)
+ ((null shell-command-dont-erase-buffer)
+ (if output-current (concat str str)
+ str))
+ (t (concat str str)))))
+ (should (string= expected (buffer-string))))))))
+
+(ert-deftest simple-tests-shell-command-dont-erase-buffer ()
+ "The point is set at the expected position after execution of the command."
+ (let* ((str "foo\n")
+ (expected-point `((beg-last-out . ,(1+ (length str)))
+ (end-last-out . ,(1+ (* 2 (length str))))
+ (save-point . 1))))
+ (dolist (output-buffer-is-current '(t ni))
+ (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))))))))
+
+
(provide 'simple-test)
;;; simple-test.el ends here