]> git.eshelyaron.com Git - emacs.git/commitdiff
; Make ERC test fixture more robust
authorF. Jason Park <jp@neverwas.me>
Sat, 8 Feb 2025 02:54:22 +0000 (18:54 -0800)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Feb 2025 08:44:55 +0000 (09:44 +0100)
* 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)

test/lisp/erc/erc-tests.el
test/lisp/erc/resources/erc-tests-common.el

index 9d853c0f19a10d680548c0e3d5a1bd52ea6483df..7db28ffc95252dced9a377a580f7e02fb7f0f3cf 100644 (file)
   (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,
 
 (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
index 36c5df76e2dac55f6497538e0a10d053188ed219..ed52b9decd4985f7bc1ed1c1de8f9127d0f54404 100644 (file)
@@ -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" ())