diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-05 05:11:55 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-05 05:11:55 -0500 |
| commit | ba22e0cc3c81d85b3ee8aaa337d6a388627c3af2 (patch) | |
| tree | 87edb50acc44464d2887d73f2e0eb46cdac7b91e /tests/test-wttrin-debug-show-log.el | |
| parent | 6554cb8000a8f471f7c9e050e284f3fc364d5dad (diff) | |
| download | emacs-wttrin-ba22e0cc3c81d85b3ee8aaa337d6a388627c3af2.tar.gz emacs-wttrin-ba22e0cc3c81d85b3ee8aaa337d6a388627c3af2.zip | |
test: cover wttrin-debug.el and expand lint to all source files
I added 24 unit tests across six new files for wttrin-debug.el. They cover enable/disable, the debug-log writer, clear-log, show-log, and the mode-line diagnostic dump. That lifts wttrin-debug.el coverage from 27% to 95%, and overall coverage from 84% to 94%. Each function gets Normal / Boundary / Error categories where applicable. Globals like `wttrin-debug` and `wttrin--debug-log` are isolated per test with let-bindings. The dynamic-scope rebinding restores state cleanly at exit.
I expanded the `lint` target to run on all three source files instead of just `wttrin.el`. Checkdoc and elisp-lint run on every file. Package-lint stays scoped to `wttrin.el` because the others aren't standalone packages.
The tricky bit: `elisp-lint-file` re-runs package-lint internally as one of its validators. So the explicit guard alone wasn't enough. The fix binds `elisp-lint-ignored-validators` to include "package-lint" for the secondaries, which suppresses the re-run at the validator level.
I also added `*-autoloads.el` to .gitignore. Eask generates `emacs-wttrin-autoloads.el` during install, and it shouldn't be tracked.
I skipped one function: `wttrin--debug-mode-line-info` is a one-line dispatcher to `debug-wttrin-mode-line`. Testing it would assert the dispatch happened, which only tests Emacs.
Diffstat (limited to 'tests/test-wttrin-debug-show-log.el')
| -rw-r--r-- | tests/test-wttrin-debug-show-log.el | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/test-wttrin-debug-show-log.el b/tests/test-wttrin-debug-show-log.el new file mode 100644 index 0000000..e90b2e9 --- /dev/null +++ b/tests/test-wttrin-debug-show-log.el @@ -0,0 +1,101 @@ +;;; test-wttrin-debug-show-log.el --- Tests for wttrin-debug-show-log -*- lexical-binding: t; -*- + +;; Copyright (C) 2025-2026 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-debug-show-log. Verifies the *wttrin-debug-log* +;; buffer is created with the expected header, entry rendering, and the +;; reversed (oldest-first) ordering used for human reading. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +(require 'wttrin-debug + (expand-file-name "wttrin-debug.el" + (file-name-directory (locate-library "wttrin")))) + +;;; Setup and Teardown + +(defun test-wttrin-debug-show-log-setup () + "Setup for show-log tests." + (when (get-buffer "*wttrin-debug-log*") + (kill-buffer "*wttrin-debug-log*"))) + +(defun test-wttrin-debug-show-log-teardown () + "Teardown for show-log tests." + (when (get-buffer "*wttrin-debug-log*") + (kill-buffer "*wttrin-debug-log*"))) + +;;; Normal Cases + +(ert-deftest test-wttrin-debug-show-log-normal-creates-display-buffer () + "Show-log creates the *wttrin-debug-log* buffer." + (test-wttrin-debug-show-log-setup) + (unwind-protect + (let ((wttrin--debug-log nil)) + (wttrin-debug-show-log) + (should (get-buffer "*wttrin-debug-log*"))) + (test-wttrin-debug-show-log-teardown))) + +(ert-deftest test-wttrin-debug-show-log-normal-header-shows-entry-count () + "Header reflects the number of entries currently in the log." + (test-wttrin-debug-show-log-setup) + (unwind-protect + (let ((wttrin--debug-log '(("00:00:03.000" . "c") + ("00:00:02.000" . "b") + ("00:00:01.000" . "a")))) + (wttrin-debug-show-log) + (with-current-buffer "*wttrin-debug-log*" + (should (string-match-p "Total entries: 3" (buffer-string))))) + (test-wttrin-debug-show-log-teardown))) + +(ert-deftest test-wttrin-debug-show-log-normal-renders-entries-with-timestamps () + "Each entry appears as [timestamp] message in the display." + (test-wttrin-debug-show-log-setup) + (unwind-protect + (let ((wttrin--debug-log '(("12:34:56.789" . "hello world")))) + (wttrin-debug-show-log) + (with-current-buffer "*wttrin-debug-log*" + (should (string-match-p "\\[12:34:56\\.789\\] hello world" + (buffer-string))))) + (test-wttrin-debug-show-log-teardown))) + +(ert-deftest test-wttrin-debug-show-log-normal-entries-rendered-oldest-first () + "Storage is newest-first (push); display reverses to oldest-first for reading." + (test-wttrin-debug-show-log-setup) + (unwind-protect + (let ((wttrin--debug-log '(("00:00:03.000" . "third") + ("00:00:02.000" . "second") + ("00:00:01.000" . "first")))) + (wttrin-debug-show-log) + (with-current-buffer "*wttrin-debug-log*" + (let* ((contents (buffer-string)) + (pos-first (string-match "first" contents)) + (pos-second (string-match "second" contents)) + (pos-third (string-match "third" contents))) + (should pos-first) + (should pos-second) + (should pos-third) + (should (< pos-first pos-second)) + (should (< pos-second pos-third))))) + (test-wttrin-debug-show-log-teardown))) + +;;; Boundary Cases + +(ert-deftest test-wttrin-debug-show-log-boundary-empty-log-shows-placeholder () + "Empty log renders the \"No log entries yet\" placeholder." + (test-wttrin-debug-show-log-setup) + (unwind-protect + (let ((wttrin--debug-log nil)) + (wttrin-debug-show-log) + (with-current-buffer "*wttrin-debug-log*" + (should (string-match-p "(No log entries yet)" (buffer-string))) + (should (string-match-p "Total entries: 0" (buffer-string))))) + (test-wttrin-debug-show-log-teardown))) + +(provide 'test-wttrin-debug-show-log) +;;; test-wttrin-debug-show-log.el ends here |
