branch: master commit 1b05e1e2b6b5c66b4fad338dc94ddc6605cde5b9 Author: Ian Dunn <du...@gnu.org> Commit: Ian Dunn <du...@gnu.org>
Fixed failing tests * org-edna-tests.el (org-test-at-time): Added to keep up with org mode changes. (org-edna-test-setup): Use it. --- org-edna-tests.el | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- org-edna.el | 4 ++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/org-edna-tests.el b/org-edna-tests.el index c877321..d044e3d 100644 --- a/org-edna-tests.el +++ b/org-edna-tests.el @@ -76,12 +76,65 @@ ;; Change the test file back to its original state. (org-edna-test-restore-test-file))) +;; Copied from org-test.el in `org-mode' source code. +(defmacro org-test-at-time (time &rest body) + "Run body while pretending that the current time is TIME. +TIME can be a non-nil Lisp time value, or a string specifying a date and time." + (declare (indent 1)) + (let ((tm (cl-gensym)) + (at (cl-gensym))) + `(let* ((,tm ,time) + (,at (if (stringp ,tm) + (apply #'encode-time (org-parse-time-string ,tm)) + ,tm))) + (cl-letf + ;; Wrap builtins whose behavior can depend on the current time. + (((symbol-function 'current-time) + (lambda () ,at)) + ((symbol-function 'current-time-string) + (lambda (&optional time &rest args) + (apply ,(symbol-function 'current-time-string) + (or time ,at) args))) + ((symbol-function 'current-time-zone) + (lambda (&optional time &rest args) + (apply ,(symbol-function 'current-time-zone) + (or time ,at) args))) + ((symbol-function 'decode-time) + (lambda (&optional time) (funcall ,(symbol-function 'decode-time) + (or time ,at)))) + ((symbol-function 'encode-time) + (lambda (time &rest args) + (apply ,(symbol-function 'encode-time) (or time ,at) args))) + ((symbol-function 'float-time) + (lambda (&optional time) + (funcall ,(symbol-function 'float-time) (or time ,at)))) + ((symbol-function 'format-time-string) + (lambda (format &optional time &rest args) + (apply ,(symbol-function 'format-time-string) + format (or time ,at) args))) + ((symbol-function 'set-file-times) + (lambda (file &optional time) + (funcall ,(symbol-function 'set-file-times) file (or time ,at)))) + ((symbol-function 'time-add) + (lambda (a b) (funcall ,(symbol-function 'time-add) + (or a ,at) (or b ,at)))) + ((symbol-function 'time-equal-p) + (lambda (a b) (funcall ,(symbol-function 'time-equal-p) + (or a ,at) (or b ,at)))) + ((symbol-function 'time-less-p) + (lambda (a b) (funcall ,(symbol-function 'time-less-p) + (or a ,at) (or b ,at)))) + ((symbol-function 'time-subtract) + (lambda (a b) (funcall ,(symbol-function 'time-subtract) + (or a ,at) (or b ,at))))) + ,@body)))) + (defmacro org-edna-test-setup (&rest body) "Common settings for tests." (declare (indent 0)) ;; Override `current-time' so we can get a deterministic value - `(cl-letf* (((symbol-function 'current-time) (lambda () org-edna-test-time)) - ;; Only use the test file in the agenda + `(org-test-at-time org-edna-test-time + (let* (;; Only use the test file in the agenda (org-agenda-files `(,org-edna-test-file)) ;; Ensure interactive modification of TODO states works. (org-todo-keywords '((sequence "TODO" "|" "DONE"))) @@ -91,7 +144,7 @@ (org-trigger-hook 'org-edna-trigger-function) ;; Inhibit messages if indicated (inhibit-message org-edna-test-inhibit-messages)) - ,@body)) + ,@body))) (defmacro org-edna-with-point-at-test-heading (heading-id &rest body) (declare (indent 1)) diff --git a/org-edna.el b/org-edna.el index 1cdc52b..38aff93 100644 --- a/org-edna.el +++ b/org-edna.el @@ -971,8 +971,8 @@ All arguments are symbols, unless noted otherwise. ('step-down (setq targets (org-with-wide-buffer - (org-goto-first-child) - (org-edna-collect-current-level (org-edna-self-marker) nil nil t)))) + (when (org-goto-first-child) + (org-edna-collect-current-level (org-edna-self-marker) nil nil t))))) ('todo-only ;; Remove any entry without a TODO keyword, or with a DONE keyword (cl-pushnew