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-mode-line-force-refresh.el | 71 ++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/test-wttrin-mode-line-force-refresh.el (limited to 'tests/test-wttrin-mode-line-force-refresh.el') diff --git a/tests/test-wttrin-mode-line-force-refresh.el b/tests/test-wttrin-mode-line-force-refresh.el new file mode 100644 index 0000000..2275cee --- /dev/null +++ b/tests/test-wttrin-mode-line-force-refresh.el @@ -0,0 +1,71 @@ +;;; test-wttrin-mode-line-force-refresh.el --- Tests for wttrin-mode-line-force-refresh -*- lexical-binding: t; -*- + +;; Copyright (C) 2025 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-mode-line-force-refresh function. +;; Tests the right-click handler that force-refreshes mode-line weather. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +;;; Setup and Teardown + +(defun test-wttrin-mode-line-force-refresh-setup () + "Setup for mode-line-force-refresh tests." + (testutil-wttrin-setup) + (setq wttrin-mode-line-string nil) + (setq wttrin--mode-line-cache nil)) + +(defun test-wttrin-mode-line-force-refresh-teardown () + "Teardown for mode-line-force-refresh tests." + (testutil-wttrin-teardown) + (setq wttrin-mode-line-string nil) + (setq wttrin--mode-line-cache nil)) + +;;; Normal Cases + +(ert-deftest test-wttrin-mode-line-force-refresh-normal-calls-fetch () + "Right-click should trigger a weather fetch." + (test-wttrin-mode-line-force-refresh-setup) + (unwind-protect + (let ((wttrin-favorite-location "Paris") + (fetch-called nil)) + (cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather) + (lambda () (setq fetch-called t)))) + (wttrin-mode-line-force-refresh) + (should fetch-called))) + (test-wttrin-mode-line-force-refresh-teardown))) + +(ert-deftest test-wttrin-mode-line-force-refresh-normal-sets-force-flag () + "The fetch should run with force-refresh bound to t to bypass cache." + (test-wttrin-mode-line-force-refresh-setup) + (unwind-protect + (let ((wttrin-favorite-location "Paris") + (force-flag-during-fetch nil)) + (cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather) + (lambda () (setq force-flag-during-fetch wttrin--force-refresh)))) + (wttrin-mode-line-force-refresh) + (should force-flag-during-fetch))) + (test-wttrin-mode-line-force-refresh-teardown))) + +;;; Boundary Cases + +(ert-deftest test-wttrin-mode-line-force-refresh-boundary-nil-location-is-noop () + "When no favorite location is set, right-click should do nothing." + (test-wttrin-mode-line-force-refresh-setup) + (unwind-protect + (let ((wttrin-favorite-location nil) + (fetch-called nil)) + (cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather) + (lambda () (setq fetch-called t)))) + (wttrin-mode-line-force-refresh) + (should-not fetch-called))) + (test-wttrin-mode-line-force-refresh-teardown))) + +(provide 'test-wttrin-mode-line-force-refresh) +;;; test-wttrin-mode-line-force-refresh.el ends here -- cgit v1.2.3