branch: externals/hyperbole
commit 8e4d0ffb70c59fcdf4d447676113be8673282185
Author: Mats Lidell <mats.lid...@lidells.se>
Commit: GitHub <nore...@github.com>

    Use ert-with-message-capture (#739)
---
 ChangeLog                |  6 ++++++
 test/demo-tests.el       | 50 +++++++++++++++++++++++++++---------------------
 test/hactypes-tests.el   | 15 ++++++++-------
 test/hib-kbd-tests.el    |  3 +--
 test/hibtypes-tests.el   | 10 +++++-----
 test/hmouse-drv-tests.el | 11 ++++++-----
 test/hui-select-tests.el | 47 +++++++++++++++++++++++++--------------------
 test/hy-test-helpers.el  | 11 ++++-------
 test/hyrolo-tests.el     |  3 +--
 9 files changed, 85 insertions(+), 71 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4c92af5062..9ec6944e06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-06-01  Mats Lidell  <ma...@gnu.org>
+
+* test/hy-test-helpers.el (hy-test-helpers:should-last-message): Change
+    helper to work on captured messages by ert-with-message-capture. Add
+    use of ert-with-message-capture where the helper is used.
+
 2025-05-31  Mats Lidell  <ma...@gnu.org>
 
 * hyrolo.el (consult-preview-key): Defvar var from consult.
diff --git a/test/demo-tests.el b/test/demo-tests.el
index 3366971c05..0bdfc5678f 100644
--- a/test/demo-tests.el
+++ b/test/demo-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:    30-Jan-21 at 12:00:00
-;; Last-Mod:     19-May-25 at 22:53:23 by Bob Weiner
+;; Last-Mod:      2-Jun-25 at 10:39:14 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -19,6 +19,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'hib-kbd)
 (require 'hmouse-drv)
 (require 'hhist)
@@ -32,7 +33,6 @@
 (require 'hy-test-helpers "test/hy-test-helpers")
 
 (declare-function hy-test-helpers:consume-input-events "hy-test-helpers")
-(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
 (declare-function hyrolo-demo-quit "hyrolo-demo.el")
 (declare-function org-check-for-hidden "org-el")
 
@@ -211,8 +211,9 @@
   (with-temp-buffer
     (insert "<message \"%d\" (eval (+ 2 2))>")
     (goto-char 2)
-    (action-key)
-    (hy-test-helpers:should-last-message "4")))
+    (ert-with-message-capture cap
+      (action-key)
+      (hy-test-helpers:should-last-message "4" cap))))
 
 (ert-deftest demo-implicit-button-action-button-sexp-test ()
   (with-temp-buffer
@@ -224,22 +225,24 @@
                      (mapcar #'buffer-name
                              (nthcdr (- (length (buffer-list)) 3) 
(buffer-list))))>")
     (goto-char 2)
-    (action-key)
-    (let* ((bufs (reverse (buffer-list)))
-          (hsettings-buf (buffer-name (nth 0 bufs)))
-          (hactypes-buf  (buffer-name (nth 1 bufs)))
-          (hibtypes-buf  (buffer-name (nth 2 bufs))))
-      (should (and (hy-test-helpers:should-last-message "Last 3 buffers are")
-                  (string-match-p "hsettings\\.el" hsettings-buf)
-                  (string-match-p "hactypes\\.el"  hactypes-buf)
-                  (string-match-p "hibtypes\\.el"  hibtypes-buf))))))
+    (ert-with-message-capture cap
+      (action-key)
+      (let* ((bufs (reverse (buffer-list)))
+            (hsettings-buf (buffer-name (nth 0 bufs)))
+            (hactypes-buf  (buffer-name (nth 1 bufs)))
+            (hibtypes-buf  (buffer-name (nth 2 bufs))))
+        (hy-test-helpers:should-last-message "Last 3 buffers are" cap)
+        (should (and (string-search "hsettings.el" hsettings-buf)
+                    (string-search "hactypes.el"  hactypes-buf)
+                    (string-search "hibtypes.el"  hibtypes-buf)))))))
 
 (ert-deftest demo-implicit-button-action-button-display-boolean-test ()
   (with-temp-buffer
     (insert "<string-empty-p \"False\">")
     (goto-char 2)
-    (action-key)
-    (hy-test-helpers:should-last-message "Result = nil; Boolean value = 
False")))
+    (ert-with-message-capture cap
+      (action-key)
+      (hy-test-helpers:should-last-message "Result = nil; Boolean value = 
False" cap))))
 
 (ert-deftest demo-implicit-button-hash-link-test ()
   (unwind-protect
@@ -403,9 +406,10 @@
   (unwind-protect
       (let ((enable-local-variables nil))
         (hypb:display-file-with-logo "DEMO")
-        (should (hact 'kbd-key "C-h h a factorial RET"))
-        (hy-test-helpers:consume-input-events)
-        (hy-test-helpers:should-last-message "Factorial of 5 = 120"))
+        (ert-with-message-capture cap
+          (should (hact 'kbd-key "C-h h a factorial RET"))
+          (hy-test-helpers:consume-input-events)
+          (hy-test-helpers:should-last-message "Factorial of 5 = 120" cap)))
     (hy-test-helpers:kill-buffer "DEMO")))
 
 (ert-deftest demo-factorial-ebutton-test ()
@@ -415,8 +419,9 @@
         (hypb:display-file-with-logo "DEMO")
         (re-search-forward "<(factorial)>")
         (forward-char -5)
-        (action-key)
-        (hy-test-helpers:should-last-message "Factorial of 5 = 120"))
+        (ert-with-message-capture cap
+          (action-key)
+          (hy-test-helpers:should-last-message "Factorial of 5 = 120" cap)))
     (hy-test-helpers:kill-buffer "DEMO")))
 
 ;;; Fast demo
@@ -781,8 +786,9 @@ enough files with matching mode loaded."
   (with-temp-buffer
     (insert "<fill-column>")
     (goto-char 2)
-    (action-key)
-    (hy-test-helpers:should-last-message (format "fill-column = %d" 
(current-fill-column)))))
+    (ert-with-message-capture cap
+      (action-key)
+      (hy-test-helpers:should-last-message (format "fill-column = %d" 
(current-fill-column)) cap))))
 
 (ert-deftest fast-demo-display-demo-using-action-buttons ()
   "Verify the three ways show in the demo works."
diff --git a/test/hactypes-tests.el b/test/hactypes-tests.el
index 304d342039..15b7beb09b 100644
--- a/test/hactypes-tests.el
+++ b/test/hactypes-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:    30-Jan-21 at 12:00:00
-;; Last-Mod:      4-Mar-25 at 17:05:59 by Mats Lidell
+;; Last-Mod:      1-Jun-25 at 23:31:35 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -19,19 +19,20 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'el-mock)
 (require 'hactypes)
 (require 'hy-test-helpers "test/hy-test-helpers")
 
-(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
-
 (ert-deftest display-boolean-true-test ()
-  (should (actypes::display-boolean t))
-  (hy-test-helpers:should-last-message "Result = t; Boolean value = True"))
+  (ert-with-message-capture cap
+    (should (actypes::display-boolean t))
+    (hy-test-helpers:should-last-message "Result = t; Boolean value = True" 
cap)))
 
 (ert-deftest display-boolean-false-test ()
-  (should (actypes::display-boolean nil))
-    (hy-test-helpers:should-last-message "Result = nil; Boolean value = 
False"))
+  (ert-with-message-capture cap
+    (should (actypes::display-boolean nil))
+    (hy-test-helpers:should-last-message "Result = nil; Boolean value = False" 
cap)))
 
 (ert-deftest hactypes-tests--link-to-Info-index-item ()
   "Verify `actypes::link-to-Info-index-item'."
diff --git a/test/hib-kbd-tests.el b/test/hib-kbd-tests.el
index ac019f698f..d8202df1e8 100644
--- a/test/hib-kbd-tests.el
+++ b/test/hib-kbd-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:    30-Jan-21 at 12:00:00
-;; Last-Mod:     20-Jan-24 at 15:43:57 by Mats Lidell
+;; Last-Mod:      1-Jun-25 at 10:52:33 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -23,7 +23,6 @@
 (require 'hy-test-helpers "test/hy-test-helpers")
 
 (declare-function hy-test-helpers:consume-input-events "hy-test-helpers")
-(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
 
 (ert-deftest kbd-key-hy-about-test ()
   "Test if HY-ABOUT file is displayed properly from the Hyperbole menus."
diff --git a/test/hibtypes-tests.el b/test/hibtypes-tests.el
index ab2bef76ad..825c3995cc 100644
--- a/test/hibtypes-tests.el
+++ b/test/hibtypes-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:    20-Feb-21 at 23:45:00
-;; Last-Mod:     24-Apr-25 at 23:49:38 by Mats Lidell
+;; Last-Mod:      2-Jun-25 at 10:39:56 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -26,7 +26,6 @@
 (require 'hy-test-helpers "test/hy-test-helpers")
 
 (declare-function hy-test-helpers:consume-input-events "hy-test-helpers")
-(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
 
 ;; Mail address
 (ert-deftest mail-address-at-p-test ()
@@ -149,9 +148,10 @@
   (with-temp-buffer
     (insert "\"-${hyperb:dir}/test/hy-test-dependencies.el\"")
     (goto-char 2)
-    (ibtypes::pathname)
-    (hy-test-helpers:should-last-message "Loading")
-    (hy-test-helpers:should-last-message "hy-test-dependencies.el")))
+    (ert-with-message-capture cap
+      (ibtypes::pathname)
+      (hy-test-helpers:should-last-message "Loading" cap)
+      (hy-test-helpers:should-last-message "hy-test-dependencies.el" cap))))
 
 (ert-deftest ibtypes::pathname-dot-slash-in-other-folder-test ()
   "Invalid pathname that starts with ./ triggers an error when resolved."
diff --git a/test/hmouse-drv-tests.el b/test/hmouse-drv-tests.el
index 444bfb8938..59ce95446d 100644
--- a/test/hmouse-drv-tests.el
+++ b/test/hmouse-drv-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:    28-Feb-21 at 22:52:00
-;; Last-Mod:     19-May-25 at 22:53:55 by Bob Weiner
+;; Last-Mod:      1-Jun-25 at 23:31:35 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -421,10 +421,11 @@
   (with-temp-buffer
     (insert "\"-${hyperb:dir}/test/hy-test-dependencies.el\"")
     (goto-char 2)
-    (action-key)
-    (should (hattr:ibtype-is-p 'pathname))
-    (hy-test-helpers:should-last-message "Loading")
-    (hy-test-helpers:should-last-message "hy-test-dependencies.el")))
+    (ert-with-message-capture cap
+      (action-key)
+      (should (hattr:ibtype-is-p 'pathname))
+      (hy-test-helpers:should-last-message "Loading" cap)
+      (hy-test-helpers:should-last-message "hy-test-dependencies.el" cap))))
 
 (ert-deftest hbut-pathname-directory-test ()
   "Pathname with directory opens Dired."
diff --git a/test/hui-select-tests.el b/test/hui-select-tests.el
index bb3d1fa354..00abcb6495 100644
--- a/test/hui-select-tests.el
+++ b/test/hui-select-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:    14-Apr-22 at 23:45:52
-;; Last-Mod:     20-Jan-24 at 15:44:04 by Mats Lidell
+;; Last-Mod:      1-Jun-25 at 23:40:09 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -24,11 +24,10 @@
 ;;; ************************************************************************
 
 (require 'ert)
+(require 'ert-x)
 (require 'hui-select)
 (require 'hy-test-helpers "test/hy-test-helpers")
 
-(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
-
 (ert-deftest hui-select--at-delimited-thing-p ()
   "At delimited thing p returns type of thing."
   (with-temp-buffer
@@ -119,9 +118,9 @@
                      "Buffer\n\nParagraph\nline.  One word."))
 
     ;; error
-    (should-not (hui-select-thing))
-    (hy-test-helpers:should-last-message
-     "(hui-select-boundaries): ‘buffer’ is the largest selectable region")))
+    (ert-with-message-capture cap
+      (should-not (hui-select-thing))
+      (hy-test-helpers:should-last-message "(hui-select-boundaries): ‘buffer’ 
is the largest selectable region" cap))))
 
 (ert-deftest hui-select--thing-interactive-prints-type-of-match ()
   "`hui-select-thing' selects bigger sections of text when called repeatedly.
@@ -133,36 +132,42 @@ Verifies right type of match is printed when 
`hui-select-display-type' is set to
       (insert "Buffer\n\nParagraph\nline.  One word.")
       (forward-char -3)
 
-      (should (call-interactively 'hui-select-thing))
-      (hy-test-helpers:should-last-message "word")
+      (ert-with-message-capture cap
+        (should (call-interactively 'hui-select-thing))
+        (hy-test-helpers:should-last-message "word" cap))
       (should (string= (buffer-substring-no-properties (region-beginning) 
(region-end)) "word"))
 
-      (should (call-interactively 'hui-select-thing))
-      (hy-test-helpers:should-last-message "symbol")
+      (ert-with-message-capture cap
+        (should (call-interactively 'hui-select-thing))
+        (hy-test-helpers:should-last-message "symbol" cap))
       (should (string= (buffer-substring-no-properties (region-beginning) 
(region-end)) "word."))
 
-      (should (call-interactively 'hui-select-thing))
-      (hy-test-helpers:should-last-message "sentence")
+      (ert-with-message-capture cap
+        (should (call-interactively 'hui-select-thing))
+        (hy-test-helpers:should-last-message "sentence" cap))
       (should (string= (buffer-substring-no-properties (region-beginning) 
(region-end)) "One word."))
 
-      (should (call-interactively 'hui-select-thing))
-      (hy-test-helpers:should-last-message "line")
+      (ert-with-message-capture cap
+        (should (call-interactively 'hui-select-thing))
+        (hy-test-helpers:should-last-message "line" cap))
       (should (string= (buffer-substring-no-properties (region-beginning) 
(region-end))
                        "line.  One word."))
 
-      (should (call-interactively 'hui-select-thing))
-      (hy-test-helpers:should-last-message "paragraph")
+      (ert-with-message-capture cap
+        (should (call-interactively 'hui-select-thing))
+        (hy-test-helpers:should-last-message "paragraph" cap))
       (should (string= (buffer-substring-no-properties (region-beginning) 
(region-end))
                        "\nParagraph\nline.  One word."))
 
-      (should (call-interactively 'hui-select-thing))
-      (hy-test-helpers:should-last-message "Buffer")
+      (ert-with-message-capture cap
+        (should (call-interactively 'hui-select-thing))
+        (hy-test-helpers:should-last-message "buffer" cap))
       (should (string= (buffer-substring-no-properties (region-beginning) 
(region-end))
                        "Buffer\n\nParagraph\nline.  One word."))
 
-      (should-not (call-interactively 'hui-select-thing))
-      (hy-test-helpers:should-last-message
-       "(hui-select-boundaries): ‘buffer’ is the largest selectable region"))))
+      (ert-with-message-capture cap
+        (should-not (call-interactively 'hui-select-thing))
+        (hy-test-helpers:should-last-message "(hui-select-boundaries): 
‘buffer’ is the largest selectable region" cap)))))
 
 (provide 'hui-select-tests)
 ;;; hui-select-tests.el ends here
diff --git a/test/hy-test-helpers.el b/test/hy-test-helpers.el
index 13b6766cb9..5d0b78819a 100644
--- a/test/hy-test-helpers.el
+++ b/test/hy-test-helpers.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:    30-Jan-21 at 12:00:00
-;; Last-Mod:      6-Apr-25 at 19:45:02 by Mats Lidell
+;; Last-Mod:      1-Jun-25 at 23:22:27 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -34,12 +34,9 @@
     (should (= (length possible-types) 1))
     (should (equal first-type type))))
 
-(defun hy-test-helpers:should-last-message (msg)
-  "Verify last message is MSG."
-  (with-current-buffer (messages-buffer)
-    (should (save-excursion
-              (goto-char (point-max))
-              (search-backward msg (- (point-max) 350) t)))))
+(defun hy-test-helpers:should-last-message (msg captured)
+  "Verify MSG is in CAPTURED text."
+  (should (string-search msg captured)))
 
 (defun hy-test-helpers:action-key-should-call-hpath:find (str)
   "Call action-key and check that hpath:find was called with STR."
diff --git a/test/hyrolo-tests.el b/test/hyrolo-tests.el
index 58048e459e..a6b63acc0a 100644
--- a/test/hyrolo-tests.el
+++ b/test/hyrolo-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:    19-Jun-21 at 22:42:00
-;; Last-Mod:     27-May-25 at 02:28:30 by Bob Weiner
+;; Last-Mod:      1-Jun-25 at 10:16:31 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -28,7 +28,6 @@
 (require 'kotl-mode)
 
 (declare-function hy-test-helpers:consume-input-events "hy-test-helpers")
-(declare-function hy-test-helpers:should-last-message "hy-test-helpers")
 
 (ert-deftest hyrolo-add-items-at-multiple-levels ()
   "`hyrolo-add` can add items at different levels."

Reply via email to