diff options
| author | Jim Porter | 2024-10-21 15:41:42 -0700 |
|---|---|---|
| committer | Jim Porter | 2024-10-31 22:38:10 -0700 |
| commit | 9682d385c103a9ee1afdeaf3e1711fa3d2001eee (patch) | |
| tree | 15547d9f7baa2c677ea73855ce3d099e1bf00175 /test | |
| parent | 98e24e369a3f6bed95cdf0b32ee03999f5dfb98b (diff) | |
| download | emacs-9682d385c103a9ee1afdeaf3e1711fa3d2001eee.tar.gz emacs-9682d385c103a9ee1afdeaf3e1711fa3d2001eee.zip | |
Improve correctness of Eshell globs when using escape characters
This new implementation opts *in* to treating characters as glob
characters, rather than opting out. This reduces the need to coordinate
with other parts of Eshell and should be harder to break (bug#74033).
* lisp/eshell/em-glob.el (eshell-parse-glob-chars): Return the
propertized globbing character directly.
(eshell--propertize-glob, eshell--glob-char-p)
(eshell--contains-glob-char-p, eshell--all-glob-chars-p): New functions.
(eshell-glob-p): Make obsolete.
(eshell-glob-regexp, eshell-glob-convert-1, eshell-glob-convert): Check
for 'eshell-glob-char' property.
(eshell-extended-glob): Remove text properties when returning no match.
(eshell--glob-anything): New constant.
(eshell-glob-entries): Propertize "*" to treat it as a glob.
* lisp/eshell/em-ls.el (eshell-ls--expand-wildcards): New function...
(eshell-ls--insert-directory): ... use it.
* test/lisp/eshell/em-glob-tests.el: Use 'eshell--propertize-glob' in
tests.
(em-glob-test/convert/literal-characters)
(em-glob-test/convert/mixed-literal-characters): New tests.
* lisp/eshell/em-glob.el (eshell-expand-glob): Rename from
'eshell-extended-glob'. Update callers.
(eshell-extended-glob): New function to expand a GLOB that hasn't been
propertized yet, for use outside of Eshell command forms.
(eshell-parse-glob-chars): Return the propertized globbing character
directly.
(eshell-parse-glob-string, eshell--glob-char-p)
(eshell--contains-glob-char-p, eshell--all-glob-chars-p): New functions.
(eshell-glob-regexp, eshell-glob-convert-1, eshell-glob-convert): Check
for 'eshell-glob-char' property.
(eshell-glob-p): Make obsolete.
(eshell--glob-anything): New constant...
(eshell-glob-entries): ... use it.
* lisp/eshell/em-ls.el (eshell-ls--expand-wildcards): New function...
(eshell-ls--insert-directory): ... use it.
* test/lisp/eshell/em-glob-tests.el: Use 'eshell-parse-glob-string in
tests.
(em-glob-test/convert/literal-characters)
(em-glob-test/convert/mixed-literal-characters): New tests.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/eshell/em-glob-tests.el | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/test/lisp/eshell/em-glob-tests.el b/test/lisp/eshell/em-glob-tests.el index 16ae9be1bce..57343eced6b 100644 --- a/test/lisp/eshell/em-glob-tests.el +++ b/test/lisp/eshell/em-glob-tests.el | |||
| @@ -134,17 +134,19 @@ value of `eshell-glob-splice-results'." | |||
| 134 | 134 | ||
| 135 | (ert-deftest em-glob-test/convert/current-start-directory () | 135 | (ert-deftest em-glob-test/convert/current-start-directory () |
| 136 | "Test converting a glob starting in the current directory." | 136 | "Test converting a glob starting in the current directory." |
| 137 | (should (equal (eshell-glob-convert "*.el") | 137 | (should (equal (eshell-glob-convert (eshell-parse-glob-string "*.el")) |
| 138 | '("./" (("\\`.*\\.el\\'" . "\\`\\.")) nil)))) | 138 | '("./" (("\\`.*\\.el\\'" . "\\`\\.")) nil)))) |
| 139 | 139 | ||
| 140 | (ert-deftest em-glob-test/convert/relative-start-directory () | 140 | (ert-deftest em-glob-test/convert/relative-start-directory () |
| 141 | "Test converting a glob starting in a relative directory." | 141 | "Test converting a glob starting in a relative directory." |
| 142 | (should (equal (eshell-glob-convert "some/where/*.el") | 142 | (should (equal (eshell-glob-convert |
| 143 | (eshell-parse-glob-string "some/where/*.el")) | ||
| 143 | '("./some/where/" (("\\`.*\\.el\\'" . "\\`\\.")) nil)))) | 144 | '("./some/where/" (("\\`.*\\.el\\'" . "\\`\\.")) nil)))) |
| 144 | 145 | ||
| 145 | (ert-deftest em-glob-test/convert/absolute-start-directory () | 146 | (ert-deftest em-glob-test/convert/absolute-start-directory () |
| 146 | "Test converting a glob starting in an absolute directory." | 147 | "Test converting a glob starting in an absolute directory." |
| 147 | (should (equal (eshell-glob-convert "/some/where/*.el") | 148 | (should (equal (eshell-glob-convert |
| 149 | (eshell-parse-glob-string "/some/where/*.el")) | ||
| 148 | '("/some/where/" (("\\`.*\\.el\\'" . "\\`\\.")) nil)))) | 150 | '("/some/where/" (("\\`.*\\.el\\'" . "\\`\\.")) nil)))) |
| 149 | 151 | ||
| 150 | (ert-deftest em-glob-test/convert/remote-start-directory () | 152 | (ert-deftest em-glob-test/convert/remote-start-directory () |
| @@ -152,16 +154,30 @@ value of `eshell-glob-splice-results'." | |||
| 152 | (skip-unless (eshell-tests-remote-accessible-p)) | 154 | (skip-unless (eshell-tests-remote-accessible-p)) |
| 153 | (let* ((default-directory ert-remote-temporary-file-directory) | 155 | (let* ((default-directory ert-remote-temporary-file-directory) |
| 154 | (remote (file-remote-p default-directory))) | 156 | (remote (file-remote-p default-directory))) |
| 155 | (should (equal (eshell-glob-convert (format "%s/some/where/*.el" remote)) | 157 | (should (equal (eshell-glob-convert |
| 158 | (format (eshell-parse-glob-string "%s/some/where/*.el") | ||
| 159 | remote)) | ||
| 156 | `(,(format "%s/some/where/" remote) | 160 | `(,(format "%s/some/where/" remote) |
| 157 | (("\\`.*\\.el\\'" . "\\`\\.")) nil))))) | 161 | (("\\`.*\\.el\\'" . "\\`\\.")) nil))))) |
| 158 | 162 | ||
| 159 | (ert-deftest em-glob-test/convert/quoted-start-directory () | 163 | (ert-deftest em-glob-test/convert/start-directory-with-spaces () |
| 160 | "Test converting a glob starting in a quoted directory name." | 164 | "Test converting a glob starting in a directory with spaces in its name." |
| 161 | (should (equal (eshell-glob-convert | 165 | (should (equal (eshell-glob-convert |
| 162 | (concat (eshell-escape-arg "some where/") "*.el")) | 166 | (eshell-parse-glob-string "some where/*.el")) |
| 163 | '("./some where/" (("\\`.*\\.el\\'" . "\\`\\.")) nil)))) | 167 | '("./some where/" (("\\`.*\\.el\\'" . "\\`\\.")) nil)))) |
| 164 | 168 | ||
| 169 | (ert-deftest em-glob-test/convert/literal-characters () | ||
| 170 | "Test converting a \"glob\" with only literal characters." | ||
| 171 | (should (equal (eshell-glob-convert "*.el") '("./*.el" nil nil))) | ||
| 172 | (should (equal (eshell-glob-convert "**/") '("./**/" nil t)))) | ||
| 173 | |||
| 174 | (ert-deftest em-glob-test/convert/mixed-literal-characters () | ||
| 175 | "Test converting a glob with some literal characters." | ||
| 176 | (should (equal (eshell-glob-convert (eshell-parse-glob-string "\\*\\*/*.el")) | ||
| 177 | '("./**/" (("\\`.*\\.el\\'" . "\\`\\.")) nil))) | ||
| 178 | (should (equal (eshell-glob-convert (eshell-parse-glob-string "**/\\*.el")) | ||
| 179 | '("./" (recurse ("\\`\\*\\.el\\'" . "\\`\\.")) nil)))) | ||
| 180 | |||
| 165 | 181 | ||
| 166 | ;; Glob matching | 182 | ;; Glob matching |
| 167 | 183 | ||
| @@ -262,11 +278,11 @@ value of `eshell-glob-splice-results'." | |||
| 262 | 278 | ||
| 263 | (ert-deftest em-glob-test/match-n-or-more-groups () | 279 | (ert-deftest em-glob-test/match-n-or-more-groups () |
| 264 | "Test that \"(x)#\" and \"(x)#\" match zero or more instances of \"(x)\"." | 280 | "Test that \"(x)#\" and \"(x)#\" match zero or more instances of \"(x)\"." |
| 265 | (with-fake-files '("h.el" "ha.el" "hi.el" "hii.el" "dir/hi.el") | 281 | (with-fake-files '("h.el" "ha.el" "hi.el" "hah.el" "hahah.el" "dir/hah.el") |
| 266 | (should (equal (eshell-extended-glob "hi#.el") | 282 | (should (equal (eshell-extended-glob "h(ah)#.el") |
| 267 | '("h.el" "hi.el" "hii.el"))) | 283 | '("h.el" "hah.el" "hahah.el"))) |
| 268 | (should (equal (eshell-extended-glob "hi##.el") | 284 | (should (equal (eshell-extended-glob "h(ah)##.el") |
| 269 | '("hi.el" "hii.el"))))) | 285 | '("hah.el" "hahah.el"))))) |
| 270 | 286 | ||
| 271 | (ert-deftest em-glob-test/match-n-or-more-character-sets () | 287 | (ert-deftest em-glob-test/match-n-or-more-character-sets () |
| 272 | "Test that \"[x]#\" and \"[x]#\" match zero or more instances of \"[x]\"." | 288 | "Test that \"[x]#\" and \"[x]#\" match zero or more instances of \"[x]\"." |
| @@ -300,11 +316,11 @@ value of `eshell-glob-splice-results'." | |||
| 300 | (ert-deftest em-glob-test/no-matches () | 316 | (ert-deftest em-glob-test/no-matches () |
| 301 | "Test behavior when a glob fails to match any files." | 317 | "Test behavior when a glob fails to match any files." |
| 302 | (with-fake-files '("foo.el" "bar.el") | 318 | (with-fake-files '("foo.el" "bar.el") |
| 303 | (should (equal (eshell-extended-glob "*.txt") | 319 | (should (equal-including-properties (eshell-extended-glob "*.txt") |
| 304 | "*.txt")) | 320 | "*.txt")) |
| 305 | (let ((eshell-glob-splice-results t)) | 321 | (let ((eshell-glob-splice-results t)) |
| 306 | (should (equal (eshell-extended-glob "*.txt") | 322 | (should (equal-including-properties (eshell-extended-glob "*.txt") |
| 307 | '("*.txt")))) | 323 | '("*.txt")))) |
| 308 | (let ((eshell-error-if-no-glob t)) | 324 | (let ((eshell-error-if-no-glob t)) |
| 309 | (should-error (eshell-extended-glob "*.txt"))))) | 325 | (should-error (eshell-extended-glob "*.txt"))))) |
| 310 | 326 | ||