aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime-notifications.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-24 16:18:27 -0400
committerCraig Jennings <c@cjennings.net>2026-06-24 16:18:27 -0400
commitd47f4f90bb1c69697a855a662bb07be1e0ccdc33 (patch)
tree777d0b786a530cb4190f8e062e0afda2506308d4 /tests/test-chime-notifications.el
parentab8cc4da57fce5d0a59f4db34fb550919a06ea79 (diff)
downloadchime-d47f4f90bb1c69697a855a662bb07be1e0ccdc33.tar.gz
chime-d47f4f90bb1c69697a855a662bb07be1e0ccdc33.zip
test: add chime-deftest fixture macro and centralize test requiresHEADmain
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-notifications.el')
-rw-r--r--tests/test-chime-notifications.el310
1 files changed, 133 insertions, 177 deletions
diff --git a/tests/test-chime-notifications.el b/tests/test-chime-notifications.el
index 17ce540..e3c7cc2 100644
--- a/tests/test-chime-notifications.el
+++ b/tests/test-chime-notifications.el
@@ -26,221 +26,177 @@
(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-notifications-setup ()
- "Setup function run before each test."
- (chime-create-test-base-dir))
-
-(defun test-chime-notifications-teardown ()
- "Teardown function run after each test."
- (chime-delete-test-base-dir))
-
;;; Normal Cases
-(ert-deftest test-chime-notifications-single-time-single-interval-returns-pair ()
+(chime-deftest test-chime-notifications-single-time-single-interval-returns-pair ()
"Test that single time with single interval returns one notification pair.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Event at 14:10 (10 minutes from now)
- (event-time (test-time-today-at 14 10))
- (timestamp-str (test-timestamp-string event-time)))
- (with-test-time now
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "Test Event")
- (intervals . ((10 . medium)))))
- (result (chime--notifications event)))
- ;; Should return list with one pair
- (should (listp result))
- (should (= 1 (length result))))))
- (test-chime-notifications-teardown)))
-
-(ert-deftest test-chime-notifications-single-time-multiple-intervals-returns-multiple-pairs ()
+ (let* ((now (test-time-today-at 14 0))
+ ;; Event at 14:10 (10 minutes from now)
+ (event-time (test-time-today-at 14 10))
+ (timestamp-str (test-timestamp-string event-time)))
+ (with-test-time now
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Test Event")
+ (intervals . ((10 . medium)))))
+ (result (chime--notifications event)))
+ ;; Should return list with one pair
+ (should (listp result))
+ (should (= 1 (length result)))))))
+
+(chime-deftest test-chime-notifications-single-time-multiple-intervals-returns-multiple-pairs ()
"Test that single time with multiple intervals returns multiple notification pairs.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Event at 14:10
- (event-time (test-time-today-at 14 10))
- (timestamp-str (test-timestamp-string event-time)))
- (with-test-time now
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "Test Event")
- (intervals . ((10 . medium) (5 . medium))))) ; Two intervals, only 10 matches
- (result (chime--notifications event)))
- ;; Should return only matching interval
- (should (listp result))
- (should (= 1 (length result))))))
- (test-chime-notifications-teardown)))
-
-(ert-deftest test-chime-notifications-multiple-times-single-interval-returns-matching-pairs ()
+ (let* ((now (test-time-today-at 14 0))
+ ;; Event at 14:10
+ (event-time (test-time-today-at 14 10))
+ (timestamp-str (test-timestamp-string event-time)))
+ (with-test-time now
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Test Event")
+ (intervals . ((10 . medium) (5 . medium))))) ; Two intervals, only 10 matches
+ (result (chime--notifications event)))
+ ;; Should return only matching interval
+ (should (listp result))
+ (should (= 1 (length result)))))))
+
+(chime-deftest test-chime-notifications-multiple-times-single-interval-returns-matching-pairs ()
"Test that multiple times with single interval returns matching notifications.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Two events: one at 14:10, one at 14:05
- (event-time-1 (test-time-today-at 14 10))
- (event-time-2 (test-time-today-at 14 5))
- (timestamp-str-1 (test-timestamp-string event-time-1))
- (timestamp-str-2 (test-timestamp-string event-time-2)))
- (with-test-time now
- (let* ((event `((times . ((,timestamp-str-1 . ,event-time-1)
- (,timestamp-str-2 . ,event-time-2)))
- (title . "Test Event")
- (intervals . ((10 . medium))))) ; Only first time matches
- (result (chime--notifications event)))
- ;; Should return only matching time
- (should (listp result))
- (should (= 1 (length result))))))
- (test-chime-notifications-teardown)))
-
-(ert-deftest test-chime-notifications-multiple-times-multiple-intervals-returns-all-matches ()
+ (let* ((now (test-time-today-at 14 0))
+ ;; Two events: one at 14:10, one at 14:05
+ (event-time-1 (test-time-today-at 14 10))
+ (event-time-2 (test-time-today-at 14 5))
+ (timestamp-str-1 (test-timestamp-string event-time-1))
+ (timestamp-str-2 (test-timestamp-string event-time-2)))
+ (with-test-time now
+ (let* ((event `((times . ((,timestamp-str-1 . ,event-time-1)
+ (,timestamp-str-2 . ,event-time-2)))
+ (title . "Test Event")
+ (intervals . ((10 . medium))))) ; Only first time matches
+ (result (chime--notifications event)))
+ ;; Should return only matching time
+ (should (listp result))
+ (should (= 1 (length result)))))))
+
+(chime-deftest test-chime-notifications-multiple-times-multiple-intervals-returns-all-matches ()
"Test that multiple times and intervals return all matching combinations.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Event at 14:10 and 14:05
- (event-time-1 (test-time-today-at 14 10))
- (event-time-2 (test-time-today-at 14 5))
- (timestamp-str-1 (test-timestamp-string event-time-1))
- (timestamp-str-2 (test-timestamp-string event-time-2)))
- (with-test-time now
- (let* ((event `((times . ((,timestamp-str-1 . ,event-time-1)
- (,timestamp-str-2 . ,event-time-2)))
- (title . "Test Event")
- (intervals . ((10 . medium) (5 . medium))))) ; Both match (10 with first, 5 with second)
- (result (chime--notifications event)))
- ;; Should return both matching pairs
- (should (listp result))
- (should (= 2 (length result))))))
- (test-chime-notifications-teardown)))
-
-(ert-deftest test-chime-notifications-zero-interval-returns-current-time-match ()
+ (let* ((now (test-time-today-at 14 0))
+ ;; Event at 14:10 and 14:05
+ (event-time-1 (test-time-today-at 14 10))
+ (event-time-2 (test-time-today-at 14 5))
+ (timestamp-str-1 (test-timestamp-string event-time-1))
+ (timestamp-str-2 (test-timestamp-string event-time-2)))
+ (with-test-time now
+ (let* ((event `((times . ((,timestamp-str-1 . ,event-time-1)
+ (,timestamp-str-2 . ,event-time-2)))
+ (title . "Test Event")
+ (intervals . ((10 . medium) (5 . medium))))) ; Both match (10 with first, 5 with second)
+ (result (chime--notifications event)))
+ ;; Should return both matching pairs
+ (should (listp result))
+ (should (= 2 (length result)))))))
+
+(chime-deftest test-chime-notifications-zero-interval-returns-current-time-match ()
"Test that zero interval (notify now) works correctly.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Event at exactly current time
- (event-time (test-time-today-at 14 0))
- (timestamp-str (test-timestamp-string event-time)))
- (with-test-time now
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "Test Event")
- (intervals . ((0 . high)))))
- (result (chime--notifications event)))
- ;; Should return one matching pair
- (should (listp result))
- (should (= 1 (length result))))))
- (test-chime-notifications-teardown)))
-
-(ert-deftest test-chime-notifications-filters-day-wide-events ()
+ (let* ((now (test-time-today-at 14 0))
+ ;; Event at exactly current time
+ (event-time (test-time-today-at 14 0))
+ (timestamp-str (test-timestamp-string event-time)))
+ (with-test-time now
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Test Event")
+ (intervals . ((0 . high)))))
+ (result (chime--notifications event)))
+ ;; Should return one matching pair
+ (should (listp result))
+ (should (= 1 (length result)))))))
+
+(chime-deftest test-chime-notifications-filters-day-wide-events ()
"Test that day-wide events (without time) are filtered out.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Mix of day-wide and timed events
- (event-time (test-time-today-at 14 10))
- (timestamp-str-day (test-timestamp-string event-time t)) ; Day-wide
- (timestamp-str-timed (test-timestamp-string event-time))) ; Timed
- (with-test-time now
- (let* ((event `((times . ((,timestamp-str-day . ,event-time) ; Day-wide
- (,timestamp-str-timed . ,event-time))) ; Timed
- (title . "Test Event")
- (intervals . ((10 . medium)))))
- (result (chime--notifications event)))
- ;; Should return only timed event
- (should (listp result))
- (should (= 1 (length result))))))
- (test-chime-notifications-teardown)))
+ (let* ((now (test-time-today-at 14 0))
+ ;; Mix of day-wide and timed events
+ (event-time (test-time-today-at 14 10))
+ (timestamp-str-day (test-timestamp-string event-time t)) ; Day-wide
+ (timestamp-str-timed (test-timestamp-string event-time))) ; Timed
+ (with-test-time now
+ (let* ((event `((times . ((,timestamp-str-day . ,event-time) ; Day-wide
+ (,timestamp-str-timed . ,event-time))) ; Timed
+ (title . "Test Event")
+ (intervals . ((10 . medium)))))
+ (result (chime--notifications event)))
+ ;; Should return only timed event
+ (should (listp result))
+ (should (= 1 (length result)))))))
;;; Boundary Cases
-(ert-deftest test-chime-notifications-empty-times-returns-empty-list ()
+(chime-deftest test-chime-notifications-empty-times-returns-empty-list ()
"Test that event with no times returns empty list.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let ((now (test-time-today-at 14 0)))
- (with-test-time now
- (let* ((event `((times . (()))
- (title . "Test Event")
- (intervals . ((10 . medium)))))
- (result (chime--notifications event)))
- (should (listp result))
- (should (= 0 (length result))))))
- (test-chime-notifications-teardown)))
-
-(ert-deftest test-chime-notifications-empty-intervals-returns-empty-list ()
+ (let ((now (test-time-today-at 14 0)))
+ (with-test-time now
+ (let* ((event `((times . (()))
+ (title . "Test Event")
+ (intervals . ((10 . medium)))))
+ (result (chime--notifications event)))
+ (should (listp result))
+ (should (= 0 (length result)))))))
+
+(chime-deftest test-chime-notifications-empty-intervals-returns-empty-list ()
"Test that event with no intervals returns empty list.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- (event-time (test-time-today-at 14 10))
- (timestamp-str (test-timestamp-string event-time)))
- (with-test-time now
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "Test Event")
- (intervals . ())))
- (result (chime--notifications event)))
- (should (listp result))
- (should (= 0 (length result))))))
- (test-chime-notifications-teardown)))
+ (let* ((now (test-time-today-at 14 0))
+ (event-time (test-time-today-at 14 10))
+ (timestamp-str (test-timestamp-string event-time)))
+ (with-test-time now
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Test Event")
+ (intervals . ())))
+ (result (chime--notifications event)))
+ (should (listp result))
+ (should (= 0 (length result)))))))
;;; Error Cases
-(ert-deftest test-chime-notifications-nil-times-returns-empty-list ()
+(chime-deftest test-chime-notifications-nil-times-returns-empty-list ()
"Test that event with nil times returns empty list.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let ((now (test-time-today-at 14 0)))
- (with-test-time now
- (let* ((event `((times . (nil))
- (title . "Test Event")
- (intervals . ((10 . medium)))))
- (result (chime--notifications event)))
- (should (listp result))
- (should (= 0 (length result))))))
- (test-chime-notifications-teardown)))
-
-(ert-deftest test-chime-notifications-nil-intervals-returns-empty-list ()
+ (let ((now (test-time-today-at 14 0)))
+ (with-test-time now
+ (let* ((event `((times . (nil))
+ (title . "Test Event")
+ (intervals . ((10 . medium)))))
+ (result (chime--notifications event)))
+ (should (listp result))
+ (should (= 0 (length result)))))))
+
+(chime-deftest test-chime-notifications-nil-intervals-returns-empty-list ()
"Test that event with nil intervals returns empty list.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- (event-time (test-time-today-at 14 10))
- (timestamp-str (test-timestamp-string event-time)))
- (with-test-time now
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "Test Event")
- (intervals . nil)))
- (result (chime--notifications event)))
- (should (listp result))
- (should (= 0 (length result))))))
- (test-chime-notifications-teardown)))
+ (let* ((now (test-time-today-at 14 0))
+ (event-time (test-time-today-at 14 10))
+ (timestamp-str (test-timestamp-string event-time)))
+ (with-test-time now
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Test Event")
+ (intervals . nil)))
+ (result (chime--notifications event)))
+ (should (listp result))
+ (should (= 0 (length result)))))))
(provide 'test-chime-notifications)
;;; test-chime-notifications.el ends here