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. --- tests/test-wttrin-requery-force.el | 91 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/test-wttrin-requery-force.el (limited to 'tests/test-wttrin-requery-force.el') diff --git a/tests/test-wttrin-requery-force.el b/tests/test-wttrin-requery-force.el new file mode 100644 index 0000000..04ad40a --- /dev/null +++ b/tests/test-wttrin-requery-force.el @@ -0,0 +1,91 @@ +;;; test-wttrin-requery-force.el --- Tests for wttrin-requery-force -*- lexical-binding: t; -*- + +;; Copyright (C) 2025 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-requery-force function. +;; Tests the force-refresh behavior that bypasses cache for the current location. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +;;; Setup and Teardown + +(defun test-wttrin-requery-force-setup () + "Setup for requery-force tests." + (testutil-wttrin-setup) + (when (get-buffer "*wttr.in*") + (kill-buffer "*wttr.in*"))) + +(defun test-wttrin-requery-force-teardown () + "Teardown for requery-force tests." + (testutil-wttrin-teardown) + (when (get-buffer "*wttr.in*") + (kill-buffer "*wttr.in*"))) + +;;; Normal Cases + +(ert-deftest test-wttrin-requery-force-normal-queries-current-location () + "Force refresh should query weather for the buffer's current location." + (test-wttrin-requery-force-setup) + (unwind-protect + (let ((queried-location nil)) + (cl-letf (((symbol-function 'wttrin-query) + (lambda (location) (setq queried-location location)))) + ;; Set up a weather buffer with a known location + (with-current-buffer (get-buffer-create "*wttr.in*") + (setq-local wttrin--current-location "Berlin, DE") + (wttrin-requery-force) + (should (equal queried-location "Berlin, DE"))))) + (test-wttrin-requery-force-teardown))) + +(ert-deftest test-wttrin-requery-force-normal-sets-force-refresh-flag () + "The force-refresh flag should be true when the query executes." + (test-wttrin-requery-force-setup) + (unwind-protect + (let ((force-refresh-was-set nil)) + (cl-letf (((symbol-function 'wttrin-query) + (lambda (_location) + (setq force-refresh-was-set wttrin--force-refresh)))) + (with-current-buffer (get-buffer-create "*wttr.in*") + (setq-local wttrin--current-location "Paris") + (wttrin-requery-force) + (should force-refresh-was-set)))) + (test-wttrin-requery-force-teardown))) + +;;; Boundary Cases + +(ert-deftest test-wttrin-requery-force-boundary-no-location-shows-message () + "When no current location is set, user should be told there's nothing to refresh." + (test-wttrin-requery-force-setup) + (unwind-protect + (let ((displayed-message nil)) + (cl-letf (((symbol-function 'message) + (lambda (fmt &rest args) + (setq displayed-message (apply #'format fmt args))))) + (with-current-buffer (get-buffer-create "*wttr.in*") + ;; wttrin--current-location is nil (buffer-local default) + (wttrin-requery-force) + (should displayed-message) + (should (string-match-p "No location" displayed-message))))) + (test-wttrin-requery-force-teardown))) + +(ert-deftest test-wttrin-requery-force-boundary-force-flag-does-not-leak () + "The force-refresh flag should not persist after the requery completes." + (test-wttrin-requery-force-setup) + (unwind-protect + (progn + (cl-letf (((symbol-function 'wttrin-query) (lambda (_location) nil))) + (with-current-buffer (get-buffer-create "*wttr.in*") + (setq-local wttrin--current-location "Paris") + (wttrin-requery-force))) + ;; After the let-binding unwinds, force-refresh should be back to nil + (should-not wttrin--force-refresh)) + (test-wttrin-requery-force-teardown))) + +(provide 'test-wttrin-requery-force) +;;; test-wttrin-requery-force.el ends here -- cgit v1.2.3