aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-05 05:11:55 -0500
committerCraig Jennings <c@cjennings.net>2026-05-05 05:11:55 -0500
commitba22e0cc3c81d85b3ee8aaa337d6a388627c3af2 (patch)
tree87edb50acc44464d2887d73f2e0eb46cdac7b91e
parent6554cb8000a8f471f7c9e050e284f3fc364d5dad (diff)
downloademacs-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.
-rw-r--r--.gitignore1
-rw-r--r--Makefile39
-rw-r--r--tests/test-debug-wttrin-disable.el43
-rw-r--r--tests/test-debug-wttrin-enable.el43
-rw-r--r--tests/test-debug-wttrin-mode-line.el79
-rw-r--r--tests/test-wttrin--debug-log.el82
-rw-r--r--tests/test-wttrin-debug-clear-log.el45
-rw-r--r--tests/test-wttrin-debug-show-log.el101
8 files changed, 417 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index b622a8e..aead5da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
/.coverage/
/dist/
*.elc
+*-autoloads.el
diff --git a/Makefile b/Makefile
index 846fdb5..f80a494 100644
--- a/Makefile
+++ b/Makefile
@@ -280,22 +280,29 @@ compile:
@echo "[v] Compilation complete"
lint:
- @echo "Running linters on $(MAIN_FILE)..."
- @$(EASK_EMACS) \
- --eval "(progn \
- (require 'checkdoc nil t) \
- (require 'package-lint nil t) \
- (require 'elisp-lint nil t) \
- (find-file \"$(MAIN_FILE)\") \
- (when (featurep 'checkdoc) \
- (message \"-- checkdoc --\") \
- (checkdoc-current-buffer t)) \
- (when (featurep 'package-lint) \
- (message \"-- package-lint --\") \
- (package-lint-current-buffer)) \
- (when (featurep 'elisp-lint) \
- (message \"-- elisp-lint --\") \
- (elisp-lint-file \"$(MAIN_FILE)\")))" || true
+ @echo "Running linters on source files..."
+ @for src in $(SOURCE_FILES); do \
+ echo " Linting $$src..."; \
+ $(EASK_EMACS) \
+ --eval "(let ((src \"$$src\") (main \"$(MAIN_FILE)\")) \
+ (require 'checkdoc nil t) \
+ (require 'package-lint nil t) \
+ (require 'elisp-lint nil t) \
+ (find-file src) \
+ (when (featurep 'checkdoc) \
+ (message \"-- checkdoc on %s --\" src) \
+ (checkdoc-current-buffer t)) \
+ (when (and (featurep 'package-lint) (string= src main)) \
+ (message \"-- package-lint on %s --\" src) \
+ (package-lint-current-buffer)) \
+ (when (featurep 'elisp-lint) \
+ (message \"-- elisp-lint on %s --\" src) \
+ (let ((elisp-lint-ignored-validators \
+ (if (string= src main) \
+ elisp-lint-ignored-validators \
+ (cons \"package-lint\" elisp-lint-ignored-validators)))) \
+ (elisp-lint-file src))))" || true; \
+ done
@echo "[i] Lint complete (informational)"
# ============================================================================
diff --git a/tests/test-debug-wttrin-disable.el b/tests/test-debug-wttrin-disable.el
new file mode 100644
index 0000000..dc560c3
--- /dev/null
+++ b/tests/test-debug-wttrin-disable.el
@@ -0,0 +1,43 @@
+;;; test-debug-wttrin-disable.el --- Tests for debug-wttrin-disable -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025-2026 Craig Jennings
+
+;;; Commentary:
+
+;; Unit tests for debug-wttrin-disable. Verifies the interactive command
+;; clears `wttrin-debug' and is idempotent when already disabled.
+
+;;; Code:
+
+(require 'ert)
+(require 'wttrin)
+(require 'testutil-wttrin)
+
+(require 'wttrin-debug
+ (expand-file-name "wttrin-debug.el"
+ (file-name-directory (locate-library "wttrin"))))
+
+;;; Normal Cases
+
+(ert-deftest test-debug-wttrin-disable-normal-flips-from-t-to-nil ()
+ "Calling disable when wttrin-debug is t sets it to nil."
+ (let ((wttrin-debug t))
+ (debug-wttrin-disable)
+ (should-not wttrin-debug)))
+
+(ert-deftest test-debug-wttrin-disable-normal-idempotent-when-already-disabled ()
+ "Calling disable when wttrin-debug is already nil leaves it nil."
+ (let ((wttrin-debug nil))
+ (debug-wttrin-disable)
+ (should-not wttrin-debug)))
+
+;;; Boundary Cases
+
+(ert-deftest test-debug-wttrin-disable-boundary-clears-non-boolean-truthy-value ()
+ "Calling disable replaces any truthy value with nil."
+ (let ((wttrin-debug 'verbose))
+ (debug-wttrin-disable)
+ (should-not wttrin-debug)))
+
+(provide 'test-debug-wttrin-disable)
+;;; test-debug-wttrin-disable.el ends here
diff --git a/tests/test-debug-wttrin-enable.el b/tests/test-debug-wttrin-enable.el
new file mode 100644
index 0000000..569547d
--- /dev/null
+++ b/tests/test-debug-wttrin-enable.el
@@ -0,0 +1,43 @@
+;;; test-debug-wttrin-enable.el --- Tests for debug-wttrin-enable -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025-2026 Craig Jennings
+
+;;; Commentary:
+
+;; Unit tests for debug-wttrin-enable. Verifies the interactive command
+;; flips `wttrin-debug' to t and is idempotent when already enabled.
+
+;;; Code:
+
+(require 'ert)
+(require 'wttrin)
+(require 'testutil-wttrin)
+
+(require 'wttrin-debug
+ (expand-file-name "wttrin-debug.el"
+ (file-name-directory (locate-library "wttrin"))))
+
+;;; Normal Cases
+
+(ert-deftest test-debug-wttrin-enable-normal-flips-from-nil-to-t ()
+ "Calling enable when wttrin-debug is nil sets it to t."
+ (let ((wttrin-debug nil))
+ (debug-wttrin-enable)
+ (should (eq wttrin-debug t))))
+
+(ert-deftest test-debug-wttrin-enable-normal-idempotent-when-already-enabled ()
+ "Calling enable when wttrin-debug is already t leaves it t."
+ (let ((wttrin-debug t))
+ (debug-wttrin-enable)
+ (should (eq wttrin-debug t))))
+
+;;; Boundary Cases
+
+(ert-deftest test-debug-wttrin-enable-boundary-overrides-non-boolean-truthy-value ()
+ "Calling enable replaces a non-boolean truthy value with t."
+ (let ((wttrin-debug 'verbose))
+ (debug-wttrin-enable)
+ (should (eq wttrin-debug t))))
+
+(provide 'test-debug-wttrin-enable)
+;;; test-debug-wttrin-enable.el ends here
diff --git a/tests/test-debug-wttrin-mode-line.el b/tests/test-debug-wttrin-mode-line.el
new file mode 100644
index 0000000..437185a
--- /dev/null
+++ b/tests/test-debug-wttrin-mode-line.el
@@ -0,0 +1,79 @@
+;;; test-debug-wttrin-mode-line.el --- Tests for debug-wttrin-mode-line -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025-2026 Craig Jennings
+
+;;; Commentary:
+
+;; Unit tests for debug-wttrin-mode-line. This function is a UI-heavy
+;; diagnostic dump, so testing focuses on the two top-level branches:
+;; - When *wttr.in* is missing, no diagnostic buffer is produced.
+;; - When *wttr.in* exists, the diagnostic buffer is created and contains
+;; the expected section labels.
+
+;;; 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-debug-wttrin-mode-line-setup ()
+ "Setup for debug-wttrin-mode-line tests."
+ (when (get-buffer "*wttr.in*")
+ (kill-buffer "*wttr.in*"))
+ (when (get-buffer "*wttrin-mode-debug*")
+ (kill-buffer "*wttrin-mode-debug*")))
+
+(defun test-debug-wttrin-mode-line-teardown ()
+ "Teardown for debug-wttrin-mode-line tests."
+ (when (get-buffer "*wttr.in*")
+ (kill-buffer "*wttr.in*"))
+ (when (get-buffer "*wttrin-mode-debug*")
+ (kill-buffer "*wttrin-mode-debug*")))
+
+;;; Normal Cases
+
+(ert-deftest test-debug-wttrin-mode-line-normal-no-buffer-skips-diagnostic-buffer ()
+ "When the *wttr.in* buffer is absent, no diagnostic buffer is created."
+ (test-debug-wttrin-mode-line-setup)
+ (unwind-protect
+ (progn
+ (debug-wttrin-mode-line)
+ (should-not (get-buffer "*wttrin-mode-debug*")))
+ (test-debug-wttrin-mode-line-teardown)))
+
+(ert-deftest test-debug-wttrin-mode-line-normal-buffer-exists-creates-diagnostic-buffer ()
+ "When the *wttr.in* buffer exists, the diagnostic buffer is created."
+ (test-debug-wttrin-mode-line-setup)
+ (unwind-protect
+ (progn
+ (with-current-buffer (get-buffer-create "*wttr.in*")
+ (wttrin-mode))
+ (debug-wttrin-mode-line)
+ (should (get-buffer "*wttrin-mode-debug*")))
+ (test-debug-wttrin-mode-line-teardown)))
+
+(ert-deftest test-debug-wttrin-mode-line-normal-diagnostic-buffer-contains-section-labels ()
+ "Diagnostic buffer contains the expected section labels."
+ (test-debug-wttrin-mode-line-setup)
+ (unwind-protect
+ (progn
+ (with-current-buffer (get-buffer-create "*wttr.in*")
+ (wttrin-mode))
+ (debug-wttrin-mode-line)
+ (with-current-buffer "*wttrin-mode-debug*"
+ (let ((contents (buffer-string)))
+ (should (string-match-p "Wttrin Mode-Line Debug Info" contents))
+ (should (string-match-p "Buffer:" contents))
+ (should (string-match-p "Major mode:" contents))
+ (should (string-match-p "mode-name variable:" contents))
+ (should (string-match-p "mode-line-format first 5 elements:" contents)))))
+ (test-debug-wttrin-mode-line-teardown)))
+
+(provide 'test-debug-wttrin-mode-line)
+;;; test-debug-wttrin-mode-line.el ends here
diff --git a/tests/test-wttrin--debug-log.el b/tests/test-wttrin--debug-log.el
new file mode 100644
index 0000000..4f4e2ba
--- /dev/null
+++ b/tests/test-wttrin--debug-log.el
@@ -0,0 +1,82 @@
+;;; test-wttrin--debug-log.el --- Tests for wttrin--debug-log -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025-2026 Craig Jennings
+
+;;; Commentary:
+
+;; Unit tests for wttrin--debug-log. Verifies that messages are appended
+;; only when `wttrin-debug' is non-nil, that format args are interpolated,
+;; and that entries are timestamped (timestamp . message) cons cells.
+
+;;; Code:
+
+(require 'ert)
+(require 'wttrin)
+(require 'testutil-wttrin)
+
+(require 'wttrin-debug
+ (expand-file-name "wttrin-debug.el"
+ (file-name-directory (locate-library "wttrin"))))
+
+;;; Normal Cases
+
+(ert-deftest test-wttrin--debug-log-normal-appends-entry-when-debug-enabled ()
+ "Calling debug-log with debug enabled appends a single entry."
+ (let ((wttrin-debug t)
+ (wttrin--debug-log nil))
+ (wttrin--debug-log "hello")
+ (should (= 1 (length wttrin--debug-log)))))
+
+(ert-deftest test-wttrin--debug-log-normal-interpolates-format-args ()
+ "Format args are passed through `format' before storage."
+ (let ((wttrin-debug t)
+ (wttrin--debug-log nil))
+ (wttrin--debug-log "value=%d name=%s" 42 "foo")
+ (should (string= "value=42 name=foo" (cdar wttrin--debug-log)))))
+
+(ert-deftest test-wttrin--debug-log-normal-prepends-most-recent-entry ()
+ "Most recent entry is at the head of the log (push semantics)."
+ (let ((wttrin-debug t)
+ (wttrin--debug-log nil))
+ (wttrin--debug-log "first")
+ (wttrin--debug-log "second")
+ (should (string= "second" (cdar wttrin--debug-log)))
+ (should (string= "first" (cdadr wttrin--debug-log)))))
+
+(ert-deftest test-wttrin--debug-log-normal-timestamp-has-millisecond-format ()
+ "Timestamp is a string in HH:MM:SS.mmm format."
+ (let ((wttrin-debug t)
+ (wttrin--debug-log nil))
+ (wttrin--debug-log "anything")
+ (should (string-match-p "^[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\.[0-9]\\{3\\}$"
+ (caar wttrin--debug-log)))))
+
+;;; Boundary Cases
+
+(ert-deftest test-wttrin--debug-log-boundary-empty-format-string-stores-empty-message ()
+ "An empty format string produces an entry with an empty message."
+ (let ((wttrin-debug t)
+ (wttrin--debug-log nil))
+ (wttrin--debug-log "")
+ (should (= 1 (length wttrin--debug-log)))
+ (should (string= "" (cdar wttrin--debug-log)))))
+
+(ert-deftest test-wttrin--debug-log-boundary-no-format-args-stores-literal-string ()
+ "Calling with only a format string and no args stores it as-is."
+ (let ((wttrin-debug t)
+ (wttrin--debug-log nil))
+ (wttrin--debug-log "literal text with no format directives")
+ (should (string= "literal text with no format directives"
+ (cdar wttrin--debug-log)))))
+
+;;; Error Cases
+
+(ert-deftest test-wttrin--debug-log-error-no-entry-when-debug-disabled ()
+ "When wttrin-debug is nil, debug-log adds nothing."
+ (let ((wttrin-debug nil)
+ (wttrin--debug-log nil))
+ (wttrin--debug-log "should not appear")
+ (should-not wttrin--debug-log)))
+
+(provide 'test-wttrin--debug-log)
+;;; test-wttrin--debug-log.el ends here
diff --git a/tests/test-wttrin-debug-clear-log.el b/tests/test-wttrin-debug-clear-log.el
new file mode 100644
index 0000000..10e4c21
--- /dev/null
+++ b/tests/test-wttrin-debug-clear-log.el
@@ -0,0 +1,45 @@
+;;; test-wttrin-debug-clear-log.el --- Tests for wttrin-debug-clear-log -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025-2026 Craig Jennings
+
+;;; Commentary:
+
+;; Unit tests for wttrin-debug-clear-log. Verifies the interactive
+;; command empties the debug log alist regardless of prior state.
+
+;;; Code:
+
+(require 'ert)
+(require 'wttrin)
+(require 'testutil-wttrin)
+
+(require 'wttrin-debug
+ (expand-file-name "wttrin-debug.el"
+ (file-name-directory (locate-library "wttrin"))))
+
+;;; Normal Cases
+
+(ert-deftest test-wttrin-debug-clear-log-normal-empties-populated-log ()
+ "Clearing a non-empty log leaves it nil."
+ (let ((wttrin--debug-log '(("00:00:01.000" . "one")
+ ("00:00:02.000" . "two"))))
+ (wttrin-debug-clear-log)
+ (should-not wttrin--debug-log)))
+
+(ert-deftest test-wttrin-debug-clear-log-normal-multiple-calls-stay-empty ()
+ "Calling clear twice in a row leaves the log empty."
+ (let ((wttrin--debug-log '(("00:00:01.000" . "one"))))
+ (wttrin-debug-clear-log)
+ (wttrin-debug-clear-log)
+ (should-not wttrin--debug-log)))
+
+;;; Boundary Cases
+
+(ert-deftest test-wttrin-debug-clear-log-boundary-clearing-already-empty-log ()
+ "Clearing an already-empty log is a no-op and leaves it nil."
+ (let ((wttrin--debug-log nil))
+ (wttrin-debug-clear-log)
+ (should-not wttrin--debug-log)))
+
+(provide 'test-wttrin-debug-clear-log)
+;;; test-wttrin-debug-clear-log.el ends here
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