aboutsummaryrefslogtreecommitdiff
path: root/tests/test-ai-vterm--displayed-claude-window.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-09 15:22:20 -0500
committerCraig Jennings <c@cjennings.net>2026-05-09 15:22:20 -0500
commitcdda0a01decb7dc61c71d830823a2ba36207306d (patch)
treeeb15d55362d5f2c273f9cc29d8156aa35c663753 /tests/test-ai-vterm--displayed-claude-window.el
parent7ad613f96380319c037f367a1b6b1beda03846ca (diff)
downloaddotemacs-cdda0a01decb7dc61c71d830823a2ba36207306d.tar.gz
dotemacs-cdda0a01decb7dc61c71d830823a2ba36207306d.zip
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.
Diffstat (limited to 'tests/test-ai-vterm--displayed-claude-window.el')
-rw-r--r--tests/test-ai-vterm--displayed-claude-window.el16
1 files changed, 6 insertions, 10 deletions
diff --git a/tests/test-ai-vterm--displayed-claude-window.el b/tests/test-ai-vterm--displayed-claude-window.el
index 283a1b3cd..9f84f87b4 100644
--- a/tests/test-ai-vterm--displayed-claude-window.el
+++ b/tests/test-ai-vterm--displayed-claude-window.el
@@ -10,24 +10,20 @@
(require 'ert)
(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--displayed-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--displayed-claude-window-no-buffers-returns-nil ()
"Boundary: no claude buffers anywhere -> nil."
- (test-ai-vterm--displayed-cleanup)
+ (cj/test--kill-claude-buffers)
(save-window-excursion
(delete-other-windows)
(should-not (cj/--ai-vterm-displayed-claude-window))))
(ert-deftest test-ai-vterm--displayed-claude-window-not-displayed-returns-nil ()
"Boundary: claude buffer exists but not in any window -> nil."
- (test-ai-vterm--displayed-cleanup)
+ (cj/test--kill-claude-buffers)
(let ((b1 (get-buffer-create "claude [hidden]")))
(unwind-protect
(save-window-excursion
@@ -37,7 +33,7 @@
(ert-deftest test-ai-vterm--displayed-claude-window-returns-window-when-displayed ()
"Normal: claude buffer in a window -> returns that window."
- (test-ai-vterm--displayed-cleanup)
+ (cj/test--kill-claude-buffers)
(let ((b1 (get-buffer-create "claude [shown]")))
(unwind-protect
(save-window-excursion
@@ -51,7 +47,7 @@
(ert-deftest test-ai-vterm--displayed-claude-window-ignores-non-claude-windows ()
"Boundary: only a non-claude buffer is displayed -> nil."
- (test-ai-vterm--displayed-cleanup)
+ (cj/test--kill-claude-buffers)
(let ((other (get-buffer-create "regular-displayed-buffer")))
(unwind-protect
(save-window-excursion