diff options
| author | Craig Jennings <c@cjennings.net> | 2026-02-17 19:14:14 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-02-17 19:14:14 -0600 |
| commit | 28b7e4cecadce207d532b8d42346c3823450a35f (patch) | |
| tree | 4d8772206e10c59762ae1e60343d4bc8dded77b5 /tests/testutil-wttrin.el | |
| parent | bf989bb594680eb2e3b69f55752353aa33cb47bb (diff) | |
| download | emacs-wttrin-28b7e4cecadce207d532b8d42346c3823450a35f.tar.gz emacs-wttrin-28b7e4cecadce207d532b8d42346c3823450a35f.zip | |
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-<module>-<category>-<scenario>-<expected-result> 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 <noreply@anthropic.com>
Diffstat (limited to 'tests/testutil-wttrin.el')
| -rw-r--r-- | tests/testutil-wttrin.el | 45 |
1 files changed, 45 insertions, 0 deletions
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 () |
