aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-14 15:43:36 -0500
committerCraig Jennings <c@cjennings.net>2026-06-14 15:43:36 -0500
commit92c062b8b4cc70b09d5487d1cc29287ad52babdf (patch)
tree418d0b261f85c7183ae925cc171ae13ba1322282 /tests
parent808607872702075e638e5813f3c2958c100cdb6c (diff)
downloaddotemacs-92c062b8b4cc70b09d5487d1cc29287ad52babdf.tar.gz
dotemacs-92c062b8b4cc70b09d5487d1cc29287ad52babdf.zip
fix(erc): one mention notification, real server list, runtime require
Three audit defects. erc-modules carried the built-in notifications module while :config also added cj/erc-notify-on-mention to the same erc-text-matched-hook, so every mention popped two desktop notifications. Dropped notifications from erc-modules and kept the custom one. cj/erc-connected-servers compared a buffer's erc-server-process to itself inside with-current-buffer (always true), so it returned every ERC buffer; it now filters on erc-server-buffer-p and erc-server-process-alive. And user-constants moved from an eval-when-compile-only require to a runtime require, since user-whole-name is read at load time for erc-user-full-name.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-erc-config-connected-servers.el48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test-erc-config-connected-servers.el b/tests/test-erc-config-connected-servers.el
new file mode 100644
index 000000000..7d4540d68
--- /dev/null
+++ b/tests/test-erc-config-connected-servers.el
@@ -0,0 +1,48 @@
+;;; test-erc-config-connected-servers.el --- cj/erc-connected-servers -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; cj/erc-connected-servers must return only ERC *server* buffers with a live
+;; process. The original test compared a buffer's own erc-server-process to the
+;; same buffer-local value inside `with-current-buffer', which is always true, so
+;; it returned every ERC buffer (channels, queries, dead connections). These
+;; tests stub `erc-buffer-list' and the two ERC predicates so the classification
+;; is exercised without a real IRC connection.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'erc-config)
+
+(ert-deftest test-erc-connected-servers-keeps-only-live-server-buffers ()
+ "Normal: only buffers that are ERC server buffers with a live process are
+returned; a channel buffer and a dead-connection server buffer are excluded."
+ (let ((b-server (generate-new-buffer " *erc-server*"))
+ (b-channel (generate-new-buffer " *erc-#chan*"))
+ (b-dead (generate-new-buffer " *erc-dead*")))
+ (unwind-protect
+ (cl-letf (((symbol-function 'erc-buffer-list)
+ (lambda (&rest _) (list b-server b-channel b-dead)))
+ ((symbol-function 'erc-server-buffer-p)
+ (lambda (&rest _) (memq (current-buffer) (list b-server b-dead))))
+ ((symbol-function 'erc-server-process-alive)
+ (lambda (&rest _) (eq (current-buffer) b-server))))
+ (should (equal (cj/erc-connected-servers)
+ (list (buffer-name b-server)))))
+ (mapc #'kill-buffer (list b-server b-channel b-dead)))))
+
+(ert-deftest test-erc-connected-servers-empty-when-none-alive ()
+ "Boundary: no live server buffers yields an empty list."
+ (let ((b-channel (generate-new-buffer " *erc-#chan*")))
+ (unwind-protect
+ (cl-letf (((symbol-function 'erc-buffer-list)
+ (lambda (&rest _) (list b-channel)))
+ ((symbol-function 'erc-server-buffer-p) (lambda (&rest _) nil))
+ ((symbol-function 'erc-server-process-alive) (lambda (&rest _) nil)))
+ (should (null (cj/erc-connected-servers))))
+ (kill-buffer b-channel))))
+
+(provide 'test-erc-config-connected-servers)
+;;; test-erc-config-connected-servers.el ends here