aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJim Porter2022-01-19 18:59:23 -0800
committerLars Ingebrigtsen2022-01-21 13:06:11 +0100
commit90de226e218883f2a62ce3e1ba9a79ef8e1be70c (patch)
tree64790dd0034f28081c7a89f61d477500d3612911 /test
parenta133af7c7f3aa2fd7fb4fea9c54cd082ed1481f3 (diff)
downloademacs-90de226e218883f2a62ce3e1ba9a79ef8e1be70c.tar.gz
emacs-90de226e218883f2a62ce3e1ba9a79ef8e1be70c.zip
Raise an error from 'eval-eval-using-options' for unknown options
* lisp/eshell/em-basic.el (eshell/echo): Add -E option. * lisp/eshell/esh-opt.el (eshell--process-option): Raise an error if an unknown option is encountered, even when :external is nil. * test/lisp/eshell/esh-opt-tests.el (esh-opt-process-args-test) (test-eshell-eval-using-options): Add test cases for this.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/eshell/esh-opt-tests.el86
1 files changed, 64 insertions, 22 deletions
diff --git a/test/lisp/eshell/esh-opt-tests.el b/test/lisp/eshell/esh-opt-tests.el
index 255768635b1..b76ed8866df 100644
--- a/test/lisp/eshell/esh-opt-tests.el
+++ b/test/lisp/eshell/esh-opt-tests.el
@@ -27,41 +27,63 @@
27 (should 27 (should
28 (equal '(t) 28 (equal '(t)
29 (eshell--process-args 29 (eshell--process-args
30 "sudo" 30 "sudo" '("-a")
31 '("-a") 31 '((?a "all" nil show-all
32 '((?a "all" nil show-all ""))))) 32 "do not ignore entries starting with .")))))
33 (should
34 (equal '(nil)
35 (eshell--process-args
36 "sudo"
37 '("-g")
38 '((?a "all" nil show-all "")))))
39 (should 33 (should
40 (equal '("root" "world") 34 (equal '("root" "world")
41 (eshell--process-args 35 (eshell--process-args
42 "sudo" 36 "sudo" '("-u" "root" "world")
43 '("-u" "root" "world") 37 '((?u "user" t user
44 '((?u "user" t user "execute a command as another USER"))))) 38 "execute a command as another USER")))))
45 (should 39 (should
46 (equal '(nil "emerge" "-uDN" "world") 40 (equal '(nil "emerge" "-uDN" "world")
47 (eshell--process-args 41 (eshell--process-args
48 "sudo" 42 "sudo" '("emerge" "-uDN" "world")
49 '("emerge" "-uDN" "world") 43 '((?u "user" t user
50 '((?u "user" t user "execute a command as another USER") 44 "execute a command as another USER")
51 :parse-leading-options-only)))) 45 :parse-leading-options-only))))
52 (should 46 (should
53 (equal '("root" "emerge" "-uDN" "world") 47 (equal '("root" "emerge" "-uDN" "world")
54 (eshell--process-args 48 (eshell--process-args
55 "sudo" 49 "sudo" '("-u" "root" "emerge" "-uDN" "world")
56 '("-u" "root" "emerge" "-uDN" "world") 50 '((?u "user" t user
57 '((?u "user" t user "execute a command as another USER") 51 "execute a command as another USER")
58 :parse-leading-options-only)))) 52 :parse-leading-options-only))))
59 (should 53 (should
60 (equal '("DN" "emerge" "world") 54 (equal '("DN" "emerge" "world")
61 (eshell--process-args 55 (eshell--process-args
62 "sudo" 56 "sudo" '("-u" "root" "emerge" "-uDN" "world")
63 '("-u" "root" "emerge" "-uDN" "world") 57 '((?u "user" t user
64 '((?u "user" t user "execute a command as another USER")))))) 58 "execute a command as another USER")))))
59
60 ;; Test :external.
61 (cl-letf (((symbol-function 'eshell-search-path) #'ignore))
62 (should
63 (equal '(nil "/some/path")
64 (eshell--process-args
65 "ls" '("/some/path")
66 '((?a "all" nil show-all
67 "do not ignore entries starting with .")
68 :external "ls")))))
69 (cl-letf (((symbol-function 'eshell-search-path) #'identity))
70 (should
71 (equal '(no-catch eshell-ext-command "ls")
72 (should-error
73 (eshell--process-args
74 "ls" '("-u" "/some/path")
75 '((?a "all" nil show-all
76 "do not ignore entries starting with .")
77 :external "ls"))
78 :type 'no-catch))))
79 (cl-letf (((symbol-function 'eshell-search-path) #'ignore))
80 (should-error
81 (eshell--process-args
82 "ls" '("-u" "/some/path")
83 '((?a "all" nil show-all
84 "do not ignore entries starting with .")
85 :external "ls"))
86 :type 'error)))
65 87
66(ert-deftest test-eshell-eval-using-options () 88(ert-deftest test-eshell-eval-using-options ()
67 "Tests for `eshell-eval-using-options'." 89 "Tests for `eshell-eval-using-options'."
@@ -190,7 +212,27 @@
190 '((?u "user" t user "execute a command as another USER") 212 '((?u "user" t user "execute a command as another USER")
191 :parse-leading-options-only) 213 :parse-leading-options-only)
192 (should (eq user nil)) 214 (should (eq user nil))
193 (should (equal args '("emerge" "-uDN" "world"))))) 215 (should (equal args '("emerge" "-uDN" "world"))))
216
217 ;; Test unrecognized options.
218 (should-error
219 (eshell-eval-using-options
220 "ls" '("-u" "/some/path")
221 '((?a "all" nil show-all
222 "do not ignore entries starting with ."))
223 (ignore show-all)))
224 (should-error
225 (eshell-eval-using-options
226 "ls" '("-au" "/some/path")
227 '((?a "all" nil show-all
228 "do not ignore entries starting with ."))
229 (ignore show-all)))
230 (should-error
231 (eshell-eval-using-options
232 "ls" '("--unrecognized" "/some/path")
233 '((?a "all" nil show-all
234 "do not ignore entries starting with ."))
235 (ignore show-all))))
194 236
195(provide 'esh-opt-tests) 237(provide 'esh-opt-tests)
196 238