aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorF. Jason Park2022-07-06 00:40:42 -0700
committerF. Jason Park2022-07-27 05:19:09 -0700
commitc238f568cddc0502feb058e651907a1baaed3149 (patch)
treea8d8a497c907b317a59ae0461c5e70da968d949a /test
parent075d6bb41089a7ea4bb5353dd70448ed5653261c (diff)
downloademacs-c238f568cddc0502feb058e651907a1baaed3149.tar.gz
emacs-c238f568cddc0502feb058e651907a1baaed3149.zip
Avoid mutating default value of erc-server-last-peers
* lisp/erc/erc-backend.el (erc-server-last-peers): Leave default as nil instead of a quoted constant. (erc-server-connect): Initialize `erc-server-last-peers' to a new value local to a server buffer. (erc-message): Operate on server's local `erc-server-last-peers' value instead of the global default. Prefer replacing value instead of mutating CDR to make for easier testing. (erc-server-PRIVMSG): Create a new `erc-server-last-peers' for easier testing. (Bug#56449)
Diffstat (limited to 'test')
-rw-r--r--test/lisp/erc/erc-tests.el82
1 files changed, 82 insertions, 0 deletions
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 4971d0e194f..0f222edacfa 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -893,4 +893,86 @@
893 893
894 (should-not calls)))))) 894 (should-not calls))))))
895 895
896;; Note: if adding an erc-backend-tests.el, please relocate this there.
897
898(ert-deftest erc-message ()
899 (should-not erc-server-last-peers)
900 (let (server-proc
901 calls
902 erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
903 (cl-letf (((symbol-function 'erc-display-message)
904 (lambda (_ _ _ line) (push line calls)))
905 ((symbol-function 'erc-server-send)
906 (lambda (line _) (push line calls)))
907 ((symbol-function 'erc-server-buffer)
908 (lambda () (process-buffer server-proc))))
909 (with-current-buffer (get-buffer-create "ExampleNet")
910 (erc-mode)
911 (setq erc-server-current-nick "tester"
912 server-proc (start-process "sleep" (current-buffer) "sleep" "1")
913 erc-server-process server-proc
914 erc-server-last-peers (cons nil nil)
915 erc-server-users (make-hash-table :test 'equal)
916 erc-network 'ExampleNet)
917 (set-process-query-on-exit-flag erc-server-process nil))
918
919 (with-current-buffer (get-buffer-create "#chan")
920 (erc-mode)
921 (setq erc-server-process (buffer-local-value 'erc-server-process
922 (get-buffer "ExampleNet"))
923 erc-default-recipients '("#chan")
924 erc-channel-users (make-hash-table :test 'equal)
925 erc-network 'ExampleNet)
926 (erc-update-current-channel-member "alice" "alice")
927 (erc-update-current-channel-member "tester" "tester"))
928
929 (with-current-buffer "ExampleNet"
930 (erc-server-PRIVMSG erc-server-process
931 (make-erc-response
932 :sender "alice!~u@fsf.org"
933 :command "PRIVMSG"
934 :command-args '("#chan" "hi")
935 :unparsed ":alice!~u@fsf.org PRIVMSG #chan :hi"))
936 (should (equal erc-server-last-peers '("alice")))
937 (should (string-match "<alice>" (pop calls))))
938
939 (with-current-buffer "#chan"
940 (ert-info ("Shortcuts usable in target buffers")
941 (should-not (local-variable-p 'erc-server-last-peers))
942 (should-not erc-server-last-peers)
943 (erc-message "PRIVMSG" ". hi")
944 (should-not erc-server-last-peers)
945 (should (eq 'no-target (pop calls)))
946 (erc-message "PRIVMSG" ", hi")
947 (should-not erc-server-last-peers)
948 (should (string-match "alice :hi" (pop calls)))))
949
950 (with-current-buffer "ExampleNet"
951 (ert-info ("Shortcuts local in server bufs")
952 (should (equal erc-server-last-peers '("alice" . "alice")))
953 (erc-message "PRIVMSG" ", hi")
954 (should (equal erc-server-last-peers '("alice" . "alice")))
955 (should (string-match "PRIVMSG alice :hi" (pop calls)))
956 (setcdr erc-server-last-peers "bob")
957 (erc-message "PRIVMSG" ". hi")
958 (should (equal erc-server-last-peers '("alice" . "bob")))
959 (should (string-match "PRIVMSG bob :hi" (pop calls)))))
960
961 (with-current-buffer "#chan"
962 (ert-info ("Non-shortcuts are local to server buffer")
963 (should-not (local-variable-p 'erc-server-last-peers))
964 (should-not erc-server-last-peers)
965 (erc-message "PRIVMSG" "#chan hola")
966 (should-not erc-server-last-peers)
967 (should-not (default-value 'erc-server-last-peers))
968 (should (equal (buffer-local-value 'erc-server-last-peers
969 (get-buffer "ExampleNet"))
970 '("alice" . "#chan")))
971 (should (string-match "hola" (pop calls))))))
972
973 (should-not erc-server-last-peers)
974 (should-not calls)
975 (kill-buffer "ExampleNet")
976 (kill-buffer "#chan")))
977
896;;; erc-tests.el ends here 978;;; erc-tests.el ends here