diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-09 15:22:20 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-09 15:22:20 -0500 |
| commit | cdda0a01decb7dc61c71d830823a2ba36207306d (patch) | |
| tree | eb15d55362d5f2c273f9cc29d8156aa35c663753 /tests/test-ai-vterm--pick-buffer-candidates.el | |
| parent | 7ad613f96380319c037f367a1b6b1beda03846ca (diff) | |
| download | dotemacs-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--pick-buffer-candidates.el')
| -rw-r--r-- | tests/test-ai-vterm--pick-buffer-candidates.el | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/tests/test-ai-vterm--pick-buffer-candidates.el b/tests/test-ai-vterm--pick-buffer-candidates.el index 99ef73254..ddfd75294 100644 --- a/tests/test-ai-vterm--pick-buffer-candidates.el +++ b/tests/test-ai-vterm--pick-buffer-candidates.el @@ -16,23 +16,19 @@ (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--pbc-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--pick-buffer-candidates-empty-buffers () "Boundary: empty buffer list -> empty alist regardless of shown." - (test-ai-vterm--pbc-cleanup) + (cj/test--kill-claude-buffers) (should (null (cj/--ai-vterm-pick-buffer-candidates nil nil))) (should (null (cj/--ai-vterm-pick-buffer-candidates nil 'sentinel)))) (ert-deftest test-ai-vterm--pick-buffer-candidates-shown-nil () "Normal: shown is nil -> straight alist in input order, no marker." - (test-ai-vterm--pbc-cleanup) + (cj/test--kill-claude-buffers) (let ((b1 (get-buffer-create "claude [a]")) (b2 (get-buffer-create "claude [b]"))) (unwind-protect @@ -44,7 +40,7 @@ (ert-deftest test-ai-vterm--pick-buffer-candidates-shown-promotes-non-shown () "Normal: shown buffer sorts last with [shown] suffix; others first." - (test-ai-vterm--pbc-cleanup) + (cj/test--kill-claude-buffers) (let ((b1 (get-buffer-create "claude [a]")) (b2 (get-buffer-create "claude [b]")) (b3 (get-buffer-create "claude [c]"))) @@ -61,7 +57,7 @@ (ert-deftest test-ai-vterm--pick-buffer-candidates-shown-only-buffer () "Boundary: shown is the only entry -> single cell with [shown] marker." - (test-ai-vterm--pbc-cleanup) + (cj/test--kill-claude-buffers) (let ((b1 (get-buffer-create "claude [a]"))) (unwind-protect (let ((result (cj/--ai-vterm-pick-buffer-candidates (list b1) b1))) @@ -70,7 +66,7 @@ (ert-deftest test-ai-vterm--pick-buffer-candidates-shown-not-in-buffers () "Boundary: stale shown buffer not in list -> all cells are non-shown." - (test-ai-vterm--pbc-cleanup) + (cj/test--kill-claude-buffers) (let ((b1 (get-buffer-create "claude [a]")) (b-stale (get-buffer-create "claude [stale]"))) (unwind-protect |
