Tests: Use test buffer for link safety tests

This commit is contained in:
Adam Porter 2020-11-13 02:42:52 -06:00
parent 56647d4b11
commit b90e6e25d0

View file

@ -1172,9 +1172,17 @@ RESULTS should be a list of strings as returned by
(require 'org-ql-search) (require 'org-ql-search)
(require 'org-ql-view) (require 'org-ql-view)
;; The :auto-map test requires there to be results (because the org-super-agenda :auto-map group's
;; key-form, where the safety check is, only gets evaluated when there are results). Using
;; `with-temp-buffer' in the `open-link' function causes the temp buffer to be killed before the results
;; have a chance to be gathered. So we make a test buffer and run the test in that, with a test heading.
(let ((test-buffer (get-buffer-create "*test-org-ql*")))
(cl-flet ((open-link (cl-flet ((open-link
(link) (with-temp-buffer (link) (with-current-buffer test-buffer
(erase-buffer)
(org-mode) (org-mode)
(insert "* TODO Test heading \n\n")
(insert link) (insert link)
(backward-char 1) (backward-char 1)
(call-interactively #'org-open-at-point)))) (call-interactively #'org-open-at-point))))
@ -1244,7 +1252,7 @@ RESULTS should be a list of strings as returned by
(expect (open-link quoted-lambda-in-list-link) (expect (open-link quoted-lambda-in-list-link)
:to-throw 'error '("Potentially unsafe value found in links SORT parameter (((quote (lambda (_ _) (message AHA))))). Link not opened")) :to-throw 'error '("Potentially unsafe value found in links SORT parameter (((quote (lambda (_ _) (message AHA))))). Link not opened"))
(expect (open-link unquoted-lambda-in-list-link) (expect (open-link unquoted-lambda-in-list-link)
:to-throw 'error '("Potentially unsafe value found in links SORT parameter (((lambda nil (message AHA)))). Link not opened"))))))) :to-throw 'error '("Potentially unsafe value found in links SORT parameter (((lambda nil (message AHA)))). Link not opened"))))))))
;; Local Variables: ;; Local Variables:
;; truncate-lines: t ;; truncate-lines: t