diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-04 12:26:16 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-04 12:26:16 -0500 |
| commit | ea5636c51361b86d132d647ee3548d208394878e (patch) | |
| tree | a60ab847c7324417ca7de46e73d370ba2af90d05 /tests/test-wttrin-clear-cache.el | |
| parent | b74b98f177d92d50ddbede900ba41212e07c5f63 (diff) | |
| download | emacs-wttrin-ea5636c51361b86d132d647ee3548d208394878e.tar.gz emacs-wttrin-ea5636c51361b86d132d647ee3548d208394878e.zip | |
test: add 50 tests for untested functions; fix nil crash in save-debug-data
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.
Diffstat (limited to 'tests/test-wttrin-clear-cache.el')
| -rw-r--r-- | tests/test-wttrin-clear-cache.el | 69 |
1 files changed, 69 insertions, 0 deletions
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 |
