emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Testing: Add tests for 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item'
@ 2023-07-17 15:37 Morgan Smith
  2023-07-18  9:31 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Morgan Smith @ 2023-07-17 15:37 UTC (permalink / raw)
  To: emacs-orgmode

* testing/lisp/test-org-agenda.el
(test-org-agenda/check-for-timestamp-as-reason-to-ignore-todo-item):
New test.
---
 testing/lisp/test-org-agenda.el | 56 +++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el
index c4bd4f0a7..66f2f5bce 100644
--- a/testing/lisp/test-org-agenda.el
+++ b/testing/lisp/test-org-agenda.el
@@ -329,6 +329,62 @@ DEADLINE: <2023-07-15 Sat>"
           "* TODO write better tests"
         (org-agenda-skip-if nil options))))))
 
+(ert-deftest test-org-agenda/check-for-timestamp-as-reason-to-ignore-todo-item ()
+  "Test `org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item'."
+  (let ((org-deadline-warning-days 1)
+        (expected-return
+         (lambda (timestamp value)
+           (cl-case timestamp
+             (past (not (not (memq value '(past all -1 -2 near)))))
+             (yesteryesterday (not (not (memq value '(past all -1 -2 near)))))
+             (yesterday (not (not (memq value '(past all -1 near)))))
+             (today (not (not (memq value '(all past 0 near)))))
+             (tomorrow (not (not (memq value '(future all 1 0 near)))))
+             (tomorroworrow (not (not (memq value '(future all 2 1 0 far)))))
+             (future (not (not (memq value '(future all 2 1 0 far))))))))
+        ;; Lexically bind the variables we're changing
+        org-agenda-todo-ignore-deadlines
+        org-agenda-todo-ignore-scheduled
+        org-agenda-todo-ignore-timestamp)
+      (org-test-at-time "2023-01-15"
+        (dolist (variable '(org-agenda-todo-ignore-deadlines
+                            org-agenda-todo-ignore-scheduled
+                            org-agenda-todo-ignore-timestamp))
+          (dolist (type '(timestamp scheduled deadline))
+            ;; nil is last so it resets the variable for the next one
+            (dolist (value `(past future all 2 1 0 -1 -2
+                                  ,@(when (eq type 'deadline) '(near far nil))))
+              (dolist (timestamp '((past . "<2022-01-15>")
+                                   (yesteryesterday . "<2023-01-13>")
+                                   (yesterday . "<2023-01-14>")
+                                   (today . "<2023-01-15>")
+                                   (tomorrow . "<2023-01-16>")
+                                   (tomorroworrow . "<2023-01-17>")
+                                   (future . "<2024-01-15>")))
+                ;; Uncomment to debug failure
+                ;; (message "Type: %S, Variable: %S, Value: %S, Time: %S" type variable value (car timestamp))
+                (set variable value)
+                (should
+                 (equal
+                  (cl-case variable
+                    (org-agenda-todo-ignore-deadlines
+                     (when (eq type 'deadline)
+                       (funcall expected-return (car timestamp) value)))
+                    (org-agenda-todo-ignore-scheduled
+                     (when (eq type 'scheduled)
+                       (funcall expected-return (car timestamp) value)))
+                    (org-agenda-todo-ignore-timestamp
+                     (when (eq type 'timestamp)
+                       (funcall expected-return (car timestamp) value))))
+                  (org-test-with-temp-text
+                      (cl-case type
+                        (timestamp (concat "* hello " (cdr timestamp)))
+                        (scheduled (concat "* hello
+SCHEDULED: " (cdr timestamp)))
+                        (deadline (concat "* hello
+DEADLINE: " (cdr timestamp))))
+                    (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))))))))
+
 (ert-deftest test-org-agenda/goto-date ()
   "Test `org-agenda-goto-date'."
   (unwind-protect
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Testing: Add tests for 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item'
  2023-07-17 15:37 [PATCH] Testing: Add tests for 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item' Morgan Smith
@ 2023-07-18  9:31 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2023-07-18  9:31 UTC (permalink / raw)
  To: Morgan Smith; +Cc: emacs-orgmode

Morgan Smith <Morgan.J.Smith@outlook.com> writes:

> * testing/lisp/test-org-agenda.el
> (test-org-agenda/check-for-timestamp-as-reason-to-ignore-todo-item):
> New test.

Thanks for the patch, but I am not sure if what we want to test is this
function.

`org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item' is
semi-internal function, which is simply serving to group some common
skip tests together.

It will be more reliable to test the final agenda behaviour - what is
display in the actual agenda view and what not.
Basically, instead of testing the return value of
`org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item', test
using `org-test-agenda-with-agenda' and check the agenda buffer
contents.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-18  9:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-17 15:37 [PATCH] Testing: Add tests for 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item' Morgan Smith
2023-07-18  9:31 ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).