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-fetch-and-process.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-fetch-and-process.el')
| -rw-r--r-- | tests/test-chime-fetch-and-process.el | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/test-chime-fetch-and-process.el b/tests/test-chime-fetch-and-process.el new file mode 100644 index 0000000..6e2917c --- /dev/null +++ b/tests/test-chime-fetch-and-process.el @@ -0,0 +1,83 @@ +;;; test-chime-fetch-and-process.el --- Tests for chime--fetch-and-process branches -*- 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: + +;; Cover the two error branches inside the `chime--fetch-and-process' +;; async callback: +;; +;; 1. The async subprocess returned an `(async-signal . ERR)' tuple. +;; 2. The user-supplied callback raised an error during processing. +;; +;; Both are caught by the surrounding `condition-case' and routed through +;; `chime--record-async-failure' with a distinct prefix. + +;;; Code: + +(require 'test-bootstrap (expand-file-name "test-bootstrap.el")) +(require 'cl-lib) + +(ert-deftest test-chime-fetch-and-process-async-signal-records-failure () + "Error: when async returns an `async-signal' tuple, failure is recorded with the async prefix." + (let ((recorded nil) + (chime--process nil) + (chime--last-check-time '(0 0)) + (chime-modeline-no-events-text " ⏰") + (chime-modeline-string nil) + (chime--consecutive-async-failures 0) + (chime-max-consecutive-failures 0)) + (cl-letf (((symbol-function 'async-start) + (lambda (_start-form finish-func) + (funcall finish-func '(async-signal error "boom")) + 'fake-process)) + ((symbol-function 'chime--record-async-failure) + (lambda (err prefix) (setq recorded (cons prefix err)))) + ((symbol-function 'force-mode-line-update) (lambda (&optional _)))) + (chime--fetch-and-process (lambda (_events) nil))) + (should (equal "Async error" (car recorded))) + (should (equal '(error "boom") (cdr recorded))))) + +(ert-deftest test-chime-fetch-and-process-callback-error-records-failure () + "Error: when the callback raises during processing, failure is recorded with the processing prefix." + (let ((recorded nil) + (chime--process nil) + (chime--last-check-time '(0 0)) + (chime-modeline-no-events-text " ⏰") + (chime-modeline-string nil) + (chime--consecutive-async-failures 0) + (chime-max-consecutive-failures 0)) + (cl-letf (((symbol-function 'async-start) + (lambda (_start-form finish-func) + (funcall finish-func '(((title . "Event")))) + 'fake-process)) + ((symbol-function 'chime--record-async-failure) + (lambda (err prefix) (setq recorded (cons prefix err)))) + ((symbol-function 'force-mode-line-update) (lambda (&optional _)))) + (chime--fetch-and-process (lambda (_events) (error "callback boom")))) + (should (equal "Error processing events" (car recorded))) + (should (string-match-p "callback boom" + (error-message-string (cdr recorded)))))) + +(ert-deftest test-chime-fetch-and-process-skips-when-process-live () + "Boundary: an active live process blocks a fresh fetch." + (let ((fetched nil) + (chime--process 'fake-live-process)) + (cl-letf (((symbol-function 'process-live-p) + (lambda (proc) (eq proc 'fake-live-process))) + ((symbol-function 'async-start) + (lambda (&rest _) + (setq fetched t) + 'unused))) + (chime--fetch-and-process (lambda (_events) nil))) + (should-not fetched))) + +(provide 'test-chime-fetch-and-process) +;;; test-chime-fetch-and-process.el ends here |
