diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-11 04:50:45 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-11 04:50:45 -0500 |
| commit | 21ec114def7df9aa61e43e8f2cee484ded772e72 (patch) | |
| tree | bcce37275249879f5fb32d879e19126efdacf2d4 /tests/test-chime-lifecycle.el | |
| parent | a11f554fd533f2139cf6b9e592388a5385d4462b (diff) | |
| download | chime-21ec114def7df9aa61e43e8f2cee484ded772e72.tar.gz chime-21ec114def7df9aa61e43e8f2cee484ded772e72.zip | |
test: close coverage gaps to 99.88% line coverage
Five new test files cover branches the per-function suites missed: the day-wide notification pipeline, the jump-to-event navigation path (including the org-show-entry fallback for Org < 9.6), chime--stop's process-interrupt branch, chime--start's debug log, and the two async error branches in chime--fetch-and-process. The edge-coverage file mops up scattered one-line fallbacks: the day-wide-notification "today" path, the tooltip placeholder pass-through, timestamp-parse's no-context error message, log-silently's mid-line newline insert, the validation :error count, and record-async-failure's chime-debug hook.
Line coverage on chime.el goes from 97.1% to 99.88%, 823 of 824 coverable lines. The one remaining line is a pcase _ fallback the preceding regex can't reach.
Diffstat (limited to 'tests/test-chime-lifecycle.el')
| -rw-r--r-- | tests/test-chime-lifecycle.el | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/test-chime-lifecycle.el b/tests/test-chime-lifecycle.el new file mode 100644 index 0000000..8ce9c13 --- /dev/null +++ b/tests/test-chime-lifecycle.el @@ -0,0 +1,87 @@ +;;; test-chime-lifecycle.el --- Tests for chime--stop and chime--start -*- lexical-binding: t; -*- + +;; Copyright (C) 2026 Craig Jennings + +;; Author: Craig Jennings <c@cjennings.net> + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;;; Commentary: + +;; Unit tests for the internal lifecycle entry points `chime--stop' and +;; `chime--start'. Tests cover branches not exercised by higher-level +;; mode-toggle tests: in-progress process cleanup and the debug-only +;; scheduling log line. + +;;; Code: + +(require 'test-bootstrap (expand-file-name "test-bootstrap.el")) +(require 'cl-lib) + +(ert-deftest test-chime-stop-interrupts-running-process () + "Normal: when chime--process is set, `chime--stop' interrupts it and clears the var." + (let ((interrupted nil) + (chime--timer nil) + (chime--process 'fake-process) + (chime--validation-done t) + (chime--validation-retry-count 5)) + (cl-letf (((symbol-function 'interrupt-process) + (lambda (proc) (setq interrupted proc)))) + (chime--stop)) + (should (eq 'fake-process interrupted)) + (should (null chime--process)) + (should-not chime--validation-done) + (should (= 0 chime--validation-retry-count)))) + +(ert-deftest test-chime-stop-no-process-skips-interrupt () + "Boundary: with chime--process nil, `interrupt-process' is never called." + (let ((interrupted nil) + (chime--timer nil) + (chime--process nil) + (chime--validation-done t) + (chime--validation-retry-count 5)) + (cl-letf (((symbol-function 'interrupt-process) + (lambda (proc) (setq interrupted proc)))) + (chime--stop)) + (should (null interrupted)) + (should-not chime--validation-done) + (should (= 0 chime--validation-retry-count)))) + +(ert-deftest test-chime-start-logs-debug-message-when-feature-loaded () + "Normal: with the chime-debug feature loaded, start emits a scheduling log line." + (let ((logged nil) + (chime--timer nil) + (chime--process nil)) + (cl-letf (((symbol-function 'featurep) + (lambda (feat &rest _) (eq feat 'chime-debug))) + ((symbol-function 'run-at-time) + (lambda (&rest _) 'fake-timer)) + ((symbol-function 'chime--log-silently) + (lambda (fmt &rest args) + (push (apply #'format fmt args) logged)))) + (chime--start)) + (should (cl-some (lambda (m) (string-match-p "Scheduling first check" m)) + logged)) + (should (eq 'fake-timer chime--timer)))) + +(ert-deftest test-chime-start-skips-debug-log-when-feature-absent () + "Boundary: without the chime-debug feature loaded, no log line is emitted." + (let ((logged nil) + (chime--timer nil) + (chime--process nil)) + (cl-letf (((symbol-function 'featurep) + (lambda (feat &rest _) (not (eq feat 'chime-debug)))) + ((symbol-function 'run-at-time) + (lambda (&rest _) 'fake-timer)) + ((symbol-function 'chime--log-silently) + (lambda (fmt &rest args) + (push (apply #'format fmt args) logged)))) + (chime--start)) + (should (null logged)) + (should (eq 'fake-timer chime--timer)))) + +(provide 'test-chime-lifecycle) +;;; test-chime-lifecycle.el ends here |
