From: F. Jason Park Date: Sat, 8 Feb 2025 02:54:22 +0000 (-0800) Subject: ; Make ERC test fixture more robust X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a8b5ff4df039612aa94565ee6c530d8336917eec;p=emacs.git ; Make ERC test fixture more robust * test/lisp/erc/erc-tests.el (erc-tests--assert-printed-in-subprocess): Scan for sentinel before reading. (erc--find-mode, erc--essential-hook-ordering): Use contrived :result protocol expected by `erc-tests--assert-printed-in-subprocess'. * test/lisp/erc/resources/erc-tests-common.el (erc-tests-common-create-subprocess): Divert stderr to messages buffer. (cherry picked from commit 028913c446b8f06288f2e17be91aef701dc58ba4) --- diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 9d853c0f19a..7db28ffc952 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -3546,12 +3546,23 @@ (should (eq (erc--normalize-module-symbol 'nickserv) 'services))) (defun erc-tests--assert-printed-in-subprocess (code expected) - (let ((proc (erc-tests-common-create-subprocess code '("-batch") nil))) - (while (accept-process-output proc 10)) - (goto-char (point-min)) - (unless (equal (read (current-buffer)) expected) - (message "Expected: %S\nGot: %s" expected (buffer-string)) - (ert-fail "Mismatch")))) + "Assert result emitted to standard output from CODE matches EXPECTED. +Expect CODE to print result using `prin1' as a list beginning with the +keyword :result." + (with-current-buffer + (get-buffer-create + (concat "*" (symbol-name (ert-test-name (ert-running-test))) "*")) + (unwind-protect + (let ((proc (erc-tests-common-create-subprocess code '("-batch") nil))) + (while (accept-process-output proc 10)) + (goto-char (point-min)) + (search-forward "(:result " nil t) + (unless (equal (ignore-errors (read (current-buffer))) expected) + (ert-fail (list "Mismatch" + :expected expected + :buffer-string (buffer-string))))) + (when noninteractive + (kill-buffer))))) ;; Worrying about which library a module comes from is mostly not ;; worth the hassle so long as ERC can find its minor mode. However, @@ -3561,25 +3572,25 @@ (ert-deftest erc--find-mode () (erc-tests--assert-printed-in-subprocess - `(let ((mods (mapcar #'cadddr (cdddr (get 'erc-modules 'custom-type)))) + '(let ((mods (mapcar #'cadddr (cdddr (get 'erc-modules 'custom-type)))) moded) (setq mods (sort mods (lambda (a b) (if (zerop (random 2)) a b)))) (dolist (mod mods) (unless (keywordp mod) (push (if-let ((mode (erc--find-mode mod))) mod (list :missing mod)) moded))) - (message "%S" - (sort moded (lambda (a b) - (string< (symbol-name a) (symbol-name b)))))) + (prin1 (list :result + (sort moded (lambda (a b) + (string< (symbol-name a) (symbol-name b))))))) erc-tests--modules)) (ert-deftest erc--essential-hook-ordering () (erc-tests--assert-printed-in-subprocess '(progn (erc-update-modules) - (message "%S" - (list :erc-insert-modify-hook erc-insert-modify-hook - :erc-send-modify-hook erc-send-modify-hook))) + (prin1 (list :result + (list :erc-insert-modify-hook erc-insert-modify-hook + :erc-send-modify-hook erc-send-modify-hook)))) '( :erc-insert-modify-hook (erc-controls-highlight ; 0 erc-button-add-buttons ; 30 diff --git a/test/lisp/erc/resources/erc-tests-common.el b/test/lisp/erc/resources/erc-tests-common.el index 36c5df76e2d..ed52b9decd4 100644 --- a/test/lisp/erc/resources/erc-tests-common.el +++ b/test/lisp/erc/resources/erc-tests-common.el @@ -356,15 +356,17 @@ interspersing \"-l\" between members." (require 'erc) (cl-assert (equal erc-version ,erc-version) t) ,code)) - (proc (apply #'start-process - (symbol-name (ert-test-name (ert-running-test))) - (current-buffer) - (concat invocation-directory invocation-name) - `(,@(or init '("-Q")) - ,@switches - ,@(mapcan (lambda (f) (list "-l" f)) libs) - "-eval" ,(format "%S" prog))))) - (set-process-query-on-exit-flag proc t) + (proc (make-process + :name (symbol-name (ert-test-name (ert-running-test))) + :buffer (current-buffer) + :command `(,(concat invocation-directory invocation-name) + ,@(or init '("-Q")) + ,@switches + ,@(mapcan (lambda (f) (list "-l" f)) libs) + "-eval" ,(format "%S" prog)) + :connection-type 'pipe + :stderr (messages-buffer) + :noquery t))) proc)) (declare-function erc-track--setup "erc-track" ())