From 55f5708cc084d8f986ac892aee85525f1cd292b5 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Wed, 16 Jun 2021 19:06:51 -0500 Subject: [PATCH] Tests: Fix link-to-self-buffer-search test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also, ensure that views that search non-file-backed buffers can’t be linked to. This fixes the test failures on Emacs 27.2 and Emacs 28 pre-release. (I can't explain why this test didn't fail on earlier versions, but it's not worth figuring out.) --- tests/test-org-ql.el | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/tests/test-org-ql.el b/tests/test-org-ql.el index 1692c38..25e8a2b 100644 --- a/tests/test-org-ql.el +++ b/tests/test-org-ql.el @@ -1626,10 +1626,44 @@ RESULTS should be a list of strings as returned by :store-input "M-n M-n RET") :to-equal temp-filenames)) (it "Can search buffer containing the link" - ;; This is sort-of a special case because of how the test link-opening function works. - (expect (var-after-link-save-open 'org-ql-view-buffers-files one-filename query + ;; The purpose of this test is to ensure that links that search whichever buffer contains the link + ;; search the buffer that contains the link. This only applies to file-backed buffers. The code is + ;; messy because it requires doing things like switching between buffers and emulating user input. + (let ((temp-file (make-temp-file "org-ql-test-" nil ".org")) + (view-buffer (get-buffer-create "*Org QL View TEST BUFFER*"))) + (unwind-protect + (progn + (with-temp-file temp-file + ;; See function `var-after-link-save-open`. + (insert "* TODO Test heading\n\n")) + (find-file temp-file) + (org-ql-search (current-buffer) query + :buffer view-buffer) + (cl-assert (member '("org-ql-search" :follow org-ql-view--link-follow :store org-ql-view--link-store) + org-link-parameters) + t) + (with-current-buffer view-buffer + (with-simulated-input "RET" + ;; Avoid writing "Stored: ..." to test output. + (let ((inhibit-message t)) + (call-interactively #'org-store-link nil)))) + (cl-assert (and org-stored-links (caar org-stored-links)) t) + (with-current-buffer (find-buffer-visiting temp-file) + (goto-char (point-max)) + (with-simulated-input "RET RET" + (call-interactively #'org-insert-link)) + (save-buffer) + (backward-char 1) + (with-simulated-input "RET" + (org-open-at-point))) + (with-current-buffer view-buffer + (expect org-ql-view-buffers-files + :to-equal (find-buffer-visiting temp-file)))) + (delete-file temp-file nil)))) + (it "Refuses to link to non-file-backed buffer" + (expect (var-after-link-save-open 'org-ql-view-buffers-files link-buffer query :buffer link-buffer) - :to-equal link-buffer))))) + :to-throw 'user-error '("Views that search non-file-backed buffers can’t be linked to")))))) ;; MAYBE: Also test `org-ql-views', although I already know it works now. ;; (describe "org-ql-views")