aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPhilipp Stephani2021-04-18 21:57:59 +0200
committerPhilipp Stephani2021-04-18 21:59:25 +0200
commit652b0f4c7453e6d440fec767336ca85aec13e33d (patch)
tree287b1cc1fb320db1a289eb2f8c32bbdf21dce930 /test
parent6ebc6e12cfa8909655e3c0e722d3c5727ea418d8 (diff)
downloademacs-652b0f4c7453e6d440fec767336ca85aec13e33d.tar.gz
emacs-652b0f4c7453e6d440fec767336ca85aec13e33d.zip
Factor out a helper macro to create a temporary directory.
This is a useful abstraction, and saves a few levels of indentation in the test body. * test/lisp/progmodes/project-tests.el (project-tests--with-temporary-directory): New helper macro. (project/quoted-directory): Use it.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/progmodes/project-tests.el78
1 files changed, 44 insertions, 34 deletions
diff --git a/test/lisp/progmodes/project-tests.el b/test/lisp/progmodes/project-tests.el
index bb58f80d181..c8c03aa2579 100644
--- a/test/lisp/progmodes/project-tests.el
+++ b/test/lisp/progmodes/project-tests.el
@@ -27,49 +27,59 @@
27 27
28(require 'project) 28(require 'project)
29 29
30(require 'cl-lib)
30(require 'ert) 31(require 'ert)
31(require 'grep) 32(require 'grep)
32(require 'xref) 33(require 'xref)
33 34
35(defmacro project-tests--with-temporary-directory (var &rest body)
36 "Create a new temporary directory.
37Bind VAR to the name of the directory, and evaluate BODY. Delete
38the directory after BODY exits."
39 (declare (debug (symbolp body)) (indent 1))
40 (cl-check-type var symbol)
41 (let ((directory (make-symbol "directory")))
42 `(let ((,directory (make-temp-file "project-tests-" :directory)))
43 (unwind-protect
44 (let ((,var ,directory))
45 ,@body)
46 (delete-directory ,directory :recursive)))))
47
34(ert-deftest project/quoted-directory () 48(ert-deftest project/quoted-directory ()
35 "Check that `project-files' and `project-find-regexp' deal with 49 "Check that `project-files' and `project-find-regexp' deal with
36quoted directory names (Bug#47799)." 50quoted directory names (Bug#47799)."
37 (skip-unless (executable-find find-program)) 51 (skip-unless (executable-find find-program))
38 (skip-unless (executable-find "xargs")) 52 (skip-unless (executable-find "xargs"))
39 (skip-unless (executable-find "grep")) 53 (skip-unless (executable-find "grep"))
40 (let ((directory (make-temp-file "project-tests-" :directory))) 54 (project-tests--with-temporary-directory directory
41 (unwind-protect 55 (let ((default-directory directory)
42 (let ((default-directory directory) 56 (project-current-inhibit-prompt t)
43 (project-current-inhibit-prompt t) 57 (project-find-functions nil)
44 (project-find-functions nil) 58 (project-list-file
45 (project-list-file 59 (expand-file-name "projects" directory))
46 (expand-file-name "projects" directory)) 60 (project (cons 'transient (file-name-quote directory)))
47 (project (cons 'transient (file-name-quote directory))) 61 (file (expand-file-name "file" directory)))
48 (file (expand-file-name "file" directory))) 62 (add-hook 'project-find-functions (lambda (_dir) project))
49 (add-hook 'project-find-functions (lambda (_dir) project)) 63 (should (eq (project-current) project))
50 (should (eq (project-current) project)) 64 (write-region "contents" nil file nil nil nil 'excl)
51 (write-region "contents" nil file nil nil nil 'excl) 65 (should (equal (project-files project)
52 (should (equal (project-files project) 66 (list (file-name-quote file))))
53 (list (file-name-quote file)))) 67 (let* ((references nil)
54 (let* ((references nil) 68 (xref-search-program 'grep)
55 (xref-search-program 'grep) 69 (xref-show-xrefs-function
56 (xref-show-xrefs-function 70 (lambda (fetcher _display)
57 (lambda (fetcher _display) 71 (push (funcall fetcher) references))))
58 (push (funcall fetcher) references)))) 72 (project-find-regexp "tent")
59 (project-find-regexp "tent") 73 (pcase references
60 (pcase references 74 (`((,item))
61 (`((,item)) 75 ;; FIXME: Shouldn't `xref-match-item' be a subclass of
62 (should 76 ;; `xref-item'?
63 ;; FIXME: Shouldn't `xref-match-item' be a subclass of 77 (should (cl-typep item '(or xref-item xref-match-item)))
64 ;; `xref-item'? 78 (should (file-equal-p
65 (cl-typep item '(or xref-item xref-match-item))) 79 (xref-location-group (xref-item-location item))
66 (should 80 file)))
67 (file-equal-p 81 (otherwise
68 (xref-location-group (xref-item-location item)) 82 (ert-fail (format-message "Unexpected references: %S"
69 file))) 83 otherwise))))))))
70 (otherwise
71 (ert-fail (format-message "Unexpected references: %S"
72 otherwise))))))
73 (delete-directory directory :recursive))))
74 84
75;;; project-tests.el ends here 85;;; project-tests.el ends here