;;; tests/eshell.el --- Eshell test suite
-;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
;; Author: John Wiegley <johnw@gnu.org>
(funcall (or func 'eshell-send-input)))
(defun eshell-match-result (regexp)
- "Insert a command at the end of the buffer."
+ "Check that text after `eshell-last-input-end' matches REGEXP."
(goto-char eshell-last-input-end)
- (looking-at regexp))
+ (should (string-match-p regexp (buffer-substring-no-properties
+ (point) (point-max)))))
(defun eshell-command-result-p (text regexp &optional func)
"Insert a command at the end of the buffer."
"Like `eshell-command-result', but not using HOME."
(let ((eshell-directory-name (make-temp-file "eshell" t))
(eshell-history-file-name nil))
- (eshell-command-result command)))
+ (unwind-protect
+ (eshell-command-result command)
+ (delete-directory eshell-directory-name t))))
;;; Tests:
(should (equal (eshell-test-command-result "(+ 1 2)") 3)))
(ert-deftest eshell-test/for-loop ()
- "Test `eshell-command-result' with an elisp command."
- (should (equal (eshell-test-command-result "for foo in 5 { echo $foo }") 5)))
+ "Test `eshell-command-result' with a for loop.."
+ (let ((process-environment (cons "foo" process-environment)))
+ (should (equal (eshell-test-command-result
+ "for foo in 5 { echo $foo }") 5))))
(ert-deftest eshell-test/for-name-loop () ;Bug#15231
- "Test `eshell-command-result' with an elisp command."
- (should (equal (eshell-test-command-result "for name in 3 { echo $name }") 3)))
+ "Test `eshell-command-result' with a for loop using `name'."
+ (let ((process-environment (cons "name" process-environment)))
+ (should (equal (eshell-test-command-result
+ "for name in 3 { echo $name }") 3))))
+
+(ert-deftest eshell-test/for-name-shadow-loop () ; bug#15372
+ "Test `eshell-command-result' with a for loop using an env-var."
+ (let ((process-environment (cons "name=env-value" process-environment)))
+ (with-temp-eshell
+ (eshell-command-result-p "echo $name; for name in 3 { echo $name }; echo $name"
+ "env-value\n3\nenv-value\n"))))
(ert-deftest eshell-test/lisp-command-args ()
"Test `eshell-command-result' with elisp and trailing args.
(ert-deftest eshell-test/last-result-var ()
"Test using the \"last result\" ($$) variable"
(with-temp-eshell
- (should
- (eshell-command-result-p "+ 1 2; + $$ 2"
- "3\n5\n"))))
+ (eshell-command-result-p "+ 1 2; + $$ 2"
+ "3\n5\n")))
(ert-deftest eshell-test/last-result-var2 ()
"Test using the \"last result\" ($$) variable twice"
(with-temp-eshell
- (should
- (eshell-command-result-p "+ 1 2; + $$ $$"
- "3\n6\n"))))
+ (eshell-command-result-p "+ 1 2; + $$ $$"
+ "3\n6\n")))
(ert-deftest eshell-test/last-arg-var ()
"Test using the \"last arg\" ($_) variable"
(with-temp-eshell
- (should
- (eshell-command-result-p "+ 1 2; + $_ 4"
- "3\n6\n"))))
+ (eshell-command-result-p "+ 1 2; + $_ 4"
+ "3\n6\n")))
(ert-deftest eshell-test/command-running-p ()
"Modeline should show no command running"
(> count 0))
(sit-for 1)
(setq count (1- count))))
- (should (eshell-match-result "alpha\n"))))
+ (eshell-match-result "alpha\n")))
(ert-deftest eshell-test/flush-output ()
"Test flushing of previous output"
(with-temp-eshell
(eshell-insert-command "echo alpha")
(eshell-kill-output)
- (should (eshell-match-result (regexp-quote "*** output flushed ***\n")))
+ (eshell-match-result (regexp-quote "*** output flushed ***\n"))
(should (forward-line))
(should (= (point) eshell-last-output-start))))