Skip to content

Commit

Permalink
WIP: do not merge: tests for relative dates
Browse files Browse the repository at this point in the history
Hello,

unfortunately with my limited elisp knowledge, I am unable to write
succesful tests.

Maybe is possible to fake the current time for the current test. Faking
org-today is not enough?

My idea is that org-read-date return the date relative to the date of
the test instead of the day of the agenda that we want to test.

I think some steps are wrong/missing/incomplete:

- [ ] why ad-set-argument fails?
- [ ] use cl-letf with/instead of advice
- [ ] calculate the constant org-super-agenda-test-date-internal at runtime
- [ ] remove verbose message code
- [ ] save the correct test results
  • Loading branch information
Daniele Pizzolli committed Oct 8, 2021
1 parent f3d3b63 commit 369a4cd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/test.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
;;;; Variables

(defconst org-super-agenda-test-date "2017-07-05 12:00")
;; (org-read-date t t org-super-agenda-test-date))
(defconst org-super-agenda-test-date-internal '(22876 47264))
(defvar org-super-agenda-test-results (ht-create))
(defvar org-super-agenda-test-save-results nil)
(defvar org-super-agenda-test-show-results nil)
Expand Down Expand Up @@ -58,6 +60,19 @@
(defun org-super-agenda-test--diary-sunset ()
(cl-second (org-super-agenda-test--diary-sunrise-sunset-split)))


;;;; Relative dates

(defun org-read-date-get-relative-hack (orig-fun &rest args)
;; (defun org-read-date-get-relative (s today default)
(message "first called with args %s" args)
(ad-set-argument 'args 1 org-super-agenda-test-date-internal)
(ad-set-argument 'args 2 org-super-agenda-test-date-internal)
(message "then calling with args %s" args)
(let ((res (apply orig-fun args)))
(message "returned %s" res)
res))

;;;; Commands

(cl-defun org-super-agenda-test--update-all ()
Expand Down Expand Up @@ -530,10 +545,25 @@ already loaded."
(should (org-super-agenda-test--run
:groups '((:deadline (after "2017-07-10"))))))

(ert-deftest org-super-agenda-test--:deadline-after-relative ()
;; NOTE: is safe for parallel testing?
(advice-add 'org-read-date-get-relative :around #'org-read-date-get-relative-hack)
(should (org-super-agenda-test--run
:groups '((:deadline (after "+5d")))))
(advice-remove 'org-read-date-get-relative #'org-read-date-get-relative-hack))

(ert-deftest org-super-agenda-test--:deadline-before-relative ()
;; NOTE: is safe for parallel testing?
(advice-add 'org-read-date-get-relative :around #'org-read-date-get-relative-hack)
(should (org-super-agenda-test--run
:groups '((:deadline (before "+5d")))))
(advice-remove 'org-read-date-get-relative #'org-read-date-get-relative-hack))

(ert-deftest org-super-agenda-test--:effort< ()
;; DONE: Works.
(should (org-super-agenda-test--run
:groups '((:effort< "5")))))

(ert-deftest org-super-agenda-test--:effort> ()
;; DONE: Works.
(should (org-super-agenda-test--run
Expand Down

0 comments on commit 369a4cd

Please sign in to comment.