From cdda0a01decb7dc61c71d830823a2ba36207306d Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 9 May 2026 15:22:20 -0500 Subject: refactor(tests): extract shared buffer-cleanup and fake-vterm helpers Eight test files across the ai-vterm and vterm-toggle suites each shipped a small variant of the same cleanup loop: walk `buffer-list`, kill any buffer whose name starts with a given prefix. Each file also re-implemented the `(string-prefix-p ...)` check inline. One file additionally had its own fake-vterm-mode-buffer constructor for tests that needed `cj/--vterm-toggle-buffer-p` to fire. I pulled the shared logic into `tests/testutil-vterm-buffers.el`: - `cj/test--kill-buffers-matching-prefix` is the primitive. - `cj/test--kill-claude-buffers` and `cj/test--kill-test-vterm-buffers` are thin wrappers for the two prefixes that actually appear. - `cj/test--make-fake-vterm-buffer` constructs a buffer with `major-mode` set to `vterm-mode` without launching a real vterm process. Each affected test file now `(require 'testutil-vterm-buffers)` and calls the shared helpers directly. `test-vterm-toggle--buffer-filter.el` keeps a 3-line wrapper that calls both kill helpers in sequence (the only place that needs both prefixes). Net diff: -116 / +72 across 8 test files, plus ~30 lines in the new testutil. Roughly -45 lines after the abstraction is paid for. No behavior change. 80 ai-vterm tests, 15 vterm-toggle tests, 15 cj-window-geometry tests all pass. Full make test green. --- tests/test-ai-vterm--dispatch.el | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'tests/test-ai-vterm--dispatch.el') diff --git a/tests/test-ai-vterm--dispatch.el b/tests/test-ai-vterm--dispatch.el index 030b200d..8871af9a 100644 --- a/tests/test-ai-vterm--dispatch.el +++ b/tests/test-ai-vterm--dispatch.el @@ -14,13 +14,9 @@ (require 'cl-lib) (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) (require 'ai-vterm) - -(defun test-ai-vterm--dispatch-cleanup () - "Kill any leftover claude-prefixed buffers." - (dolist (b (buffer-list)) - (when (string-prefix-p "claude [" (buffer-name b)) - (kill-buffer b)))) +(require 'testutil-vterm-buffers) (ert-deftest test-ai-vterm--dispatch-window-displayed-returns-toggle-off () "Normal: displayed claude window -> (toggle-off . WIN)." @@ -32,7 +28,7 @@ (ert-deftest test-ai-vterm--dispatch-no-window-single-buffer-returns-redisplay-recent () "Normal: no displayed claude, one alive buffer -> redisplay-recent + buffer." - (test-ai-vterm--dispatch-cleanup) + (cj/test--kill-claude-buffers) (let ((b1 (get-buffer-create "claude [single]"))) (unwind-protect (cl-letf (((symbol-function 'cj/--ai-vterm-displayed-claude-window) @@ -48,7 +44,7 @@ F9 redisplays the most-recently-selected claude (head of buffer-list order) rather than opening the project picker, so the user toggles THE claude they were last using. Other claudes are reachable via M-F9." - (test-ai-vterm--dispatch-cleanup) + (cj/test--kill-claude-buffers) (let ((b1 (get-buffer-create "claude [a]")) (b2 (get-buffer-create "claude [b]"))) (unwind-protect @@ -63,7 +59,7 @@ THE claude they were last using. Other claudes are reachable via M-F9." (ert-deftest test-ai-vterm--dispatch-no-window-zero-buffers-returns-pick-project () "Boundary: no displayed claude, zero alive buffers -> pick-project." - (test-ai-vterm--dispatch-cleanup) + (cj/test--kill-claude-buffers) (cl-letf (((symbol-function 'cj/--ai-vterm-displayed-claude-window) (lambda (&optional _frame) nil)) ((symbol-function 'cj/--ai-vterm-claude-buffers) -- cgit v1.2.3