branch: externals/org
commit cc3976c3eafcbad5092baea9f05f424801f0cad8
Author: Morgan Smith <[email protected]>
Commit: Ihor Radchenko <[email protected]>
testing: Suppress interactive prompts during testing and on quit
Running the tests interactively would give the user multiple prompts
asking if they wanted to kill a modified buffer. Then when quitting
Emacs, the user would receive prompts asking if they wanted to save
some of the temporary test files.
* testing/org-test.el (org-test-kill-buffer): New function.
(org-test-at-id, org-test-in-example-file,
org-test-with-temp-text-in-file, org-test-kill-all-examples): Use new
function to kill buffers.
* testing/lisp/test-ob-tangle.el (ob-tangle/tangle-to-self,
ob-tangle/bibtex): Use
`org-test-with-temp-text-in-file' to ensure buffers are killed.
* testing/lisp/test-org-agenda.el (test-org-agenda/set-priority): Use
`unwind-protect' for test cleanup and kill a buffer to "agenda-file.org".
* testing/lisp/test-org-capture.el
(test-org-capture/org-capture-expand-olp): Use
`org-test-with-temp-text-in-file' to ensure buffers are killed.
* testing/lisp/test-org-protocol.el
(test-org-protocol/org-protocol-capture-file): Add cleanup for buffers
and files.
* testing/lisp/test-ox.el (test-org-export/org-export-copy-buffer):
Kill buffer.
---
testing/lisp/test-ob-tangle.el | 45 +++++++++++++++++----------------------
testing/lisp/test-org-agenda.el | 12 ++++++-----
testing/lisp/test-org-capture.el | 20 ++++++-----------
testing/lisp/test-org-protocol.el | 16 ++++++++------
testing/lisp/test-ox.el | 3 ++-
testing/org-test.el | 22 +++++++++++--------
6 files changed, 58 insertions(+), 60 deletions(-)
diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el
index 83dddb1162..2ab3950eb5 100644
--- a/testing/lisp/test-ob-tangle.el
+++ b/testing/lisp/test-ob-tangle.el
@@ -559,17 +559,14 @@ another block
(ert-deftest ob-tangle/tangle-to-self ()
"Do not allow tangling into self."
- (let ((file (make-temp-file "org-tangle-" nil ".org")))
- (unwind-protect
- (with-current-buffer (find-file-noselect file)
- (insert
- (format "
-#+begin_src elisp :tangle %s
+ (org-test-with-temp-text-in-file
+ "
+#+begin_src elisp :tangle <point>
2
#+end_src
-" file))
- (should-error (org-babel-tangle)))
- (delete-file file))))
+"
+ (insert buffer-file-name)
+ (should-error (org-babel-tangle))))
(ert-deftest ob-tangle/detangle-false-positive ()
"Test handling of false positive link during detangle."
@@ -721,29 +718,25 @@ another block
(ert-deftest ob-tangle/bibtex ()
"Tangle BibTeX into a `.bib' file."
- (let ((file (make-temp-file "org-tangle-" nil ".org"))
- (bib "@Misc{example,
+ (let ((bib "@Misc{example,
author = {Richard Stallman and {contributors}},
title = {{GNU} {Emacs}},
publisher = {Free Software Foundation},
url = {https://www.emacs.org/},
}"))
- (unwind-protect
- (with-current-buffer (find-file-noselect file)
- (insert (format "#+begin_src bibtex :tangle yes
+ (org-test-with-temp-text-in-file
+ (format "#+begin_src bibtex :tangle yes
%s
-#+end_src"
- bib))
- (org-babel-tangle)
- (let ((bib-file
- (if (fboundp 'file-name-with-extension)
- (file-name-with-extension file "bib")
- ;; Emacs <28
- (concat (file-name-sans-extension file) "." "bib"))))
- (should (file-exists-p bib-file))
- (should (string= (string-trim (org-file-contents bib-file))
- bib))))
- (delete-file file))))
+#+end_src" bib)
+ (org-babel-tangle)
+ (let ((bib-file
+ (if (fboundp 'file-name-with-extension)
+ (file-name-with-extension buffer-file-name "bib")
+ ;; Emacs <28
+ (concat (file-name-sans-extension buffer-file-name) "."
"bib"))))
+ (should (file-exists-p bib-file))
+ (should (string= (string-trim (org-file-contents bib-file))
+ bib))))))
;; See https://list.orgmode.org/87msfxd81c.fsf@localhost/T/#t
(ert-deftest ob-tangle/tangle-from-capture-buffer ()
diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el
index 36da85fc01..46ae942295 100644
--- a/testing/lisp/test-org-agenda.el
+++ b/testing/lisp/test-org-agenda.el
@@ -385,11 +385,13 @@ See
https://list.orgmode.org/[email protected]"
;; `org-today' or not.
(org-agenda-list nil "<2017-07-19 Wed>")
(set-buffer org-agenda-buffer-name)
- (should
- (progn (goto-line 3)
- (org-agenda-priority ?B)
- (looking-at-p " *agenda-file:Scheduled: *\\[#B\\] test agenda"))))
- (org-test-agenda--kill-all-agendas))
+ (unwind-protect
+ (should
+ (progn (goto-line 3)
+ (org-agenda-priority ?B)
+ (looking-at-p " *agenda-file:Scheduled: *\\[#B\\] test
agenda")))
+ (org-test-agenda--kill-all-agendas)
+ (org-test-kill-buffer "agenda-file.org"))))
(ert-deftest test-org-agenda/sticky-agenda-name ()
"Agenda buffer name after having created one sticky agenda buffer."
diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el
index 494fee4cf5..6b49a2df74 100644
--- a/testing/lisp/test-org-capture.el
+++ b/testing/lisp/test-org-capture.el
@@ -1089,28 +1089,22 @@ before\nglobal-before\nafter\nglobal-after"
(should
(equal
'("A" "B" "C")
- (let ((file (make-temp-file "org-test")))
- (unwind-protect
- (org-capture-expand-olp file "A" "B" "C")
- (delete-file file)))))
+ (org-test-with-temp-text-in-file ""
+ (org-capture-expand-olp buffer-file-name "A" "B" "C"))))
;; The current buffer during the funcall of the lambda is the temporary
;; test file.
(should
- (let ((file (make-temp-file "org-test")))
+ (org-test-with-temp-text-in-file ""
(equal
- file
- (unwind-protect
- (org-capture-expand-olp file (lambda () (buffer-file-name)))
- (delete-file file)))))
+ buffer-file-name
+ (org-capture-expand-olp buffer-file-name (lambda ()
(buffer-file-name))))))
;; `org-capture-expand-olp' rejects outline path that is not
;; inlined.
(should-error
(equal
'("A" "B" "C")
- (let ((file (make-temp-file "org-test")))
- (unwind-protect
- (org-capture-expand-olp file '("A" "B" "C"))
- (delete-file file))))))
+ (org-test-with-temp-text-in-file ""
+ (org-capture-expand-olp buffer-file-name '("A" "B" "C"))))))
(provide 'test-org-capture)
;;; test-org-capture.el ends here
diff --git a/testing/lisp/test-org-protocol.el
b/testing/lisp/test-org-protocol.el
index 6429432a38..d31940d3e1 100644
--- a/testing/lisp/test-org-protocol.el
+++ b/testing/lisp/test-org-protocol.el
@@ -164,12 +164,16 @@
(temp-file-name (make-temp-file "org-protocol-test"))
(org-capture-templates
`(("t" "Test" plain (file ,temp-file-name) "%a\n%i\n" :kill-buffer
t))))
- (let ((uri
"/org-protocol:/capture:/t/file%3A%2F%2F%2Fetc%2Fmailcap/Triple%20Slash/Body"))
- (should (null (org-protocol-check-filename-for-protocol uri (list uri)
nil)))
- (should (string= (buffer-string) "[[file:///etc/mailcap][Triple
Slash]]\nBody")))
- (let ((uri
"/org-protocol:/capture?template=t&url=file%3A%2F%2F%2Fetc%2Fmailcap&title=Triple%20Slash&body=Body"))
- (should (null (org-protocol-check-filename-for-protocol uri (list uri)
nil)))
- (should (string= (buffer-string) "[[file:///etc/mailcap][Triple
Slash]]\nBody")))))
+ (unwind-protect
+ (progn
+ (let ((uri
"/org-protocol:/capture:/t/file%3A%2F%2F%2Fetc%2Fmailcap/Triple%20Slash/Body"))
+ (should (null (org-protocol-check-filename-for-protocol uri (list
uri) nil)))
+ (should (string= (buffer-string) "[[file:///etc/mailcap][Triple
Slash]]\nBody")))
+ (let ((uri
"/org-protocol:/capture?template=t&url=file%3A%2F%2F%2Fetc%2Fmailcap&title=Triple%20Slash&body=Body"))
+ (should (null (org-protocol-check-filename-for-protocol uri (list
uri) nil)))
+ (should (string= (buffer-string) "[[file:///etc/mailcap][Triple
Slash]]\nBody"))))
+ (org-test-kill-buffer (get-file-buffer temp-file-name))
+ (delete-file temp-file-name))))
(ert-deftest test-org-protocol/org-protocol-open-source ()
"Test org-protocol://open-source links."
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 279642d94b..ddf37a5f6f 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -75,7 +75,8 @@ variable, and communication channel under `info'."
"* Heading"
(with-temp-buffer
(insert-file-contents file)
- (buffer-string)))))))
+ (buffer-string))))
+ (org-test-kill-buffer (current-buffer)))))
;; The copy must not show when re-opening the original file.
(org-test-with-temp-text-in-file
"* Heading"
diff --git a/testing/org-test.el b/testing/org-test.el
index bc63b62b57..28e095440b 100644
--- a/testing/org-test.el
+++ b/testing/org-test.el
@@ -116,6 +116,15 @@ If file is non-nil insert its contents in there.")
If file is not given, search for a file named after the test
currently executed.")
+(defun org-test-kill-buffer (buffer)
+ "Kill BUFFER like `kill-buffer' but without user interaction."
+ (setq buffer (get-buffer buffer))
+ (when (and buffer (buffer-live-p buffer))
+ (with-current-buffer buffer
+ ;; Prevent "Buffer *temp* modified; kill anyway?".
+ (set-buffer-modified-p nil)
+ (kill-buffer))))
+
(defmacro org-test-at-id (id &rest body)
"Run body after placing the point in the headline identified by ID."
(declare (indent 1) (debug t))
@@ -136,7 +145,7 @@ currently executed.")
(error nil))
(save-restriction ,@body)))
(unless (or ,visited-p (not ,to-be-removed))
- (kill-buffer ,to-be-removed))))))
+ (org-test-kill-buffer ,to-be-removed))))))
(defmacro org-test-in-example-file (file &rest body)
"Execute body in the Org example file."
@@ -161,7 +170,7 @@ currently executed.")
(error nil))
(setq ,results (save-restriction ,@body))))
(unless ,visited-p
- (kill-buffer ,to-be-removed))
+ (org-test-kill-buffer ,to-be-removed))
,results)))
(defmacro org-test-at-marker (file marker &rest body)
@@ -217,12 +226,7 @@ point at the beginning of the buffer."
(org-mode)
(progn ,@body))
(let ((kill-buffer-query-functions nil))
- (when ,buffer
- (set-buffer ,buffer)
- ;; Ignore changes, we're deleting the file in the next step
- ;; anyways.
- (set-buffer-modified-p nil)
- (kill-buffer))
+ (org-test-kill-buffer ,buffer)
(delete-file ,file))))))
(defun org-test-table-target-expect (target &optional expect laps &rest tblfm)
@@ -455,7 +459,7 @@ https://list.orgmode.org/orgmode/[email protected]"
(defun org-test-kill-all-examples ()
(while org-test-buffers
(let ((b (pop org-test-buffers)))
- (when (buffer-live-p b) (kill-buffer b)))))
+ (org-test-kill-buffer b))))
(defun org-test-update-id-locations ()
(setq org-id-locations-file