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-clear-cache.el | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/test-wttrin-clear-cache.el (limited to 'tests/test-wttrin-clear-cache.el') diff --git a/tests/test-wttrin-clear-cache.el b/tests/test-wttrin-clear-cache.el new file mode 100644 index 0000000..3404cf8 --- /dev/null +++ b/tests/test-wttrin-clear-cache.el @@ -0,0 +1,69 @@ +;;; test-wttrin-clear-cache.el --- Tests for wttrin-clear-cache -*- lexical-binding: t; -*- + +;; Copyright (C) 2025 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-clear-cache function. +;; Tests the interactive command that clears all cached weather data. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +;;; Setup and Teardown + +(defun test-wttrin-clear-cache-setup () + "Setup for clear-cache tests." + (testutil-wttrin-setup)) + +(defun test-wttrin-clear-cache-teardown () + "Teardown for clear-cache tests." + (testutil-wttrin-teardown)) + +;;; Normal Cases + +(ert-deftest test-wttrin-clear-cache-normal-empties-all-entries () + "Clearing the cache should remove all stored weather entries." + (test-wttrin-clear-cache-setup) + (unwind-protect + (progn + ;; Populate cache with several entries + (testutil-wttrin-add-to-cache "Paris" "data1") + (testutil-wttrin-add-to-cache "London" "data2") + (testutil-wttrin-add-to-cache "Tokyo" "data3") + (should (= 3 (testutil-wttrin-cache-size))) + (wttrin-clear-cache) + (should (= 0 (testutil-wttrin-cache-size)))) + (test-wttrin-clear-cache-teardown))) + +(ert-deftest test-wttrin-clear-cache-normal-shows-confirmation () + "User should be told the cache was cleared." + (test-wttrin-clear-cache-setup) + (unwind-protect + (let ((displayed-message nil)) + (cl-letf (((symbol-function 'message) + (lambda (fmt &rest args) + (setq displayed-message (apply #'format fmt args))))) + (wttrin-clear-cache) + (should displayed-message) + (should (string-match-p "cache cleared" displayed-message)))) + (test-wttrin-clear-cache-teardown))) + +;;; Boundary Cases + +(ert-deftest test-wttrin-clear-cache-boundary-already-empty () + "Clearing an already empty cache should not error." + (test-wttrin-clear-cache-setup) + (unwind-protect + (progn + (should (= 0 (testutil-wttrin-cache-size))) + ;; Should not error + (wttrin-clear-cache) + (should (= 0 (testutil-wttrin-cache-size)))) + (test-wttrin-clear-cache-teardown))) + +(provide 'test-wttrin-clear-cache) +;;; test-wttrin-clear-cache.el ends here -- cgit v1.2.3