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/test-wttrin-mode-initialization-order.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/test-wttrin-mode-initialization-order.el')
| -rw-r--r-- | tests/test-wttrin-mode-initialization-order.el | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/tests/test-wttrin-mode-initialization-order.el b/tests/test-wttrin-mode-initialization-order.el index 20adf06..5ecd4bc 100644 --- a/tests/test-wttrin-mode-initialization-order.el +++ b/tests/test-wttrin-mode-initialization-order.el @@ -18,6 +18,8 @@ (require 'wttrin) (require 'testutil-wttrin) +;;; Setup and Teardown + (defun test-wttrin-mode-init-setup () "Setup for mode initialization tests." (testutil-wttrin-setup) @@ -30,7 +32,9 @@ (when (get-buffer "*wttr.in*") (kill-buffer "*wttr.in*"))) -(ert-deftest test-wttrin-mode-initialization-order-mode-before-buffer-local-vars () +;;; Tests + +(ert-deftest test-wttrin-mode-initialization-order-normal-mode-before-buffer-local-vars-calls-mode-first () "Test that wttrin-mode is activated before setting buffer-local variables. This test verifies the fix for the color rendering bug where xterm-color--state @@ -43,45 +47,46 @@ The test strategy: 4. Verify wttrin-mode was called BEFORE any buffer-local vars were set" (test-wttrin-mode-init-setup) (unwind-protect - (let ((mode-called-at nil) - (first-setq-local-at nil) - (call-counter 0)) - - ;; Advise to track when wttrin-mode is called - (cl-letf (((symbol-function 'wttrin-mode) - (let ((orig-fn (symbol-function 'wttrin-mode))) - (lambda () - (setq mode-called-at (cl-incf call-counter)) - (funcall orig-fn)))) - - ;; Advise to track first buffer-local variable set - ((symbol-function 'set) - (let ((orig-fn (symbol-function 'set))) - (lambda (symbol value) - ;; Track xterm-color--state specifically - (when (and (eq symbol 'xterm-color--state) - (null first-setq-local-at)) - (setq first-setq-local-at (cl-incf call-counter))) - (funcall orig-fn symbol value))))) - - (wttrin--display-weather "Paris" "Test weather data") - - ;; Verify mode was called - (should mode-called-at) - ;; Verify buffer-local var was set - (should first-setq-local-at) - ;; Critical: mode must be called BEFORE buffer-local var - (should (< mode-called-at first-setq-local-at)))) + (testutil-wttrin-with-clean-weather-buffer + (let ((mode-called-at nil) + (first-setq-local-at nil) + (call-counter 0)) + + ;; Advise to track when wttrin-mode is called + (cl-letf (((symbol-function 'wttrin-mode) + (let ((orig-fn (symbol-function 'wttrin-mode))) + (lambda () + (setq mode-called-at (cl-incf call-counter)) + (funcall orig-fn)))) + + ;; Advise to track first buffer-local variable set + ((symbol-function 'set) + (let ((orig-fn (symbol-function 'set))) + (lambda (symbol value) + ;; Track xterm-color--state specifically + (when (and (eq symbol 'xterm-color--state) + (null first-setq-local-at)) + (setq first-setq-local-at (cl-incf call-counter))) + (funcall orig-fn symbol value))))) + + (wttrin--display-weather "Paris" "Test weather data") + + ;; Verify mode was called + (should mode-called-at) + ;; Verify buffer-local var was set + (should first-setq-local-at) + ;; Critical: mode must be called BEFORE buffer-local var + (should (< mode-called-at first-setq-local-at))))) (test-wttrin-mode-init-teardown))) -(ert-deftest test-wttrin-mode-initialization-order-xterm-color-state-survives () +(ert-deftest test-wttrin-mode-initialization-order-normal-xterm-color-state-survives-mode-init () "Test that xterm-color--state remains buffer-local after wttrin--display-weather. This verifies that the state isn't wiped by kill-all-local-variables." (test-wttrin-mode-init-setup) (unwind-protect - (progn + (testutil-wttrin-with-clean-weather-buffer (wttrin--display-weather "London" "Test data") (should (get-buffer "*wttr.in*")) |
