diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-05 05:20:44 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-05 05:20:44 -0500 |
| commit | 35131cb72c08c657d2a3389338d0c049d57e69bd (patch) | |
| tree | ad377579abb8bc143dd57c9a4f63fa244d137a94 /tests/test-wttrin-debug-show-raw.el | |
| parent | 306c4ea1dd07de0d862c0943aeb8b7e170a1b343 (diff) | |
| download | emacs-wttrin-35131cb72c08c657d2a3389338d0c049d57e69bd.tar.gz emacs-wttrin-35131cb72c08c657d2a3389338d0c049d57e69bd.zip | |
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.
Diffstat (limited to 'tests/test-wttrin-debug-show-raw.el')
| -rw-r--r-- | tests/test-wttrin-debug-show-raw.el | 121 |
1 files changed, 121 insertions, 0 deletions
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 |
