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-fetch-raw-string.el | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/test-wttrin-fetch-raw-string.el (limited to 'tests/test-wttrin-fetch-raw-string.el') diff --git a/tests/test-wttrin-fetch-raw-string.el b/tests/test-wttrin-fetch-raw-string.el new file mode 100644 index 0000000..963fd29 --- /dev/null +++ b/tests/test-wttrin-fetch-raw-string.el @@ -0,0 +1,65 @@ +;;; test-wttrin-fetch-raw-string.el --- Tests for wttrin-fetch-raw-string -*- lexical-binding: t; -*- + +;; Copyright (C) 2025 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin-fetch-raw-string function. +;; Tests the public API for fetching weather data by location query. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +;;; Setup and Teardown + +(defun test-wttrin-fetch-raw-string-setup () + "Setup for fetch-raw-string tests." + (testutil-wttrin-setup)) + +(defun test-wttrin-fetch-raw-string-teardown () + "Teardown for fetch-raw-string tests." + (testutil-wttrin-teardown)) + +;;; Normal Cases + +(ert-deftest test-wttrin-fetch-raw-string-normal-builds-correct-url () + "The fetch should use a properly constructed wttr.in URL for the query." + (test-wttrin-fetch-raw-string-setup) + (unwind-protect + (let ((fetched-url nil)) + (cl-letf (((symbol-function 'wttrin--fetch-url) + (lambda (url _callback) (setq fetched-url url)))) + (wttrin-fetch-raw-string "Paris" #'ignore) + ;; URL should contain wttr.in and the encoded location + (should (string-match-p "wttr\\.in" fetched-url)) + (should (string-match-p "Paris" fetched-url)))) + (test-wttrin-fetch-raw-string-teardown))) + +(ert-deftest test-wttrin-fetch-raw-string-normal-passes-callback-through () + "The user's callback should receive the fetched data." + (test-wttrin-fetch-raw-string-setup) + (unwind-protect + (let ((received-data nil)) + (cl-letf (((symbol-function 'wttrin--fetch-url) + (lambda (_url callback) + (funcall callback "weather response")))) + (wttrin-fetch-raw-string "Paris" + (lambda (data) (setq received-data data))) + (should (equal received-data "weather response")))) + (test-wttrin-fetch-raw-string-teardown))) + +;;; Error Cases + +(ert-deftest test-wttrin-fetch-raw-string-error-nil-query-signals-error () + "Passing nil as query should signal an error (invalid URL construction)." + (test-wttrin-fetch-raw-string-setup) + (unwind-protect + (should-error (wttrin-fetch-raw-string nil #'ignore) + :type 'error) + (test-wttrin-fetch-raw-string-teardown))) + +(provide 'test-wttrin-fetch-raw-string) +;;; test-wttrin-fetch-raw-string.el ends here -- cgit v1.2.3