>From f36367ad0e57819a015fd6e9a3f28f3649fdba2a Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 24 Jul 2022 05:14:24 -0700 Subject: [PATCH 1/3] Allow non-IRC line delimiter in ERC test server * test/lisp/erc/resources/erc-d/erc-d.el (erc-d-server-fqdn, erc-d--initialize-client, erc-d--log, erc-d--send, erc-d--filter, erc-d-run): Add new variable and use it. * test/lisp/erc/resources/erc-d/erc-d-tests.el (erc-d-run-direct-foreign-protocol): Add test demoing newline-only line-wise protocol. * test/lisp/erc/resources/erc-d/resources/foreign.eld: New file. --- test/lisp/erc/resources/erc-d/erc-d-tests.el | 27 +++++++++++++++++++ test/lisp/erc/resources/erc-d/erc-d.el | 16 ++++++++--- .../erc/resources/erc-d/resources/foreign.eld | 5 ++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 test/lisp/erc/resources/erc-d/resources/foreign.eld diff --git a/test/lisp/erc/resources/erc-d/erc-d-tests.el b/test/lisp/erc/resources/erc-d/erc-d-tests.el index 21005cd760..019099edcc 100644 --- a/test/lisp/erc/resources/erc-d/erc-d-tests.el +++ b/test/lisp/erc/resources/erc-d/erc-d-tests.el @@ -1343,4 +1343,31 @@ erc-d-unix-socket-direct (kill-buffer dumb-server-buffer))) (delete-file sock)))) +(ert-deftest erc-d-run-direct-foreign-protocol () + :tags '(:expensive-test) + (let* ((erc-d-line-ending "\n") + (server (erc-d-run "localhost" t "erc-d-server" 'foreign)) + (server-buffer (get-buffer "*erc-d-server*")) + (client-buffer (get-buffer-create "*erc-d-client*")) + client) + (with-current-buffer server-buffer (erc-d-t-search-for 4 "Starting")) + (setq client (make-network-process + :buffer client-buffer + :name "erc-d-client" + :family 'ipv4 + :noquery t + :coding 'binary + :service (process-contact server :service) + :host "localhost")) + (process-send-string client "ONE one\n") + (with-current-buffer client-buffer + (erc-d-t-search-for 5 "echo ONE one")) + (process-send-string client "TWO two\n") + (with-current-buffer client-buffer + (erc-d-t-search-for 2 "echo TWO two")) + (erc-d-t-wait-for 2 "server death" (not (process-live-p server))) + (when noninteractive + (kill-buffer client-buffer) + (kill-buffer server-buffer)))) + ;;; erc-d-tests.el ends here diff --git a/test/lisp/erc/resources/erc-d/erc-d.el b/test/lisp/erc/resources/erc-d/erc-d.el index ee9b6a7fec..00cc704fc6 100644 --- a/test/lisp/erc/resources/erc-d/erc-d.el +++ b/test/lisp/erc/resources/erc-d/erc-d.el @@ -136,6 +136,9 @@ erc-d-server-fqdn Possibly used by overriding handlers, like the one for PING, and/or dialog templates for the sender portion of a reply message.") +(defvar erc-d-line-ending "\r\n" + "Protocol line delimiter for sending and receiving.") + (defvar erc-d-linger-secs nil "Seconds to wait before quitting for all dialogs. For more granular control, use the provided LINGER `rx' variable (alone) @@ -249,6 +252,7 @@ erc-d--initialize-client (mat-h (copy-sequence (process-get process :dialog-match-handlers))) (fqdn (copy-sequence (process-get process :dialog-server-fqdn))) (vars (copy-sequence (process-get process :dialog-vars))) + (ending (process-get process :dialog-ending)) (dialog (make-erc-d-dialog :name name :process process :queue (make-ring 5) @@ -263,6 +267,8 @@ erc-d--initialize-client (erc-d-dialog-hunks dialog) reader) ;; Add reverse link, register client, launch (process-put process :dialog dialog) + (process-put process :ending ending) + (process-put process :ending-regexp (rx-to-string `(+ ,ending))) (push process erc-d--clients) (erc-d--command-refresh dialog nil) (erc-d--on-request process))) @@ -311,7 +317,7 @@ erc-d--log (name (erc-d-dialog-name (process-get ,process :dialog)))) (if ,outbound (erc-d--m process "-> %s:%s %s" name id ,string) - (dolist (line (split-string ,string "\r\n")) + (dolist (line (split-string ,string (process-get process :ending))) (erc-d--m process "<- %s:%s %s" name id line))))) (defun erc-d--log-process-event (server process msg) @@ -320,7 +326,7 @@ erc-d--log-process-event (defun erc-d--send (process string) "Send STRING to PROCESS peer." (erc-d--log process string 'outbound) - (process-send-string process (concat string "\r\n"))) + (process-send-string process (concat string (process-get process :ending)))) (define-inline erc-d--fuzzy-p (exchange) (inline-letevals (exchange) @@ -442,9 +448,10 @@ erc-d--filter "Handle input received from peer. PROCESS represents a client peer connection and STRING is a raw request including line delimiters." - (let ((queue (erc-d-dialog-queue (process-get process :dialog)))) + (let ((queue (erc-d-dialog-queue (process-get process :dialog))) + (delim (process-get process :ending-regexp))) (setq string (concat (process-get process :stashed-input) string)) - (while (and string (string-match (rx (+ "\r\n")) string)) + (while (and string (string-match delim string)) (let ((line (substring string 0 (match-beginning 0)))) (setq string (unless (= (match-end 0) (length string)) (substring string (match-end 0)))) @@ -940,6 +947,7 @@ erc-d-run :dialog-vars erc-d-tmpl-vars :dialog-linger-secs erc-d-linger-secs :dialog-server-fqdn erc-d-server-fqdn + :dialog-ending erc-d-line-ending :dialog-match-handlers (erc-d-u--unkeyword erc-d-match-handlers))) diff --git a/test/lisp/erc/resources/erc-d/resources/foreign.eld b/test/lisp/erc/resources/erc-d/resources/foreign.eld new file mode 100644 index 0000000000..64a5dca8b1 --- /dev/null +++ b/test/lisp/erc/resources/erc-d/resources/foreign.eld @@ -0,0 +1,5 @@ +;;; -*- mode: lisp-data -*- +((one 5 "ONE one") + (0 "echo ONE one")) +((two 5 "TWO two") + (0 "echo TWO two")) -- 2.36.1