From 01e7178917743470d05a5b1a5d883d07191e3014 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sat, 25 Nov 2023 19:23:55 -0800 Subject: [PATCH] ; Fix erc--channel-modes test on graphical displays * lisp/erc/erc-fill.el (erc-fill--wrap-insert-merged-post): Use correct variable. * test/lisp/erc/erc-scenarios-display-message.el: Mute unrelated noisy test. * test/lisp/erc/erc-tests.el (erc--channel-modes): Bail out following first group of assertions when running on a graphical display. (erc--channel-modes/graphic-p): New test asserting different values for graphical terminals. Note that this too is tagged as :unstable. See also: d2ce30afdd2 "; Mark test for erc--update-channel-modes as :unstable". --- lisp/erc/erc-fill.el | 2 +- .../lisp/erc/erc-scenarios-display-message.el | 3 +- test/lisp/erc/erc-tests.el | 47 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/lisp/erc/erc-fill.el b/lisp/erc/erc-fill.el index fc572666461..82e881cb71c 100644 --- a/lisp/erc/erc-fill.el +++ b/lisp/erc/erc-fill.el @@ -642,7 +642,7 @@ to be disabled." (defun erc-fill--wrap-insert-merged-pre () "Add `display' property in lieu of speaker." - (if erc-fill--wrap-merge-indicator-post + (if erc-fill--wrap-merge-indicator-pre (progn (put-text-property (point-min) (point) 'display (car erc-fill--wrap-merge-indicator-pre)) diff --git a/test/lisp/erc/erc-scenarios-display-message.el b/test/lisp/erc/erc-scenarios-display-message.el index 5751a32212d..c7e0c2fc17a 100644 --- a/test/lisp/erc/erc-scenarios-display-message.el +++ b/test/lisp/erc/erc-scenarios-display-message.el @@ -57,6 +57,7 @@ (funcall expect 10 "*** dummy (~u@rdjcgiwfuwqmc.irc) has quit") (should (eq 'QUIT (get-text-property (match-beginning 0) 'erc-msg))))) - (erc-cmd-QUIT ""))) + (with-current-buffer "foonet" + (erc-cmd-QUIT "")))) ;;; erc-scenarios-display-message.el ends here diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 1d0eb70578a..0d6ddf12380 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -829,15 +829,25 @@ (should (equal (erc--channel-modes) '((?k . "h2") (?l . "3") (?t)))) (should (equal (erc--channel-modes 3 ",") "klt h2,3")) + ;; The function this tests behaves differently in different + ;; environments. For example, on one GNU Linux system, it returns + ;; truncation ellipsis when run interactively. Rather than have + ;; hard-to-read "nondeterministic" comparisons against sets of + ;; acceptable values, we use separate tests. + (when (display-graphic-p) (ert-pass)) + ;; Truncation cache populated and used. (let ((cache (erc--channel-mode-types-shortargs erc--channel-mode-types)) first-run) (should (zerop (hash-table-count cache))) (should (equal (erc--channel-modes 1 ",") "klt h,3")) (should (equal (setq first-run (map-pairs cache)) '(((1 ?k "h2") . "h")))) + + ;; Second call uses cache. (cl-letf (((symbol-function 'truncate-string-to-width) (lambda (&rest _) (ert-fail "Shouldn't run")))) (should (equal (erc--channel-modes 1 ",") "klt h,3"))) + ;; Same key for only entry matches that of first result. (should (pcase (map-pairs cache) ((and '(((1 ?k "h2") . "h")) second-run) @@ -849,6 +859,43 @@ (should (equal (erc--channel-modes 1) "klt h 3")) (should (equal (erc--channel-modes 0) "klt "))) ; 2 spaces +(ert-deftest erc--channel-modes/graphic-p () + :tags '(:unstable) + (unless (display-graphic-p) (ert-skip "See non-/graphic-p variant")) + + (erc-tests--set-fake-server-process "sleep" "1") + (setq erc--isupport-params (make-hash-table) + erc--target (erc--target-from-string "#test") + erc-server-parameters + '(("CHANMODES" . "eIbq,k,flj,CFLMPQRSTcgimnprstuz"))) + + (cl-letf (((symbol-function 'erc-update-mode-line) #'ignore)) + (erc--update-channel-modes "+bltk" "fool!*@*" "3" "hun2")) + + ;; Truncation cache populated and used. + (let ((cache (erc--channel-mode-types-shortargs erc--channel-mode-types)) + first-run) + (should (zerop (hash-table-count cache))) + (should (equal (erc--channel-modes 2 ",") "klt h…,3" )) + (should (equal (setq first-run (map-pairs cache)) + '(((2 ?k "hun2") . "h…")))) + + ;; Second call uses cache. + (cl-letf (((symbol-function 'truncate-string-to-width) + (lambda (&rest _) (ert-fail "Shouldn't run")))) + (should (equal (erc--channel-modes 2 ",") "klt h…,3" ))) + + ;; Same key for only entry matches that of first result. + (should (pcase (map-pairs cache) + ((and `(((2 ?k "hun2") . "h…")) second-run) + (eq (pcase first-run (`((,k . ,_)) k)) + (pcase second-run (`((,k . ,_)) k))))))) + + ;; A max length of 0 is nonsensical anyway, so skip those. + (should (equal (erc--channel-modes 3) "klt hu… 3")) + (should (equal (erc--channel-modes 2) "klt h… 3")) + (should (equal (erc--channel-modes 1) "klt … 3"))) + (ert-deftest erc--update-user-modes () (let ((erc--user-modes (list ?a))) (should (equal (erc--update-user-modes "+a") '(?a))) -- 2.39.5