diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-24 16:18:27 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-24 16:18:27 -0400 |
| commit | d47f4f90bb1c69697a855a662bb07be1e0ccdc33 (patch) | |
| tree | 777d0b786a530cb4190f8e062e0afda2506308d4 /tests/test-chime-extract-time.el | |
| parent | ab8cc4da57fce5d0a59f4db34fb550919a06ea79 (diff) | |
| download | chime-d47f4f90bb1c69697a855a662bb07be1e0ccdc33.tar.gz chime-d47f4f90bb1c69697a855a662bb07be1e0ccdc33.zip | |
Every test hand-wrote the same scaffolding: call a per-file setup, wrap the body in unwind-protect, call a per-file teardown. That's 419 unwind-protect blocks and 68 near-identical setup/teardown defuns, with no shared fixture because ERT has no native per-test setup.
I added a chime-deftest macro in test-bootstrap that creates the test base directory before the body and deletes it afterward, even on failure. I converted the 10 files whose fixture was exactly that base-dir create/delete and whose every test followed the standard shape, dropping their setup/teardown defuns. Files with custom fixtures (modeline state restore, validation reset) keep explicit setup/teardown, since the macro would silently drop their extra logic. I left the 4 tag-bearing integration files alone.
I also moved the near-universal testutil-general and testutil-time requires into test-bootstrap, so individual files no longer repeat them.
Behavior is unchanged: still 800 tests, full suite green. Converted bodies are copied verbatim, so the change only removes scaffolding, never an assertion.
Diffstat (limited to 'tests/test-chime-extract-time.el')
| -rw-r--r-- | tests/test-chime-extract-time.el | 361 |
1 files changed, 160 insertions, 201 deletions
diff --git a/tests/test-chime-extract-time.el b/tests/test-chime-extract-time.el index 120c45b..d2be145 100644 --- a/tests/test-chime-extract-time.el +++ b/tests/test-chime-extract-time.el @@ -28,31 +28,15 @@ (require 'test-bootstrap (expand-file-name "test-bootstrap.el")) -;; Load test utilities -(require 'testutil-general (expand-file-name "testutil-general.el")) -(require 'testutil-time (expand-file-name "testutil-time.el")) - -;;; Setup and Teardown - -(defun test-chime-extract-time-setup () - "Setup function run before each test." - (chime-create-test-base-dir)) - -(defun test-chime-extract-time-teardown () - "Teardown function run after each test." - (chime-delete-test-base-dir)) - ;;; Tests for org-gcal events -(ert-deftest test-chime-extract-time-gcal-event-from-drawer () +(chime-deftest test-chime-extract-time-gcal-event-from-drawer () "Test that org-gcal events extract timestamps ONLY from :org-gcal: drawer. REFACTORED: Uses dynamic timestamps" - (test-chime-extract-time-setup) - (unwind-protect - (let* ((time (test-time-tomorrow-at 14 0)) - (timestamp-str (format-time-string "<%Y-%m-%d %a %H:%M-15:00>" time)) - (test-content (format "* Meeting + (let* ((time (test-time-tomorrow-at 14 0)) + (timestamp-str (format-time-string "<%Y-%m-%d %a %H:%M-15:00>" time)) + (test-content (format "* Meeting :PROPERTIES: :entry-id: abc123@google.com :END: @@ -60,33 +44,30 @@ REFACTORED: Uses dynamic timestamps" %s :END: " timestamp-str)) - (test-file (chime-create-temp-test-file-with-content test-content)) - (test-buffer (find-file-noselect test-file))) - (with-current-buffer test-buffer - (org-mode) - (goto-char (point-min)) - (let* ((marker (point-marker)) - (times (chime--extract-time marker))) - ;; Should extract the timestamp from :org-gcal: drawer - (should (= 1 (length times))) - (should (string-match-p "14:00" (car (car times)))))) - (kill-buffer test-buffer)) - (test-chime-extract-time-teardown))) - -(ert-deftest test-chime-extract-time-gcal-event-ignores-body-timestamps () + (test-file (chime-create-temp-test-file-with-content test-content)) + (test-buffer (find-file-noselect test-file))) + (with-current-buffer test-buffer + (org-mode) + (goto-char (point-min)) + (let* ((marker (point-marker)) + (times (chime--extract-time marker))) + ;; Should extract the timestamp from :org-gcal: drawer + (should (= 1 (length times))) + (should (string-match-p "14:00" (car (car times)))))) + (kill-buffer test-buffer))) + +(chime-deftest test-chime-extract-time-gcal-event-ignores-body-timestamps () "Test that org-gcal events ignore plain timestamps in body text. When an event is rescheduled, old timestamps might remain in the body. The :org-gcal: drawer has the correct time, so we should ignore body text. REFACTORED: Uses dynamic timestamps" - (test-chime-extract-time-setup) - (unwind-protect - (let* ((new-time (test-time-tomorrow-at 14 0)) - (old-time (test-time-today-at 14 0)) - (new-timestamp (test-timestamp-string new-time)) - (old-timestamp (test-timestamp-string old-time)) - (test-content (format "* Meeting + (let* ((new-time (test-time-tomorrow-at 14 0)) + (old-time (test-time-today-at 14 0)) + (new-timestamp (test-timestamp-string new-time)) + (old-timestamp (test-timestamp-string old-time)) + (test-content (format "* Meeting :PROPERTIES: :entry-id: abc123@google.com :END: @@ -95,34 +76,31 @@ REFACTORED: Uses dynamic timestamps" :END: Old time was %s " new-timestamp old-timestamp)) - (test-file (chime-create-temp-test-file-with-content test-content)) - (test-buffer (find-file-noselect test-file))) - (with-current-buffer test-buffer - (org-mode) - (goto-char (point-min)) - (let* ((marker (point-marker)) - (times (chime--extract-time marker))) - ;; Should extract ONLY from drawer (tomorrow), ignore body (today) - (should (= 1 (length times))) - (should (string-match-p "14:00" (car (car times)))) - ;; Verify it's the new timestamp, not the old one - (should (string-match-p (format-time-string "%Y-%m-%d" new-time) (car (car times)))))) - (kill-buffer test-buffer)) - (test-chime-extract-time-teardown))) - -(ert-deftest test-chime-extract-time-gcal-event-ignores-scheduled () + (test-file (chime-create-temp-test-file-with-content test-content)) + (test-buffer (find-file-noselect test-file))) + (with-current-buffer test-buffer + (org-mode) + (goto-char (point-min)) + (let* ((marker (point-marker)) + (times (chime--extract-time marker))) + ;; Should extract ONLY from drawer (tomorrow), ignore body (today) + (should (= 1 (length times))) + (should (string-match-p "14:00" (car (car times)))) + ;; Verify it's the new timestamp, not the old one + (should (string-match-p (format-time-string "%Y-%m-%d" new-time) (car (car times)))))) + (kill-buffer test-buffer))) + +(chime-deftest test-chime-extract-time-gcal-event-ignores-scheduled () "Test that org-gcal events ignore SCHEDULED/DEADLINE properties. For org-gcal events, the :org-gcal: drawer is the source of truth. REFACTORED: Uses dynamic timestamps" - (test-chime-extract-time-setup) - (unwind-protect - (let* ((drawer-time (test-time-tomorrow-at 14 0)) - (scheduled-time (test-time-days-from-now 2)) - (drawer-timestamp (test-timestamp-string drawer-time)) - (scheduled-timestamp (test-timestamp-string scheduled-time)) - (test-content (format "* Meeting + (let* ((drawer-time (test-time-tomorrow-at 14 0)) + (scheduled-time (test-time-days-from-now 2)) + (drawer-timestamp (test-timestamp-string drawer-time)) + (scheduled-timestamp (test-timestamp-string scheduled-time)) + (test-content (format "* Meeting SCHEDULED: %s :PROPERTIES: :entry-id: abc123@google.com @@ -131,33 +109,30 @@ SCHEDULED: %s %s :END: " scheduled-timestamp drawer-timestamp)) - (test-file (chime-create-temp-test-file-with-content test-content)) - (test-buffer (find-file-noselect test-file))) - (with-current-buffer test-buffer - (org-mode) - (goto-char (point-min)) - (let* ((marker (point-marker)) - (times (chime--extract-time marker))) - ;; Should extract ONLY from drawer (tomorrow), ignore SCHEDULED (day after) - (should (= 1 (length times))) - (should (string-match-p "14:00" (car (car times)))) - (should (string-match-p (format-time-string "%Y-%m-%d" drawer-time) (car (car times)))))) - (kill-buffer test-buffer)) - (test-chime-extract-time-teardown))) - -(ert-deftest test-chime-extract-time-gcal-event-multiple-in-drawer () + (test-file (chime-create-temp-test-file-with-content test-content)) + (test-buffer (find-file-noselect test-file))) + (with-current-buffer test-buffer + (org-mode) + (goto-char (point-min)) + (let* ((marker (point-marker)) + (times (chime--extract-time marker))) + ;; Should extract ONLY from drawer (tomorrow), ignore SCHEDULED (day after) + (should (= 1 (length times))) + (should (string-match-p "14:00" (car (car times)))) + (should (string-match-p (format-time-string "%Y-%m-%d" drawer-time) (car (car times)))))) + (kill-buffer test-buffer))) + +(chime-deftest test-chime-extract-time-gcal-event-multiple-in-drawer () "Test that org-gcal events extract all timestamps from :org-gcal: drawer. Some recurring events might have multiple timestamps in the drawer. REFACTORED: Uses dynamic timestamps" - (test-chime-extract-time-setup) - (unwind-protect - (let* ((time1 (test-time-tomorrow-at 14 0)) - (time2 (test-time-days-from-now 2 14 0)) - (timestamp1 (test-timestamp-string time1)) - (timestamp2 (test-timestamp-string time2)) - (test-content (format "* Meeting + (let* ((time1 (test-time-tomorrow-at 14 0)) + (time2 (test-time-days-from-now 2 14 0)) + (timestamp1 (test-timestamp-string time1)) + (timestamp2 (test-timestamp-string time2)) + (test-content (format "* Meeting :PROPERTIES: :entry-id: abc123@google.com :END: @@ -166,153 +141,137 @@ REFACTORED: Uses dynamic timestamps" %s :END: " timestamp1 timestamp2)) - (test-file (chime-create-temp-test-file-with-content test-content)) - (test-buffer (find-file-noselect test-file))) - (with-current-buffer test-buffer - (org-mode) - (goto-char (point-min)) - (let* ((marker (point-marker)) - (times (chime--extract-time marker))) - ;; Should extract both timestamps from drawer - (should (= 2 (length times))) - (should (string-match-p "14:00" (car (car times)))) - (should (string-match-p "14:00" (car (cadr times)))))) - (kill-buffer test-buffer)) - (test-chime-extract-time-teardown))) + (test-file (chime-create-temp-test-file-with-content test-content)) + (test-buffer (find-file-noselect test-file))) + (with-current-buffer test-buffer + (org-mode) + (goto-char (point-min)) + (let* ((marker (point-marker)) + (times (chime--extract-time marker))) + ;; Should extract both timestamps from drawer + (should (= 2 (length times))) + (should (string-match-p "14:00" (car (car times)))) + (should (string-match-p "14:00" (car (cadr times)))))) + (kill-buffer test-buffer))) ;;; Tests for regular org events -(ert-deftest test-chime-extract-time-regular-event-scheduled () +(chime-deftest test-chime-extract-time-regular-event-scheduled () "Test that regular events extract SCHEDULED timestamp. REFACTORED: Uses dynamic timestamps" - (test-chime-extract-time-setup) - (unwind-protect - (let* ((time (test-time-tomorrow-at 14 0)) - (timestamp (test-timestamp-string time)) - (test-content (format "* Task + (let* ((time (test-time-tomorrow-at 14 0)) + (timestamp (test-timestamp-string time)) + (test-content (format "* Task SCHEDULED: %s " timestamp)) - (test-file (chime-create-temp-test-file-with-content test-content)) - (test-buffer (find-file-noselect test-file))) - (with-current-buffer test-buffer - (org-mode) - (goto-char (point-min)) - (let* ((marker (point-marker)) - (times (chime--extract-time marker))) - ;; Should extract SCHEDULED timestamp - (should (= 1 (length times))) - (should (string-match-p "14:00" (car (car times)))))) - (kill-buffer test-buffer)) - (test-chime-extract-time-teardown))) - -(ert-deftest test-chime-extract-time-regular-event-deadline () + (test-file (chime-create-temp-test-file-with-content test-content)) + (test-buffer (find-file-noselect test-file))) + (with-current-buffer test-buffer + (org-mode) + (goto-char (point-min)) + (let* ((marker (point-marker)) + (times (chime--extract-time marker))) + ;; Should extract SCHEDULED timestamp + (should (= 1 (length times))) + (should (string-match-p "14:00" (car (car times)))))) + (kill-buffer test-buffer))) + +(chime-deftest test-chime-extract-time-regular-event-deadline () "Test that regular events extract DEADLINE timestamp. REFACTORED: Uses dynamic timestamps" - (test-chime-extract-time-setup) - (unwind-protect - (let* ((time (test-time-tomorrow-at 17 0)) - (timestamp (test-timestamp-string time)) - (test-content (format "* Task + (let* ((time (test-time-tomorrow-at 17 0)) + (timestamp (test-timestamp-string time)) + (test-content (format "* Task DEADLINE: %s " timestamp)) - (test-file (chime-create-temp-test-file-with-content test-content)) - (test-buffer (find-file-noselect test-file))) - (with-current-buffer test-buffer - (org-mode) - (goto-char (point-min)) - (let* ((marker (point-marker)) - (times (chime--extract-time marker))) - ;; Should extract DEADLINE timestamp - (should (= 1 (length times))) - (should (string-match-p "17:00" (car (car times)))))) - (kill-buffer test-buffer)) - (test-chime-extract-time-teardown))) - -(ert-deftest test-chime-extract-time-regular-event-plain-timestamps () + (test-file (chime-create-temp-test-file-with-content test-content)) + (test-buffer (find-file-noselect test-file))) + (with-current-buffer test-buffer + (org-mode) + (goto-char (point-min)) + (let* ((marker (point-marker)) + (times (chime--extract-time marker))) + ;; Should extract DEADLINE timestamp + (should (= 1 (length times))) + (should (string-match-p "17:00" (car (car times)))))) + (kill-buffer test-buffer))) + +(chime-deftest test-chime-extract-time-regular-event-plain-timestamps () "Test that regular events extract plain timestamps when no SCHEDULED/DEADLINE. REFACTORED: Uses dynamic timestamps" - (test-chime-extract-time-setup) - (unwind-protect - (let* ((time (test-time-tomorrow-at 14 0)) - (timestamp (test-timestamp-string time)) - (test-content (format "* Meeting notes + (let* ((time (test-time-tomorrow-at 14 0)) + (timestamp (test-timestamp-string time)) + (test-content (format "* Meeting notes Discussed: %s " timestamp)) - (test-file (chime-create-temp-test-file-with-content test-content)) - (test-buffer (find-file-noselect test-file))) - (with-current-buffer test-buffer - (org-mode) - (goto-char (point-min)) - (let* ((marker (point-marker)) - (times (chime--extract-time marker))) - ;; Should extract plain timestamp - (should (= 1 (length times))) - (should (string-match-p "14:00" (car (car times)))))) - (kill-buffer test-buffer)) - (test-chime-extract-time-teardown))) - -(ert-deftest test-chime-extract-time-regular-event-scheduled-and-plain () + (test-file (chime-create-temp-test-file-with-content test-content)) + (test-buffer (find-file-noselect test-file))) + (with-current-buffer test-buffer + (org-mode) + (goto-char (point-min)) + (let* ((marker (point-marker)) + (times (chime--extract-time marker))) + ;; Should extract plain timestamp + (should (= 1 (length times))) + (should (string-match-p "14:00" (car (car times)))))) + (kill-buffer test-buffer))) + +(chime-deftest test-chime-extract-time-regular-event-scheduled-and-plain () "Test that regular events extract both SCHEDULED and plain timestamps. SCHEDULED/DEADLINE appear first, then plain timestamps. REFACTORED: Uses dynamic timestamps" - (test-chime-extract-time-setup) - (unwind-protect - (let* ((scheduled-time (test-time-tomorrow-at 14 0)) - (plain-time (test-time-days-from-now 2 15 0)) - (scheduled-timestamp (test-timestamp-string scheduled-time)) - (plain-timestamp (format-time-string "<%Y-%m-%d %a %H:%M>" plain-time)) - (test-content (format "* Task + (let* ((scheduled-time (test-time-tomorrow-at 14 0)) + (plain-time (test-time-days-from-now 2 15 0)) + (scheduled-timestamp (test-timestamp-string scheduled-time)) + (plain-timestamp (format-time-string "<%Y-%m-%d %a %H:%M>" plain-time)) + (test-content (format "* Task SCHEDULED: %s Note: also happens %s " scheduled-timestamp plain-timestamp)) - (test-file (chime-create-temp-test-file-with-content test-content)) - (test-buffer (find-file-noselect test-file))) - (with-current-buffer test-buffer - (org-mode) - (goto-char (point-min)) - (let* ((marker (point-marker)) - (times (chime--extract-time marker))) - ;; Should extract both: SCHEDULED first, then plain - (should (= 2 (length times))) - ;; First should be SCHEDULED - (should (string-match-p "14:00" (car (car times)))) - ;; Second should be plain at 15:00 - (should (string-match-p "15:00" (car (cadr times)))))) - (kill-buffer test-buffer)) - (test-chime-extract-time-teardown))) - -(ert-deftest test-chime-extract-time-regular-event-multiple-plain () + (test-file (chime-create-temp-test-file-with-content test-content)) + (test-buffer (find-file-noselect test-file))) + (with-current-buffer test-buffer + (org-mode) + (goto-char (point-min)) + (let* ((marker (point-marker)) + (times (chime--extract-time marker))) + ;; Should extract both: SCHEDULED first, then plain + (should (= 2 (length times))) + ;; First should be SCHEDULED + (should (string-match-p "14:00" (car (car times)))) + ;; Second should be plain at 15:00 + (should (string-match-p "15:00" (car (cadr times)))))) + (kill-buffer test-buffer))) + +(chime-deftest test-chime-extract-time-regular-event-multiple-plain () "Test that regular events extract all plain timestamps. REFACTORED: Uses dynamic timestamps" - (test-chime-extract-time-setup) - (unwind-protect - (let* ((time1 (test-time-tomorrow-at 14 0)) - (time2 (test-time-days-from-now 2 15 0)) - (timestamp1 (test-timestamp-string time1)) - (timestamp2 (test-timestamp-string time2)) - (test-content (format "* Meeting notes + (let* ((time1 (test-time-tomorrow-at 14 0)) + (time2 (test-time-days-from-now 2 15 0)) + (timestamp1 (test-timestamp-string time1)) + (timestamp2 (test-timestamp-string time2)) + (test-content (format "* Meeting notes First discussion: %s Second discussion: %s " timestamp1 timestamp2)) - (test-file (chime-create-temp-test-file-with-content test-content)) - (test-buffer (find-file-noselect test-file))) - (with-current-buffer test-buffer - (org-mode) - (goto-char (point-min)) - (let* ((marker (point-marker)) - (times (chime--extract-time marker))) - ;; Should extract both plain timestamps - (should (= 2 (length times))) - (should (string-match-p "14:00" (car (car times)))) - (should (string-match-p "15:00" (car (cadr times)))))) - (kill-buffer test-buffer)) - (test-chime-extract-time-teardown))) + (test-file (chime-create-temp-test-file-with-content test-content)) + (test-buffer (find-file-noselect test-file))) + (with-current-buffer test-buffer + (org-mode) + (goto-char (point-min)) + (let* ((marker (point-marker)) + (times (chime--extract-time marker))) + ;; Should extract both plain timestamps + (should (= 2 (length times))) + (should (string-match-p "14:00" (car (car times)))) + (should (string-match-p "15:00" (car (cadr times)))))) + (kill-buffer test-buffer))) (provide 'test-chime-extract-time) ;;; test-chime-extract-time.el ends here |
