From a02514c0dc8dfef1e8425a93cd23d91e72fbc1d5 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Tue, 17 Nov 2020 00:24:26 -0600 Subject: [PATCH] Tests: Test dynamic block sexp query warning --- tests/test-org-ql.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test-org-ql.el b/tests/test-org-ql.el index e1c40d5..7dad757 100644 --- a/tests/test-org-ql.el +++ b/tests/test-org-ql.el @@ -1406,6 +1406,34 @@ RESULTS should be a list of strings as returned by (mapcar #'find-file-noselect temp-filenames) query) :to-equal temp-filenames))))) + (describe "Dynamic blocks" + (describe "warn about sexp queries" + + (cl-flet ((test-dblock + (&optional input) (with-current-buffer (get-buffer-create "*TEST DBLOCK*") + (erase-buffer) + (org-mode) + (insert "* TODO Heading 1\n\n" + "#+BEGIN: org-ql :query (or (todo) (regexp \"Heading\")) :columns (todo)\n" + "#+END:") + (goto-char (point-min)) + (forward-line 2) + (with-simulated-input input + (org-dblock-update)) + (kill-buffer)))) + + (it "when org-ql-ask-unsafe-queries is non-nil" + ;; TODO: Should the query be converted to string form if possible and only warn if not? + (let ((org-ql-ask-unsafe-queries t)) + (expect (test-dblock "no RET") + :to-throw 'user-error '("Query aborted by user")))) + + (it "unless org-ql-ask-unsafe-queries is nil" + ;; TODO: Should the query be converted to string form if possible and only warn if not? + (let ((org-ql-ask-unsafe-queries nil)) + (expect (test-dblock) + :not :to-throw)))))) + (describe "Links" ;; Not sure if this binding works. :var ((title "ORG-QL-TEST")