From ea5636c51361b86d132d647ee3548d208394878e Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 4 Apr 2026 12:26:16 -0500 Subject: test: add 50 tests for untested functions; fix nil crash in save-debug-data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add 11 new test files covering wttrin--save-debug-data, wttrin--buffer-cache-refresh, wttrin--mode-line-stop, wttrin--mode-line-start, wttrin-query, wttrin-requery-force, wttrin-mode-line-click, wttrin-mode-line-force-refresh, wttrin-fetch-raw-string, wttrin-clear-cache, and wttrin-requery. Fix bug in wttrin--save-debug-data where nil raw-string caused (insert nil) crash — reachable when debug mode is on and fetch fails. Refactor wttrin-requery: extract wttrin--requery-location so the core kill-buffer-and-query logic is testable without mocking completing-read. 267 tests total (was 217), all passing. --- wttrin.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'wttrin.el') diff --git a/wttrin.el b/wttrin.el index 47f4af7..0c556da 100644 --- a/wttrin.el +++ b/wttrin.el @@ -305,6 +305,12 @@ CALLBACK is called with the weather data string when ready, or nil on error." (interactive) (quit-window t)) +(defun wttrin--requery-location (new-location) + "Kill current weather buffer and query NEW-LOCATION." + (when (get-buffer "*wttr.in*") + (kill-buffer "*wttr.in*")) + (wttrin-query new-location)) + (defun wttrin-requery () "Kill buffer and requery wttrin." (interactive) @@ -312,9 +318,7 @@ CALLBACK is called with the weather data string when ready, or nil on error." "Location Name: " wttrin-default-locations nil nil (when (= (length wttrin-default-locations) 1) (car wttrin-default-locations))))) - (when (get-buffer "*wttr.in*") - (kill-buffer "*wttr.in*")) - (wttrin-query new-location))) + (wttrin--requery-location new-location))) (defvar wttrin-mode-map (let ((map (make-sparse-keymap))) @@ -347,7 +351,7 @@ Returns the path to the saved file." (insert (format "Timestamp: %s\n" (format-time-string "%Y-%m-%d %H:%M:%S"))) (insert (format "wttrin-unit-system: %s\n" wttrin-unit-system)) (insert "\n--- Raw Response ---\n\n") - (insert raw-string)) + (insert (or raw-string "(nil — no data received)"))) (when (featurep 'wttrin-debug) (wttrin--debug-log "Debug data saved to: %s" filepath)) filepath)) -- cgit v1.2.3