diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-11 07:32:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-11 07:32:34 -0500 |
| commit | 1a53381a176e99f5c7f9bed1589dbaf689f38390 (patch) | |
| tree | 8bf917604b30907a4a5ed5a66feb37d68c8e12d5 | |
| parent | 1702bf7e2bd50e0be63642fddbd48c66e7b7ee77 (diff) | |
| download | org-drill-1a53381a176e99f5c7f9bed1589dbaf689f38390.tar.gz org-drill-1a53381a176e99f5c7f9bed1589dbaf689f38390.zip | |
test: fix date-sensitive days-since-creation assertion
test-org-drill-entry-days-since-creation-with-date-added pinned DATE_ADDED to a hardcoded 2026-04-01 and asserted 33-35 days, which only holds when the wall clock is near 2026-05-05. The with-fixed-now mock that was supposed to make it deterministic rebinds `current-time`. But the DATE_ADDED branch of org-drill-entry-days-since-creation goes through `org-time-stamp-to-now`, which reads the real clock. The rebind never reaches it. CI went red once the calendar moved past the +35-day window.
I rewrote the test to derive DATE_ADDED 34 calendar days before today (via decode-time / encode-time, so month rollover and DST are handled) and assert the function returns exactly 34. No mock needed. Both sides read the same real clock.
| -rw-r--r-- | tests/test-org-drill-entry-status.el | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/tests/test-org-drill-entry-status.el b/tests/test-org-drill-entry-status.el index 239bcac..60ea21a 100644 --- a/tests/test-org-drill-entry-status.el +++ b/tests/test-org-drill-entry-status.el @@ -133,14 +133,20 @@ because its days-overdue computes nil." ;;;; org-drill-entry-days-since-creation (ert-deftest test-org-drill-entry-days-since-creation-with-date-added () - "DATE_ADDED set → returns days since that date." + "DATE_ADDED set → returns days since that date. +Fixture date is relative to today so the assertion stays exact whenever +the test runs; the timestamp branch reads the real clock via +`org-time-stamp-to-now' and a `current-time' rebind wouldn't reach it." (with-org-buffer "* Question :drill:\n" - (org-set-property "DATE_ADDED" "<2026-04-01 Wed>") - (with-fixed-now - (let ((days (org-drill-entry-days-since-creation (org-drill-session)))) - (should (numberp days)) - (should (>= days 33)) ; ~34 days from 4-01 to 5-05 - (should (<= days 35)))))) + (let* ((days-ago 34) + (now (decode-time)) + (added (encode-time 0 0 12 + (- (nth 3 now) days-ago) + (nth 4 now) + (nth 5 now)))) + (org-set-property "DATE_ADDED" (format-time-string "<%Y-%m-%d %a>" added)) + (should (= days-ago + (org-drill-entry-days-since-creation (org-drill-session))))))) (ert-deftest test-org-drill-entry-days-since-creation-no-date-no-flag-returns-nil () "DATE_ADDED missing, USE-LAST-INTERVAL-P nil → returns nil." |
