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-format-event-for-tooltip.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-format-event-for-tooltip.el')
| -rw-r--r-- | tests/test-chime-format-event-for-tooltip.el | 303 |
1 files changed, 128 insertions, 175 deletions
diff --git a/tests/test-chime-format-event-for-tooltip.el b/tests/test-chime-format-event-for-tooltip.el index 5e2cabb..0569477 100644 --- a/tests/test-chime-format-event-for-tooltip.el +++ b/tests/test-chime-format-event-for-tooltip.el @@ -26,222 +26,175 @@ (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-format-event-for-tooltip-setup () - "Setup function run before each test." - (chime-create-test-base-dir)) - -(defun test-chime-format-event-for-tooltip-teardown () - "Teardown function run after each test." - (chime-delete-test-base-dir)) - ;;; Normal Cases -(ert-deftest test-chime-format-event-for-tooltip-normal-minutes () +(chime-deftest test-chime-format-event-for-tooltip-normal-minutes () "Test formatting event with minutes until event. REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-tomorrow-at 14 10)) - (timestamp (test-timestamp-string time)) - (result (chime--format-event-for-tooltip - timestamp - 10 - "Team Meeting"))) - (should (stringp result)) - (should (string-match-p "Team Meeting" result)) - (should (string-match-p "02:10 PM" result)) - (should (string-match-p "10 minutes" result))) - (test-chime-format-event-for-tooltip-teardown))) - -(ert-deftest test-chime-format-event-for-tooltip-normal-hours () + (let* ((time (test-time-tomorrow-at 14 10)) + (timestamp (test-timestamp-string time)) + (result (chime--format-event-for-tooltip + timestamp + 10 + "Team Meeting"))) + (should (stringp result)) + (should (string-match-p "Team Meeting" result)) + (should (string-match-p "02:10 PM" result)) + (should (string-match-p "10 minutes" result)))) + +(chime-deftest test-chime-format-event-for-tooltip-normal-hours () "Test formatting event with hours until event. REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-tomorrow-at 15 30)) - (timestamp (test-timestamp-string time)) - (result (chime--format-event-for-tooltip - timestamp - 90 - "Afternoon Meeting"))) - (should (stringp result)) - (should (string-match-p "Afternoon Meeting" result)) - (should (string-match-p "03:30 PM" result)) - (should (string-match-p "1 hour" result))) - (test-chime-format-event-for-tooltip-teardown))) - -(ert-deftest test-chime-format-event-for-tooltip-normal-multiple-hours () + (let* ((time (test-time-tomorrow-at 15 30)) + (timestamp (test-timestamp-string time)) + (result (chime--format-event-for-tooltip + timestamp + 90 + "Afternoon Meeting"))) + (should (stringp result)) + (should (string-match-p "Afternoon Meeting" result)) + (should (string-match-p "03:30 PM" result)) + (should (string-match-p "1 hour" result)))) + +(chime-deftest test-chime-format-event-for-tooltip-normal-multiple-hours () "Test formatting event with multiple hours until event. REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-tomorrow-at 17 0)) - (timestamp (test-timestamp-string time)) - (result (chime--format-event-for-tooltip - timestamp - 300 - "End of Day Review"))) - (should (stringp result)) - (should (string-match-p "End of Day Review" result)) - (should (string-match-p "05:00 PM" result)) - (should (string-match-p "5 hours" result))) - (test-chime-format-event-for-tooltip-teardown))) + (let* ((time (test-time-tomorrow-at 17 0)) + (timestamp (test-timestamp-string time)) + (result (chime--format-event-for-tooltip + timestamp + 300 + "End of Day Review"))) + (should (stringp result)) + (should (string-match-p "End of Day Review" result)) + (should (string-match-p "05:00 PM" result)) + (should (string-match-p "5 hours" result)))) ;;; Boundary Cases -(ert-deftest test-chime-format-event-for-tooltip-boundary-exactly-one-day () +(chime-deftest test-chime-format-event-for-tooltip-boundary-exactly-one-day () "Test formatting event exactly 1 day away (1440 minutes). REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-days-from-now 1 9 0)) - (timestamp (test-timestamp-string time)) - (result (chime--format-event-for-tooltip - timestamp - 1440 - "Tomorrow Event"))) - (should (stringp result)) - (should (string-match-p "Tomorrow Event" result)) - (should (string-match-p "09:00 AM" result)) - (should (string-match-p "in 1 day" result))) - (test-chime-format-event-for-tooltip-teardown))) - -(ert-deftest test-chime-format-event-for-tooltip-boundary-multiple-days () + (let* ((time (test-time-days-from-now 1 9 0)) + (timestamp (test-timestamp-string time)) + (result (chime--format-event-for-tooltip + timestamp + 1440 + "Tomorrow Event"))) + (should (stringp result)) + (should (string-match-p "Tomorrow Event" result)) + (should (string-match-p "09:00 AM" result)) + (should (string-match-p "in 1 day" result)))) + +(chime-deftest test-chime-format-event-for-tooltip-boundary-multiple-days () "Test formatting event multiple days away. REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-days-from-now 3 10 0)) - (timestamp (test-timestamp-string time)) - (result (chime--format-event-for-tooltip - timestamp - 4320 ; 3 days - "Future Meeting"))) - (should (stringp result)) - (should (string-match-p "Future Meeting" result)) - (should (string-match-p "10:00 AM" result)) - (should (string-match-p "in 3 days" result))) - (test-chime-format-event-for-tooltip-teardown))) - -(ert-deftest test-chime-format-event-for-tooltip-boundary-just-under-one-day () + (let* ((time (test-time-days-from-now 3 10 0)) + (timestamp (test-timestamp-string time)) + (result (chime--format-event-for-tooltip + timestamp + 4320 ; 3 days + "Future Meeting"))) + (should (stringp result)) + (should (string-match-p "Future Meeting" result)) + (should (string-match-p "10:00 AM" result)) + (should (string-match-p "in 3 days" result)))) + +(chime-deftest test-chime-format-event-for-tooltip-boundary-just-under-one-day () "Test formatting event just under 1 day away (1439 minutes). REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-tomorrow-at 8 59)) - (timestamp (test-timestamp-string time)) - (result (chime--format-event-for-tooltip - timestamp - 1439 - "Almost Tomorrow"))) - (should (stringp result)) - (should (string-match-p "Almost Tomorrow" result)) - (should (string-match-p "08:59 AM" result)) - ;; Should show hours/minutes, not days - (should (string-match-p "23 hours" result))) - (test-chime-format-event-for-tooltip-teardown))) - -(ert-deftest test-chime-format-event-for-tooltip-boundary-zero-minutes () + (let* ((time (test-time-tomorrow-at 8 59)) + (timestamp (test-timestamp-string time)) + (result (chime--format-event-for-tooltip + timestamp + 1439 + "Almost Tomorrow"))) + (should (stringp result)) + (should (string-match-p "Almost Tomorrow" result)) + (should (string-match-p "08:59 AM" result)) + ;; Should show hours/minutes, not days + (should (string-match-p "23 hours" result)))) + +(chime-deftest test-chime-format-event-for-tooltip-boundary-zero-minutes () "Test formatting event happening right now (0 minutes). REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-today-at 14 0)) - (timestamp (test-timestamp-string time)) - (result (chime--format-event-for-tooltip - timestamp - 0 - "Current Event"))) - (should (stringp result)) - (should (string-match-p "Current Event" result)) - (should (string-match-p "02:00 PM" result)) - (should (string-match-p "right now" result))) - (test-chime-format-event-for-tooltip-teardown))) - -(ert-deftest test-chime-format-event-for-tooltip-boundary-one-minute () + (let* ((time (test-time-today-at 14 0)) + (timestamp (test-timestamp-string time)) + (result (chime--format-event-for-tooltip + timestamp + 0 + "Current Event"))) + (should (stringp result)) + (should (string-match-p "Current Event" result)) + (should (string-match-p "02:00 PM" result)) + (should (string-match-p "right now" result)))) + +(chime-deftest test-chime-format-event-for-tooltip-boundary-one-minute () "Test formatting event 1 minute away. REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-today-at 14 1)) - (timestamp (test-timestamp-string time)) - (result (chime--format-event-for-tooltip - timestamp - 1 - "Imminent Event"))) - (should (stringp result)) - (should (string-match-p "Imminent Event" result)) - (should (string-match-p "02:01 PM" result)) - (should (string-match-p "1 minute" result))) - (test-chime-format-event-for-tooltip-teardown))) - -(ert-deftest test-chime-format-event-for-tooltip-boundary-long-title () + (let* ((time (test-time-today-at 14 1)) + (timestamp (test-timestamp-string time)) + (result (chime--format-event-for-tooltip + timestamp + 1 + "Imminent Event"))) + (should (stringp result)) + (should (string-match-p "Imminent Event" result)) + (should (string-match-p "02:01 PM" result)) + (should (string-match-p "1 minute" result)))) + +(chime-deftest test-chime-format-event-for-tooltip-boundary-long-title () "Test formatting event with very long title. REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-today-at 14 10)) - (timestamp (test-timestamp-string time)) - (long-title (make-string 200 ?x)) - (result (chime--format-event-for-tooltip - timestamp - 10 - long-title))) - (should (stringp result)) - (should (string-match-p long-title result))) - (test-chime-format-event-for-tooltip-teardown))) + (let* ((time (test-time-today-at 14 10)) + (timestamp (test-timestamp-string time)) + (long-title (make-string 200 ?x)) + (result (chime--format-event-for-tooltip + timestamp + 10 + long-title))) + (should (stringp result)) + (should (string-match-p long-title result)))) ;;; Error Cases -(ert-deftest test-chime-format-event-for-tooltip-error-nil-title () +(chime-deftest test-chime-format-event-for-tooltip-error-nil-title () "Test formatting with nil title doesn't crash. REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-today-at 14 10)) - (timestamp (test-timestamp-string time))) - ;; Should not crash with nil title - (should-not (condition-case nil - (progn - (chime--format-event-for-tooltip - timestamp - 10 - nil) - nil) - (error t)))) - (test-chime-format-event-for-tooltip-teardown))) - -(ert-deftest test-chime-format-event-for-tooltip-error-empty-title () + (let* ((time (test-time-today-at 14 10)) + (timestamp (test-timestamp-string time))) + ;; Should not crash with nil title + (should-not (condition-case nil + (progn + (chime--format-event-for-tooltip + timestamp + 10 + nil) + nil) + (error t))))) + +(chime-deftest test-chime-format-event-for-tooltip-error-empty-title () "Test formatting with empty title. REFACTORED: Uses dynamic timestamps" - (test-chime-format-event-for-tooltip-setup) - (unwind-protect - (let* ((time (test-time-today-at 14 10)) - (timestamp (test-timestamp-string time)) - (result (chime--format-event-for-tooltip - timestamp - 10 - ""))) - (should (stringp result)) - (should (string-match-p "02:10 PM" result))) - (test-chime-format-event-for-tooltip-teardown))) + (let* ((time (test-time-today-at 14 10)) + (timestamp (test-timestamp-string time)) + (result (chime--format-event-for-tooltip + timestamp + 10 + ""))) + (should (stringp result)) + (should (string-match-p "02:10 PM" result)))) (provide 'test-chime-format-event-for-tooltip) ;;; test-chime-format-event-for-tooltip.el ends here |
