summaryrefslogtreecommitdiff
path: root/tests/test-ai-vterm--reuse-existing-claude.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
commit86ffa2d522e8c9640cd067c3921886b96abc401f (patch)
treec8b4c4c8aad45cdd1041d8a9d014f843fea41c54 /tests/test-ai-vterm--reuse-existing-claude.el
parent26912d32f2ade914e19620b9f855433048ead35a (diff)
downloaddotemacs-86ffa2d522e8c9640cd067c3921886b96abc401f.tar.gz
dotemacs-86ffa2d522e8c9640cd067c3921886b96abc401f.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--reuse-existing-claude.el')
-rw-r--r--tests/test-ai-vterm--reuse-existing-claude.el16
1 files changed, 6 insertions, 10 deletions
diff --git a/tests/test-ai-vterm--reuse-existing-claude.el b/tests/test-ai-vterm--reuse-existing-claude.el
index 4668188d..195e50a2 100644
--- a/tests/test-ai-vterm--reuse-existing-claude.el
+++ b/tests/test-ai-vterm--reuse-existing-claude.el
@@ -15,17 +15,13 @@
(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--reuse-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--reuse-existing-claude-swaps-buffer-when-window-exists ()
"Normal: a claude window exists -> swap its buffer, return the window."
- (test-ai-vterm--reuse-cleanup)
+ (cj/test--kill-claude-buffers)
(save-window-excursion
(delete-other-windows)
(let ((existing (get-buffer-create "claude [existing]"))
@@ -42,7 +38,7 @@
(ert-deftest test-ai-vterm--reuse-existing-claude-returns-nil-when-no-claude-window ()
"Boundary: no claude window in frame -> nil (chain continues to next action)."
- (test-ai-vterm--reuse-cleanup)
+ (cj/test--kill-claude-buffers)
(save-window-excursion
(delete-other-windows)
(let ((new-buf (get-buffer-create "claude [no-existing]")))
@@ -52,7 +48,7 @@
(ert-deftest test-ai-vterm--reuse-existing-claude-leaves-non-claude-windows-alone ()
"Boundary: only non-claude windows in frame -> nil; other windows untouched."
- (test-ai-vterm--reuse-cleanup)
+ (cj/test--kill-claude-buffers)
(save-window-excursion
(delete-other-windows)
(let ((code-buf (get-buffer-create "*test-code-buffer*"))
@@ -76,7 +72,7 @@
This is the C-F9-from-claude regression: with claude at the bottom
and code on top, switching projects must replace the bottom window's
buffer, not the top window's."
- (test-ai-vterm--reuse-cleanup)
+ (cj/test--kill-claude-buffers)
(save-window-excursion
(delete-other-windows)
(let* ((code-buf (get-buffer-create "*test-code-top*"))