diff options
author | Jim Porter <jporterbugs@gmail.com> | 2022-06-25 20:05:57 -0700 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-06-26 16:51:21 +0200 |
commit | 598d7c5d1c10bfb161cb53aa76d480864414487c (patch) | |
tree | 42d650e0476b281145c650dbe095e8e651b60a18 /test/lisp/eshell/em-pred-tests.el | |
parent | b637d9c0750fde8810058a153d964b6c70e0f577 (diff) | |
download | emacs-598d7c5d1c10bfb161cb53aa76d480864414487c.tar.gz emacs-598d7c5d1c10bfb161cb53aa76d480864414487c.tar.bz2 emacs-598d7c5d1c10bfb161cb53aa76d480864414487c.zip |
Optionally signal an error if an Eshell predicate fails to match anything
* lisp/eshell/em-pred.el (eshell-error-if-no-glob): Declare it.
(eshell-apply-modifiers): Add STRING-DESC argument and signal an error
if there are no matches and 'eshell-error-if-no-glob' is set.
(eshell-parse-arg-modifier): Pass modifier string to
'eshell-apply-modifiers'.
* test/lisp/eshell/em-pred-tests.el (eshell-eval-predicate): Simplify.
(em-pred-test/no-matches): New test.
* doc/misc/eshell.texi (Bugs and ideas): Remove todo entry about this
change.
Diffstat (limited to 'test/lisp/eshell/em-pred-tests.el')
-rw-r--r-- | test/lisp/eshell/em-pred-tests.el | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/test/lisp/eshell/em-pred-tests.el b/test/lisp/eshell/em-pred-tests.el index 3b50543d69a..c8c1a6a9317 100644 --- a/test/lisp/eshell/em-pred-tests.el +++ b/test/lisp/eshell/em-pred-tests.el @@ -26,6 +26,7 @@ (require 'ert) (require 'esh-mode) (require 'eshell) +(require 'em-glob) (require 'em-pred) (require 'eshell-tests-helpers @@ -39,10 +40,9 @@ "Evaluate PREDICATE on INITIAL-VALUE, returning the result. PREDICATE is an Eshell argument predicate/modifier." (let ((eshell-test-value initial-value)) - (with-temp-eshell - (eshell-insert-command - (format "setq eshell-test-value $eshell-test-value(%s)" predicate))) - eshell-test-value)) + (ignore-errors + (eshell-test-command-result + (format "echo $eshell-test-value(%s)" predicate))))) (defun eshell-parse-file-name-attributes (file) "Parse a fake FILE name to determine its attributes. @@ -545,4 +545,22 @@ PREDICATE is the predicate used to query that attribute." (should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":j'\\\"'") "foo\\\"bar\\\"baz"))) +(ert-deftest em-pred-test/no-matches () + "Test behavior when a predicate fails to match any files." + (eshell-with-file-attributes-from-name + (let ((files '("/fake/modes=0666" "/fake/type=d,modes=0777" + "/fake/type=l,modes=0777"))) + (should (equal (eshell-eval-predicate files "*") nil)) + (let ((eshell-error-if-no-glob t)) + ;; Don't signal an error if the original list is empty. + (should (equal (eshell-eval-predicate nil "*") nil)) + ;; Ensure this signals an error. This test case is a bit + ;; clumsy, since `eshell-do-eval' makes it hard to catch + ;; errors otherwise. + (let ((modifiers (with-temp-eshell + (eshell-with-temp-command "*" + (eshell-parse-modifiers))))) + (should-error (eshell-apply-modifiers files (car modifiers) + (cdr modifiers) "*"))))))) + ;; em-pred-tests.el ends here |