diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/README-DEBUG-TESTS.org | 2 | ||||
| -rw-r--r-- | tests/test-wttrin-debug-aliases.el | 52 | ||||
| -rw-r--r-- | tests/test-wttrin-debug-disable.el (renamed from tests/test-debug-wttrin-disable.el) | 20 | ||||
| -rw-r--r-- | tests/test-wttrin-debug-enable.el (renamed from tests/test-debug-wttrin-enable.el) | 20 | ||||
| -rw-r--r-- | tests/test-wttrin-debug-mode-line.el (renamed from tests/test-debug-wttrin-mode-line.el) | 40 | ||||
| -rw-r--r-- | tests/test-wttrin-debug-show-raw.el (renamed from tests/test-debug-wttrin-show-raw.el) | 64 |
6 files changed, 125 insertions, 73 deletions
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-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-debug-wttrin-disable.el b/tests/test-wttrin-debug-disable.el index dc560c3..f6fc5db 100644 --- a/tests/test-debug-wttrin-disable.el +++ b/tests/test-wttrin-debug-disable.el @@ -1,10 +1,10 @@ -;;; test-debug-wttrin-disable.el --- Tests for debug-wttrin-disable -*- lexical-binding: t; -*- +;;; test-wttrin-debug-disable.el --- Tests for wttrin-debug-disable -*- lexical-binding: t; -*- ;; Copyright (C) 2025-2026 Craig Jennings ;;; Commentary: -;; Unit tests for debug-wttrin-disable. Verifies the interactive command +;; Unit tests for wttrin-debug-disable. Verifies the interactive command ;; clears `wttrin-debug' and is idempotent when already disabled. ;;; Code: @@ -19,25 +19,25 @@ ;;; Normal Cases -(ert-deftest test-debug-wttrin-disable-normal-flips-from-t-to-nil () +(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)) - (debug-wttrin-disable) + (wttrin-debug-disable) (should-not wttrin-debug))) -(ert-deftest test-debug-wttrin-disable-normal-idempotent-when-already-disabled () +(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)) - (debug-wttrin-disable) + (wttrin-debug-disable) (should-not wttrin-debug))) ;;; Boundary Cases -(ert-deftest test-debug-wttrin-disable-boundary-clears-non-boolean-truthy-value () +(ert-deftest test-wttrin-debug-disable-boundary-clears-non-boolean-truthy-value () "Calling disable replaces any truthy value with nil." (let ((wttrin-debug 'verbose)) - (debug-wttrin-disable) + (wttrin-debug-disable) (should-not wttrin-debug))) -(provide 'test-debug-wttrin-disable) -;;; test-debug-wttrin-disable.el ends here +(provide 'test-wttrin-debug-disable) +;;; test-wttrin-debug-disable.el ends here diff --git a/tests/test-debug-wttrin-enable.el b/tests/test-wttrin-debug-enable.el index 569547d..b5d1217 100644 --- a/tests/test-debug-wttrin-enable.el +++ b/tests/test-wttrin-debug-enable.el @@ -1,10 +1,10 @@ -;;; test-debug-wttrin-enable.el --- Tests for debug-wttrin-enable -*- lexical-binding: t; -*- +;;; test-wttrin-debug-enable.el --- Tests for wttrin-debug-enable -*- lexical-binding: t; -*- ;; Copyright (C) 2025-2026 Craig Jennings ;;; Commentary: -;; Unit tests for debug-wttrin-enable. Verifies the interactive command +;; Unit tests for wttrin-debug-enable. Verifies the interactive command ;; flips `wttrin-debug' to t and is idempotent when already enabled. ;;; Code: @@ -19,25 +19,25 @@ ;;; Normal Cases -(ert-deftest test-debug-wttrin-enable-normal-flips-from-nil-to-t () +(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)) - (debug-wttrin-enable) + (wttrin-debug-enable) (should (eq wttrin-debug t)))) -(ert-deftest test-debug-wttrin-enable-normal-idempotent-when-already-enabled () +(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)) - (debug-wttrin-enable) + (wttrin-debug-enable) (should (eq wttrin-debug t)))) ;;; Boundary Cases -(ert-deftest test-debug-wttrin-enable-boundary-overrides-non-boolean-truthy-value () +(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)) - (debug-wttrin-enable) + (wttrin-debug-enable) (should (eq wttrin-debug t)))) -(provide 'test-debug-wttrin-enable) -;;; test-debug-wttrin-enable.el ends here +(provide 'test-wttrin-debug-enable) +;;; test-wttrin-debug-enable.el ends here diff --git a/tests/test-debug-wttrin-mode-line.el b/tests/test-wttrin-debug-mode-line.el index 437185a..b9e135b 100644 --- a/tests/test-debug-wttrin-mode-line.el +++ b/tests/test-wttrin-debug-mode-line.el @@ -1,10 +1,10 @@ -;;; test-debug-wttrin-mode-line.el --- Tests for debug-wttrin-mode-line -*- lexical-binding: t; -*- +;;; 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 debug-wttrin-mode-line. This function is a UI-heavy +;; 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 @@ -22,15 +22,15 @@ ;;; Setup and Teardown -(defun test-debug-wttrin-mode-line-setup () - "Setup for debug-wttrin-mode-line tests." +(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-debug-wttrin-mode-line-teardown () - "Teardown for debug-wttrin-mode-line tests." +(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*") @@ -38,34 +38,34 @@ ;;; Normal Cases -(ert-deftest test-debug-wttrin-mode-line-normal-no-buffer-skips-diagnostic-buffer () +(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-debug-wttrin-mode-line-setup) + (test-wttrin-debug-mode-line-setup) (unwind-protect (progn - (debug-wttrin-mode-line) + (wttrin-debug-mode-line) (should-not (get-buffer "*wttrin-mode-debug*"))) - (test-debug-wttrin-mode-line-teardown))) + (test-wttrin-debug-mode-line-teardown))) -(ert-deftest test-debug-wttrin-mode-line-normal-buffer-exists-creates-diagnostic-buffer () +(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-debug-wttrin-mode-line-setup) + (test-wttrin-debug-mode-line-setup) (unwind-protect (progn (with-current-buffer (get-buffer-create "*wttr.in*") (wttrin-mode)) - (debug-wttrin-mode-line) + (wttrin-debug-mode-line) (should (get-buffer "*wttrin-mode-debug*"))) - (test-debug-wttrin-mode-line-teardown))) + (test-wttrin-debug-mode-line-teardown))) -(ert-deftest test-debug-wttrin-mode-line-normal-diagnostic-buffer-contains-section-labels () +(ert-deftest test-wttrin-debug-mode-line-normal-diagnostic-buffer-contains-section-labels () "Diagnostic buffer contains the expected section labels." - (test-debug-wttrin-mode-line-setup) + (test-wttrin-debug-mode-line-setup) (unwind-protect (progn (with-current-buffer (get-buffer-create "*wttr.in*") (wttrin-mode)) - (debug-wttrin-mode-line) + (wttrin-debug-mode-line) (with-current-buffer "*wttrin-mode-debug*" (let ((contents (buffer-string))) (should (string-match-p "Wttrin Mode-Line Debug Info" contents)) @@ -73,7 +73,7 @@ (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))) + (test-wttrin-debug-mode-line-teardown))) -(provide 'test-debug-wttrin-mode-line) -;;; test-debug-wttrin-mode-line.el ends here +(provide 'test-wttrin-debug-mode-line) +;;; test-wttrin-debug-mode-line.el ends here diff --git a/tests/test-debug-wttrin-show-raw.el b/tests/test-wttrin-debug-show-raw.el index 67e50ca..91a7c06 100644 --- a/tests/test-debug-wttrin-show-raw.el +++ b/tests/test-wttrin-debug-show-raw.el @@ -1,10 +1,10 @@ -;;; test-debug-wttrin-show-raw.el --- Tests for debug-wttrin-show-raw -*- lexical-binding: t; -*- +;;; 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 debug-wttrin-show-raw function. +;; Unit tests for wttrin-debug-show-raw function. ;; Tests that the debug display shows raw weather data with line numbers. ;;; Code: @@ -20,90 +20,90 @@ ;;; Setup and Teardown -(defun test-debug-wttrin-show-raw-setup () - "Setup for debug-wttrin-show-raw tests." +(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-debug-wttrin-show-raw-teardown () - "Teardown for debug-wttrin-show-raw tests." +(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-debug-wttrin-show-raw-normal-creates-debug-buffer () +(ert-deftest test-wttrin-debug-show-raw-normal-creates-debug-buffer () "Calling show-raw should create the *wttrin-debug* buffer." - (test-debug-wttrin-show-raw-setup) + (test-wttrin-debug-show-raw-setup) (unwind-protect (progn (testutil-wttrin-mock-http-response "Line one\nLine two\nLine three" - (debug-wttrin-show-raw "Paris")) + (wttrin-debug-show-raw "Paris")) (should (get-buffer "*wttrin-debug*"))) - (test-debug-wttrin-show-raw-teardown))) + (test-wttrin-debug-show-raw-teardown))) -(ert-deftest test-debug-wttrin-show-raw-normal-adds-line-numbers () +(ert-deftest test-wttrin-debug-show-raw-normal-adds-line-numbers () "Each line of raw data should be prefixed with its line number." - (test-debug-wttrin-show-raw-setup) + (test-wttrin-debug-show-raw-setup) (unwind-protect (progn (testutil-wttrin-mock-http-response "Alpha\nBravo\nCharlie" - (debug-wttrin-show-raw "Paris")) + (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-debug-wttrin-show-raw-teardown))) + (test-wttrin-debug-show-raw-teardown))) -(ert-deftest test-debug-wttrin-show-raw-normal-fetches-correct-location () +(ert-deftest test-wttrin-debug-show-raw-normal-fetches-correct-location () "The function should fetch weather for the specified location." - (test-debug-wttrin-show-raw-setup) + (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")))) - (debug-wttrin-show-raw "Berlin, DE") + (wttrin-debug-show-raw "Berlin, DE") (should (equal fetched-location "Berlin, DE")))) - (test-debug-wttrin-show-raw-teardown))) + (test-wttrin-debug-show-raw-teardown))) ;;; Boundary Cases -(ert-deftest test-debug-wttrin-show-raw-boundary-single-line () +(ert-deftest test-wttrin-debug-show-raw-boundary-single-line () "Single-line response should get line number 1." - (test-debug-wttrin-show-raw-setup) + (test-wttrin-debug-show-raw-setup) (unwind-protect (progn (testutil-wttrin-mock-http-response "Just one line" - (debug-wttrin-show-raw "Paris")) + (wttrin-debug-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))) + (test-wttrin-debug-show-raw-teardown))) ;;; Error Cases -(ert-deftest test-debug-wttrin-show-raw-error-nil-response-should-not-crash () +(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-debug-wttrin-show-raw-setup) + (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 - (debug-wttrin-show-raw "BadLocation") + (wttrin-debug-show-raw "BadLocation") ;; Buffer should exist even on error (should (get-buffer "*wttrin-debug*"))) - (test-debug-wttrin-show-raw-teardown))) + (test-wttrin-debug-show-raw-teardown))) -(ert-deftest test-debug-wttrin-show-raw-normal-always-fetches-fresh () +(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-debug-wttrin-show-raw-setup) + (test-wttrin-debug-show-raw-setup) (unwind-protect (let ((force-refresh-was-set nil)) ;; Seed cache so there IS data to serve @@ -112,10 +112,10 @@ When debugging, the user needs to see what the API currently returns." (lambda (_location callback) (setq force-refresh-was-set wttrin--force-refresh) (funcall callback "fresh from API")))) - (debug-wttrin-show-raw "Paris") + (wttrin-debug-show-raw "Paris") ;; Force-refresh should have been active during the fetch (should force-refresh-was-set))) - (test-debug-wttrin-show-raw-teardown))) + (test-wttrin-debug-show-raw-teardown))) -(provide 'test-debug-wttrin-show-raw) -;;; test-debug-wttrin-show-raw.el ends here +(provide 'test-wttrin-debug-show-raw) +;;; test-wttrin-debug-show-raw.el ends here |
