all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: 47320@debbugs.gnu.org
Cc: "João Távora" <joaotavora@gmail.com>
Subject: bug#47320: Improve failure reporting in test/lisp/electrict-tests.el
Date: Mon, 22 Mar 2021 14:24:37 +0000	[thread overview]
Message-ID: <YFiopbYeT8r3o4d3@ACM> (raw)

Hello, Emacs.

When running make check, and a failure occurs in electric-tests.elc, the
resulting output in electric-tests.log is frustratingly cryptic.
Although one can fairly easily get back to the source code for the test
in electric-tests.el, it is difficult to reconstruct the snippet of text
on which the test was performed.  This is because the tests are
(necessarily) generated by fairly inscrutable macros.

This is a shame, since each generated test has its own exceptionally
clear generated doc-string.  An example of such a doc string is:

#########################################################################
Electricity test in a `c-mode' buffer.

Start with point at 7 in a 7-char-long buffer
like this one:

  |"foo \"|   (buffer start and end are denoted by `|')

Now call this:

#'electric-quote-local-mode

Ensure the following bindings:

'((electric-quote-replace-double . t)
  (electric-quote-comment . t)
  (electric-quote-string . t))

Now press the key for: "

The buffer's contents should become:

  |"foo \""|

, and point should be at 7.
#########################################################################

My proposal is that on a test failure, this generated doc-string should
be output along with the other failure stuff.  It doesn't actually add
all that much bulk to the .log file.

Here is patch which does this.  If there are no objections, I will
commit it in a day or two.



diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index 62a42b7fe4..44b3d8b672 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -50,7 +50,8 @@ save-electric-modes
   `(call-with-saved-electric-modes #'(lambda () ,@body)))
 
 (defun electric-pair-test-for (fixture where char expected-string
-                                       expected-point mode bindings fixture-fn)
+                                       expected-point mode bindings
+                                       fixture-fn &optional doc-string)
   (with-temp-buffer
     (funcall mode)
     (insert fixture)
@@ -63,6 +64,14 @@ electric-pair-test-for
             (mapcar #'car bindings)
             (mapcar #'cdr bindings)
           (call-interactively (key-binding `[,last-command-event])))))
+    (when
+        (and doc-string
+             (not
+              (and
+               (equal (buffer-substring-no-properties (point-min) (point-max))
+                      expected-string)
+               (equal (point) expected-point))))
+      (message "\n%s\n" doc-string))
     (should (equal (buffer-substring-no-properties (point-min) (point-max))
                    expected-string))
     (should (equal (point)
@@ -109,14 +118,9 @@ electric-pair-test-for
            (fixture (format "%s%s%s" prefix fixture suffix))
            (expected-string (format "%s%s%s" prefix expected-string suffix))
            (expected-point (+ (length prefix) expected-point))
-           (pos (+ (length prefix) pos)))
-      `(ert-deftest ,(intern (format "electric-pair-%s-at-point-%s-in-%s%s"
-                                     name
-                                     (1+ pos)
-                                     mode
-                                     extra-desc))
-           ()
-         ,(format "Electricity test in a `%s' buffer.\n
+           (pos (+ (length prefix) pos))
+           (doc-string
+            (format "Electricity test in a `%s' buffer.\n
 Start with point at %d in a %d-char-long buffer
 like this one:
 
@@ -143,7 +147,14 @@ electric-pair-test-for
                   char
                   (if (string= fixture expected-string) "stay" "become")
                   (replace-regexp-in-string "\n" "\\\\n" expected-string)
-                  expected-point)
+                  expected-point)))
+      `(ert-deftest ,(intern (format "electric-pair-%s-at-point-%s-in-%s%s"
+                                     name
+                                     (1+ pos)
+                                     mode
+                                     extra-desc))
+           ()
+         ,doc-string
          (electric-pair-test-for ,fixture
                                  ,(1+ pos)
                                  ,char
@@ -151,7 +162,8 @@ electric-pair-test-for
                                  ,expected-point
                                  ',mode
                                  ,bindings
-                                 ,fixture-fn)))))
+                                 ,fixture-fn
+                                 ,doc-string)))))
 
 (cl-defmacro define-electric-pair-test
     (name fixture


-- 
Alan Mackenzie (Nuremberg, Germany).





             reply	other threads:[~2021-03-22 14:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 14:24 Alan Mackenzie [this message]
2021-03-23  8:53 ` bug#47320: Improve failure reporting in test/lisp/electrict-tests.el Michael Albinus
2021-03-23 14:47   ` Alan Mackenzie
2021-03-23 15:24     ` Michael Albinus
2021-03-23 15:59       ` João Távora
2021-03-24 13:46         ` Alan Mackenzie
2021-03-24 14:02           ` João Távora
2021-03-24 19:42             ` Alan Mackenzie
2021-03-24 20:10               ` João Távora
2021-03-25 13:43                 ` Alan Mackenzie
2021-03-25 23:47                   ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YFiopbYeT8r3o4d3@ACM \
    --to=acm@muc.de \
    --cc=47320@debbugs.gnu.org \
    --cc=joaotavora@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.