From 35131cb72c08c657d2a3389338d0c049d57e69bd Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 5 May 2026 05:20:44 -0500 Subject: refactor: rename debug-wttrin-* commands to wttrin-debug-* with obsolete aliases The four interactive commands in `wttrin-debug.el` used `debug-wttrin-` as their prefix instead of the package's `wttrin-debug-` prefix. package-lint flags this as a convention violation, and it makes M-x discovery slightly less consistent for users. Renamed: - `debug-wttrin-show-raw` -> `wttrin-debug-show-raw` - `debug-wttrin-enable` -> `wttrin-debug-enable` - `debug-wttrin-disable` -> `wttrin-debug-disable` - `debug-wttrin-mode-line` -> `wttrin-debug-mode-line` The old names stay available as `define-obsolete-function-alias` entries marked since 0.4.0, so anyone with a keybinding or `(call-interactively 'debug-wttrin-enable)` in their config keeps working. The byte-compiler will emit an obsolescence warning to nudge migration. Aliases will be removed in a future release. Internal caller `wttrin--debug-mode-line-info` now invokes the new name. Test files renamed to match (`test-debug-wttrin-*.el` -> `test-wttrin-debug-*.el`); inside each, ert-deftest names and function calls were updated. Added `tests/test-wttrin-debug-aliases.el` to verify each old name resolves via `indirect-function` to the new name and carries `byte-obsolete-info` with the expected target and "0.4.0" version. --- tests/README-DEBUG-TESTS.org | 2 +- tests/test-debug-wttrin-disable.el | 43 ------------- tests/test-debug-wttrin-enable.el | 43 ------------- tests/test-debug-wttrin-mode-line.el | 79 ----------------------- tests/test-debug-wttrin-show-raw.el | 121 ----------------------------------- tests/test-wttrin-debug-aliases.el | 52 +++++++++++++++ tests/test-wttrin-debug-disable.el | 43 +++++++++++++ tests/test-wttrin-debug-enable.el | 43 +++++++++++++ tests/test-wttrin-debug-mode-line.el | 79 +++++++++++++++++++++++ tests/test-wttrin-debug-show-raw.el | 121 +++++++++++++++++++++++++++++++++++ wttrin-debug.el | 34 +++++++--- 11 files changed, 364 insertions(+), 296 deletions(-) delete mode 100644 tests/test-debug-wttrin-disable.el delete mode 100644 tests/test-debug-wttrin-enable.el delete mode 100644 tests/test-debug-wttrin-mode-line.el delete mode 100644 tests/test-debug-wttrin-show-raw.el create mode 100644 tests/test-wttrin-debug-aliases.el create mode 100644 tests/test-wttrin-debug-disable.el create mode 100644 tests/test-wttrin-debug-enable.el create mode 100644 tests/test-wttrin-debug-mode-line.el create mode 100644 tests/test-wttrin-debug-show-raw.el diff --git a/tests/README-DEBUG-TESTS.org b/tests/README-DEBUG-TESTS.org index ed303f8..70a1e09 100644 --- a/tests/README-DEBUG-TESTS.org +++ b/tests/README-DEBUG-TESTS.org @@ -50,7 +50,7 @@ The integration tests demonstrate: ** Or Enable Later #+begin_src emacs-lisp -M-x debug-wttrin-enable +M-x wttrin-debug-enable #+end_src ** View Debug Log diff --git a/tests/test-debug-wttrin-disable.el b/tests/test-debug-wttrin-disable.el deleted file mode 100644 index dc560c3..0000000 --- a/tests/test-debug-wttrin-disable.el +++ /dev/null @@ -1,43 +0,0 @@ -;;; 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 deleted file mode 100644 index 569547d..0000000 --- a/tests/test-debug-wttrin-enable.el +++ /dev/null @@ -1,43 +0,0 @@ -;;; 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 deleted file mode 100644 index 437185a..0000000 --- a/tests/test-debug-wttrin-mode-line.el +++ /dev/null @@ -1,79 +0,0 @@ -;;; 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-debug-wttrin-show-raw.el b/tests/test-debug-wttrin-show-raw.el deleted file mode 100644 index 67e50ca..0000000 --- a/tests/test-debug-wttrin-show-raw.el +++ /dev/null @@ -1,121 +0,0 @@ -;;; test-debug-wttrin-show-raw.el --- Tests for debug-wttrin-show-raw -*- lexical-binding: t; -*- - -;; Copyright (C) 2025-2026 Craig Jennings - -;;; Commentary: - -;; Unit tests for debug-wttrin-show-raw function. -;; Tests that the debug display shows raw weather data with line numbers. - -;;; Code: - -(require 'ert) -(require 'wttrin) -(require 'testutil-wttrin) - -;; Load wttrin-debug for the function under test -(require 'wttrin-debug - (expand-file-name "wttrin-debug.el" - (file-name-directory (locate-library "wttrin")))) - -;;; Setup and Teardown - -(defun test-debug-wttrin-show-raw-setup () - "Setup for debug-wttrin-show-raw tests." - (testutil-wttrin-setup) - (when (get-buffer "*wttrin-debug*") - (kill-buffer "*wttrin-debug*"))) - -(defun test-debug-wttrin-show-raw-teardown () - "Teardown for debug-wttrin-show-raw tests." - (testutil-wttrin-teardown) - (when (get-buffer "*wttrin-debug*") - (kill-buffer "*wttrin-debug*"))) - -;;; Normal Cases - -(ert-deftest test-debug-wttrin-show-raw-normal-creates-debug-buffer () - "Calling show-raw should create the *wttrin-debug* buffer." - (test-debug-wttrin-show-raw-setup) - (unwind-protect - (progn - (testutil-wttrin-mock-http-response "Line one\nLine two\nLine three" - (debug-wttrin-show-raw "Paris")) - (should (get-buffer "*wttrin-debug*"))) - (test-debug-wttrin-show-raw-teardown))) - -(ert-deftest test-debug-wttrin-show-raw-normal-adds-line-numbers () - "Each line of raw data should be prefixed with its line number." - (test-debug-wttrin-show-raw-setup) - (unwind-protect - (progn - (testutil-wttrin-mock-http-response "Alpha\nBravo\nCharlie" - (debug-wttrin-show-raw "Paris")) - (with-current-buffer "*wttrin-debug*" - (let ((contents (buffer-string))) - (should (string-match-p "^ *1: Alpha" contents)) - (should (string-match-p "^ *2: Bravo" contents)) - (should (string-match-p "^ *3: Charlie" contents))))) - (test-debug-wttrin-show-raw-teardown))) - -(ert-deftest test-debug-wttrin-show-raw-normal-fetches-correct-location () - "The function should fetch weather for the specified location." - (test-debug-wttrin-show-raw-setup) - (unwind-protect - (let ((fetched-location nil)) - (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch) - (lambda (location callback) - (setq fetched-location location) - (funcall callback "data")))) - (debug-wttrin-show-raw "Berlin, DE") - (should (equal fetched-location "Berlin, DE")))) - (test-debug-wttrin-show-raw-teardown))) - -;;; Boundary Cases - -(ert-deftest test-debug-wttrin-show-raw-boundary-single-line () - "Single-line response should get line number 1." - (test-debug-wttrin-show-raw-setup) - (unwind-protect - (progn - (testutil-wttrin-mock-http-response "Just one line" - (debug-wttrin-show-raw "Paris")) - (with-current-buffer "*wttrin-debug*" - (let ((contents (buffer-string))) - (should (string-match-p "^ *1: Just one line" contents))))) - (test-debug-wttrin-show-raw-teardown))) - -;;; Error Cases - -(ert-deftest test-debug-wttrin-show-raw-error-nil-response-should-not-crash () - "When the fetch returns nil, the function should handle it gracefully." - (test-debug-wttrin-show-raw-setup) - (unwind-protect - (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch) - (lambda (_location callback) - (funcall callback nil)))) - ;; Should not crash - (debug-wttrin-show-raw "BadLocation") - ;; Buffer should exist even on error - (should (get-buffer "*wttrin-debug*"))) - (test-debug-wttrin-show-raw-teardown))) - -(ert-deftest test-debug-wttrin-show-raw-normal-always-fetches-fresh () - "A debug command should always fetch from the API, not serve cached data. -When debugging, the user needs to see what the API currently returns." - (test-debug-wttrin-show-raw-setup) - (unwind-protect - (let ((force-refresh-was-set nil)) - ;; Seed cache so there IS data to serve - (testutil-wttrin-add-to-cache "Paris" "old cached data" 300) - (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch) - (lambda (_location callback) - (setq force-refresh-was-set wttrin--force-refresh) - (funcall callback "fresh from API")))) - (debug-wttrin-show-raw "Paris") - ;; Force-refresh should have been active during the fetch - (should force-refresh-was-set))) - (test-debug-wttrin-show-raw-teardown))) - -(provide 'test-debug-wttrin-show-raw) -;;; test-debug-wttrin-show-raw.el ends here diff --git a/tests/test-wttrin-debug-aliases.el b/tests/test-wttrin-debug-aliases.el new file mode 100644 index 0000000..1e2194b --- /dev/null +++ b/tests/test-wttrin-debug-aliases.el @@ -0,0 +1,52 @@ +;;; test-wttrin-debug-aliases.el --- Tests for obsolete debug aliases -*- lexical-binding: t; -*- + +;; Copyright (C) 2026 Craig Jennings + +;;; Commentary: + +;; The four `debug-wttrin-*' names were renamed to `wttrin-debug-*' in +;; 0.4.0 to follow the package-prefix convention. The old names remain +;; as obsolete aliases so existing keybindings keep working. These tests +;; verify each alias resolves to the new function and is marked obsolete +;; with the expected target and version. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +(require 'wttrin-debug + (expand-file-name "wttrin-debug.el" + (file-name-directory (locate-library "wttrin")))) + +(defconst test-wttrin-debug-aliases-pairs + '((debug-wttrin-show-raw . wttrin-debug-show-raw) + (debug-wttrin-enable . wttrin-debug-enable) + (debug-wttrin-disable . wttrin-debug-disable) + (debug-wttrin-mode-line . wttrin-debug-mode-line)) + "Old-name to new-name pairs for the renamed debug functions.") + +;;; Normal Cases + +(ert-deftest test-wttrin-debug-aliases-normal-each-old-name-resolves-to-new () + "Every old name is fboundp and indirects to its new name." + (dolist (pair test-wttrin-debug-aliases-pairs) + (let ((old (car pair)) + (new (cdr pair))) + (should (fboundp old)) + (should (eq (indirect-function old) (symbol-function new)))))) + +(ert-deftest test-wttrin-debug-aliases-normal-each-old-name-marked-obsolete () + "Every old name has byte-obsolete-info pointing at the new name and 0.4.0." + (dolist (pair test-wttrin-debug-aliases-pairs) + (let* ((old (car pair)) + (new (cdr pair)) + (info (get old 'byte-obsolete-info))) + (should info) + ;; byte-obsolete-info is (CURRENT-NAME HANDLER WHEN) + (should (eq new (car info))) + (should (string= "0.4.0" (nth 2 info)))))) + +(provide 'test-wttrin-debug-aliases) +;;; test-wttrin-debug-aliases.el ends here diff --git a/tests/test-wttrin-debug-disable.el b/tests/test-wttrin-debug-disable.el new file mode 100644 index 0000000..f6fc5db --- /dev/null +++ b/tests/test-wttrin-debug-disable.el @@ -0,0 +1,43 @@ +;;; test-wttrin-debug-disable.el --- Tests for wttrin-debug-disable -*- lexical-binding: t; -*- + +;; Copyright (C) 2025-2026 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-debug-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-wttrin-debug-disable-normal-flips-from-t-to-nil () + "Calling disable when wttrin-debug is t sets it to nil." + (let ((wttrin-debug t)) + (wttrin-debug-disable) + (should-not wttrin-debug))) + +(ert-deftest test-wttrin-debug-disable-normal-idempotent-when-already-disabled () + "Calling disable when wttrin-debug is already nil leaves it nil." + (let ((wttrin-debug nil)) + (wttrin-debug-disable) + (should-not wttrin-debug))) + +;;; Boundary Cases + +(ert-deftest test-wttrin-debug-disable-boundary-clears-non-boolean-truthy-value () + "Calling disable replaces any truthy value with nil." + (let ((wttrin-debug 'verbose)) + (wttrin-debug-disable) + (should-not wttrin-debug))) + +(provide 'test-wttrin-debug-disable) +;;; test-wttrin-debug-disable.el ends here diff --git a/tests/test-wttrin-debug-enable.el b/tests/test-wttrin-debug-enable.el new file mode 100644 index 0000000..b5d1217 --- /dev/null +++ b/tests/test-wttrin-debug-enable.el @@ -0,0 +1,43 @@ +;;; test-wttrin-debug-enable.el --- Tests for wttrin-debug-enable -*- lexical-binding: t; -*- + +;; Copyright (C) 2025-2026 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-debug-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-wttrin-debug-enable-normal-flips-from-nil-to-t () + "Calling enable when wttrin-debug is nil sets it to t." + (let ((wttrin-debug nil)) + (wttrin-debug-enable) + (should (eq wttrin-debug t)))) + +(ert-deftest test-wttrin-debug-enable-normal-idempotent-when-already-enabled () + "Calling enable when wttrin-debug is already t leaves it t." + (let ((wttrin-debug t)) + (wttrin-debug-enable) + (should (eq wttrin-debug t)))) + +;;; Boundary Cases + +(ert-deftest test-wttrin-debug-enable-boundary-overrides-non-boolean-truthy-value () + "Calling enable replaces a non-boolean truthy value with t." + (let ((wttrin-debug 'verbose)) + (wttrin-debug-enable) + (should (eq wttrin-debug t)))) + +(provide 'test-wttrin-debug-enable) +;;; test-wttrin-debug-enable.el ends here diff --git a/tests/test-wttrin-debug-mode-line.el b/tests/test-wttrin-debug-mode-line.el new file mode 100644 index 0000000..b9e135b --- /dev/null +++ b/tests/test-wttrin-debug-mode-line.el @@ -0,0 +1,79 @@ +;;; test-wttrin-debug-mode-line.el --- Tests for wttrin-debug-mode-line -*- lexical-binding: t; -*- + +;; Copyright (C) 2025-2026 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-debug-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-wttrin-debug-mode-line-setup () + "Setup for wttrin-debug-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-wttrin-debug-mode-line-teardown () + "Teardown for wttrin-debug-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-wttrin-debug-mode-line-normal-no-buffer-skips-diagnostic-buffer () + "When the *wttr.in* buffer is absent, no diagnostic buffer is created." + (test-wttrin-debug-mode-line-setup) + (unwind-protect + (progn + (wttrin-debug-mode-line) + (should-not (get-buffer "*wttrin-mode-debug*"))) + (test-wttrin-debug-mode-line-teardown))) + +(ert-deftest test-wttrin-debug-mode-line-normal-buffer-exists-creates-diagnostic-buffer () + "When the *wttr.in* buffer exists, the diagnostic buffer is created." + (test-wttrin-debug-mode-line-setup) + (unwind-protect + (progn + (with-current-buffer (get-buffer-create "*wttr.in*") + (wttrin-mode)) + (wttrin-debug-mode-line) + (should (get-buffer "*wttrin-mode-debug*"))) + (test-wttrin-debug-mode-line-teardown))) + +(ert-deftest test-wttrin-debug-mode-line-normal-diagnostic-buffer-contains-section-labels () + "Diagnostic buffer contains the expected section labels." + (test-wttrin-debug-mode-line-setup) + (unwind-protect + (progn + (with-current-buffer (get-buffer-create "*wttr.in*") + (wttrin-mode)) + (wttrin-debug-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-wttrin-debug-mode-line-teardown))) + +(provide 'test-wttrin-debug-mode-line) +;;; test-wttrin-debug-mode-line.el ends here diff --git a/tests/test-wttrin-debug-show-raw.el b/tests/test-wttrin-debug-show-raw.el new file mode 100644 index 0000000..91a7c06 --- /dev/null +++ b/tests/test-wttrin-debug-show-raw.el @@ -0,0 +1,121 @@ +;;; test-wttrin-debug-show-raw.el --- Tests for wttrin-debug-show-raw -*- lexical-binding: t; -*- + +;; Copyright (C) 2025-2026 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-debug-show-raw function. +;; Tests that the debug display shows raw weather data with line numbers. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +;; Load wttrin-debug for the function under test +(require 'wttrin-debug + (expand-file-name "wttrin-debug.el" + (file-name-directory (locate-library "wttrin")))) + +;;; Setup and Teardown + +(defun test-wttrin-debug-show-raw-setup () + "Setup for wttrin-debug-show-raw tests." + (testutil-wttrin-setup) + (when (get-buffer "*wttrin-debug*") + (kill-buffer "*wttrin-debug*"))) + +(defun test-wttrin-debug-show-raw-teardown () + "Teardown for wttrin-debug-show-raw tests." + (testutil-wttrin-teardown) + (when (get-buffer "*wttrin-debug*") + (kill-buffer "*wttrin-debug*"))) + +;;; Normal Cases + +(ert-deftest test-wttrin-debug-show-raw-normal-creates-debug-buffer () + "Calling show-raw should create the *wttrin-debug* buffer." + (test-wttrin-debug-show-raw-setup) + (unwind-protect + (progn + (testutil-wttrin-mock-http-response "Line one\nLine two\nLine three" + (wttrin-debug-show-raw "Paris")) + (should (get-buffer "*wttrin-debug*"))) + (test-wttrin-debug-show-raw-teardown))) + +(ert-deftest test-wttrin-debug-show-raw-normal-adds-line-numbers () + "Each line of raw data should be prefixed with its line number." + (test-wttrin-debug-show-raw-setup) + (unwind-protect + (progn + (testutil-wttrin-mock-http-response "Alpha\nBravo\nCharlie" + (wttrin-debug-show-raw "Paris")) + (with-current-buffer "*wttrin-debug*" + (let ((contents (buffer-string))) + (should (string-match-p "^ *1: Alpha" contents)) + (should (string-match-p "^ *2: Bravo" contents)) + (should (string-match-p "^ *3: Charlie" contents))))) + (test-wttrin-debug-show-raw-teardown))) + +(ert-deftest test-wttrin-debug-show-raw-normal-fetches-correct-location () + "The function should fetch weather for the specified location." + (test-wttrin-debug-show-raw-setup) + (unwind-protect + (let ((fetched-location nil)) + (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch) + (lambda (location callback) + (setq fetched-location location) + (funcall callback "data")))) + (wttrin-debug-show-raw "Berlin, DE") + (should (equal fetched-location "Berlin, DE")))) + (test-wttrin-debug-show-raw-teardown))) + +;;; Boundary Cases + +(ert-deftest test-wttrin-debug-show-raw-boundary-single-line () + "Single-line response should get line number 1." + (test-wttrin-debug-show-raw-setup) + (unwind-protect + (progn + (testutil-wttrin-mock-http-response "Just one line" + (wttrin-debug-show-raw "Paris")) + (with-current-buffer "*wttrin-debug*" + (let ((contents (buffer-string))) + (should (string-match-p "^ *1: Just one line" contents))))) + (test-wttrin-debug-show-raw-teardown))) + +;;; Error Cases + +(ert-deftest test-wttrin-debug-show-raw-error-nil-response-should-not-crash () + "When the fetch returns nil, the function should handle it gracefully." + (test-wttrin-debug-show-raw-setup) + (unwind-protect + (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch) + (lambda (_location callback) + (funcall callback nil)))) + ;; Should not crash + (wttrin-debug-show-raw "BadLocation") + ;; Buffer should exist even on error + (should (get-buffer "*wttrin-debug*"))) + (test-wttrin-debug-show-raw-teardown))) + +(ert-deftest test-wttrin-debug-show-raw-normal-always-fetches-fresh () + "A debug command should always fetch from the API, not serve cached data. +When debugging, the user needs to see what the API currently returns." + (test-wttrin-debug-show-raw-setup) + (unwind-protect + (let ((force-refresh-was-set nil)) + ;; Seed cache so there IS data to serve + (testutil-wttrin-add-to-cache "Paris" "old cached data" 300) + (cl-letf (((symbol-function 'wttrin--get-cached-or-fetch) + (lambda (_location callback) + (setq force-refresh-was-set wttrin--force-refresh) + (funcall callback "fresh from API")))) + (wttrin-debug-show-raw "Paris") + ;; Force-refresh should have been active during the fetch + (should force-refresh-was-set))) + (test-wttrin-debug-show-raw-teardown))) + +(provide 'test-wttrin-debug-show-raw) +;;; test-wttrin-debug-show-raw.el ends here diff --git a/wttrin-debug.el b/wttrin-debug.el index ca378b1..e88f8ca 100644 --- a/wttrin-debug.el +++ b/wttrin-debug.el @@ -16,13 +16,16 @@ ;; (require 'wttrin) ;; ;; Available debug functions: -;; - `debug-wttrin-show-raw' - View raw weather data with line numbers -;; - `debug-wttrin-mode-line' - Diagnose mode-line lighter issues +;; - `wttrin-debug-show-raw' - View raw weather data with line numbers +;; - `wttrin-debug-mode-line' - Diagnose mode-line lighter issues ;; - `wttrin--debug-mode-line-info' - Auto-called when wttrin runs (if debug enabled) ;; ;; Interactive commands: -;; - M-x debug-wttrin-enable - Enable debug mode -;; - M-x debug-wttrin-disable - Disable debug mode +;; - M-x wttrin-debug-enable - Enable debug mode +;; - M-x wttrin-debug-disable - Disable debug mode +;; +;; Earlier versions exposed these as `debug-wttrin-*'. Those names remain +;; available as obsolete aliases and will be removed in a future release. ;; ;; When debug mode is enabled, raw weather data is automatically saved to ;; timestamped files in `temporary-file-directory' for bug reports. @@ -37,7 +40,7 @@ (declare-function wttrin--get-cached-or-fetch "wttrin") ;;;###autoload -(defun debug-wttrin-show-raw (location) +(defun wttrin-debug-show-raw (location) "Fetch and display raw wttr.in data for LOCATION with line numbers. This is useful for debugging header parsing issues. Always fetches fresh data from the API, bypassing cache." @@ -61,7 +64,7 @@ Always fetches fresh data from the API, bypassing cache." (switch-to-buffer (current-buffer))))))) ;;;###autoload -(defun debug-wttrin-enable () +(defun wttrin-debug-enable () "Enable wttrin debug mode. Raw weather data will be saved to timestamped files for bug reports." (interactive) @@ -69,14 +72,14 @@ Raw weather data will be saved to timestamped files for bug reports." (message "Wttrin debug mode enabled. Raw data will be saved to: %s" temporary-file-directory)) ;;;###autoload -(defun debug-wttrin-disable () +(defun wttrin-debug-disable () "Disable wttrin debug mode." (interactive) (setq wttrin-debug nil) (message "Wttrin debug mode disabled")) ;;;###autoload -(defun debug-wttrin-mode-line () +(defun wttrin-debug-mode-line () "Display detailed mode-line information for the wttrin buffer. This is useful for diagnosing why the mode-line lighter isn't appearing." (interactive) @@ -107,7 +110,7 @@ This is useful for diagnosing why the mode-line lighter isn't appearing." "Auto-generate mode-line diagnostic information. Called after every weather buffer display. A no-op stub in wttrin.el is overridden by this implementation when the debug module is loaded." - (debug-wttrin-mode-line)) + (wttrin-debug-mode-line)) (defvar wttrin--debug-log nil "List of debug log entries. Each entry is (timestamp . message).") @@ -143,5 +146,18 @@ Messages are stored in `wttrin--debug-log' for later review." (goto-char (point-min)) (display-buffer (current-buffer)))) +;;; Obsolete aliases for the old `debug-wttrin-*' names. +;; Kept so existing keybindings and configurations keep working; emit +;; a byte-compile / runtime obsolescence warning to nudge migration. + +(define-obsolete-function-alias 'debug-wttrin-show-raw + 'wttrin-debug-show-raw "0.4.0") +(define-obsolete-function-alias 'debug-wttrin-enable + 'wttrin-debug-enable "0.4.0") +(define-obsolete-function-alias 'debug-wttrin-disable + 'wttrin-debug-disable "0.4.0") +(define-obsolete-function-alias 'debug-wttrin-mode-line + 'wttrin-debug-mode-line "0.4.0") + (provide 'wttrin-debug) ;;; wttrin-debug.el ends here -- cgit v1.2.3