From 28b7e4cecadce207d532b8d42346c3823450a35f Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 17 Feb 2026 19:14:14 -0600 Subject: refactor: tests: standardize naming, consolidate files, and expand testutil - Expand testutil-wttrin.el with shared fixtures and macros (testutil-wttrin-with-clean-weather-buffer, testutil-wttrin-mock-http-response, sample ANSI/weather constants) - Consolidate cache tests: port unique tests from cleanup-cache-constants and cleanup-cache-refactored into cleanup-cache-if-needed, delete obsolete files - Extract startup-delay tests into dedicated file - Add setup/teardown and (require 'testutil-wttrin) to all test files - Rename all 160 tests to follow test---- convention - Rename integration test file and add detailed docstrings - Update Makefile glob to discover new integration test naming pattern Co-Authored-By: Claude Opus 4.6 --- tests/testutil-wttrin.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests/testutil-wttrin.el') diff --git a/tests/testutil-wttrin.el b/tests/testutil-wttrin.el index 0e109ad..685cc09 100644 --- a/tests/testutil-wttrin.el +++ b/tests/testutil-wttrin.el @@ -27,6 +27,25 @@ "ERROR: Unknown location; please try ~curl wttr.in/:help" "Sample error response from wttr.in service.") +(defconst testutil-wttrin-sample-ansi-response + "Weather report: Paris + +\x1b[38;5;226m \\ /\x1b[0m Partly cloudy +\x1b[38;5;226m _ /\"\"\x1b[38;5;250m.-.\x1b[0m \x1b[38;5;118m+13\x1b[0m(\x1b[38;5;082m12\x1b[0m) °C +\x1b[38;5;226m \\_\x1b[38;5;250m( ). \x1b[0m ↑ \x1b[38;5;190m12\x1b[0m km/h +" + "Sample weather data with ANSI color codes for testing rendering.") + +(defconst testutil-wttrin-sample-full-weather + "Weather for Berkeley, CA + + \\ / Clear + .-. 62 °F + ― ( ) ― ↑ 5 mph + `-' 10 mi + / \\ 0.0 in" + "Sample full weather display data for integration tests.") + ;;; Cache Testing Helpers (defun testutil-wttrin-clear-cache () @@ -65,6 +84,32 @@ `(let ((wttrin-cache-max-entries ,max-entries)) ,@body)) +;;; Buffer Management + +(defmacro testutil-wttrin-with-clean-weather-buffer (&rest body) + "Execute BODY with clean *wttr.in* buffer setup/teardown." + (declare (indent 0)) + `(progn + (when (get-buffer "*wttr.in*") + (kill-buffer "*wttr.in*")) + (unwind-protect + (progn ,@body) + (when (get-buffer "*wttr.in*") + (kill-buffer "*wttr.in*"))))) + +;;; HTTP Mock Helpers + +(defmacro testutil-wttrin-mock-http-response (response-body &rest body) + "Mock url-retrieve to return HTTP 200 with RESPONSE-BODY, execute BODY." + (declare (indent 1)) + `(cl-letf (((symbol-function 'url-retrieve) + (lambda (url callback) + (with-temp-buffer + (insert "HTTP/1.1 200 OK\n\n") + (insert ,response-body) + (funcall callback nil))))) + ,@body)) + ;;; Test Setup and Teardown (defun testutil-wttrin-setup () -- cgit v1.2.3