all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Alan Mackenzie <acm@muc.de>
Cc: 47320@debbugs.gnu.org, "João Távora" <joaotavora@gmail.com>
Subject: bug#47320: Improve failure reporting in test/lisp/electrict-tests.el
Date: Tue, 23 Mar 2021 16:24:43 +0100	[thread overview]
Message-ID: <877dlx3nb8.fsf@gmx.de> (raw)
In-Reply-To: <YFn/jUc7UYnK+4Xe@ACM> (Alan Mackenzie's message of "Tue, 23 Mar 2021 14:47:41 +0000")

Alan Mackenzie <acm@muc.de> writes:

> Hello, Michael.

Hi Alan,

>> There is the explainer functionality in ert, see
>
>> (info "(ert)Defining Explanation Functions")
>
> That description is rather terse.  In fact it is incomplete - it does
> not say when the explanation function gets called, nor does it say what
> is done with any resulting explanation.

100% d'accord. The ert manual isn't as helpful as it should ...

> It looks like a explanation function needs to duplicate the test code of
> the test being explained - it seems the function has no access to the
> internal state of the test.

No, it has full access to the test via the ert machinery.

(ert-get-test SYMBOL) returns the test object which has been created via
(ert-deftest SYMBOL-NAME ...)

(ert-running-test) returns the test object of the test just running.

With that test object, you have different access functions, like
ert-test-name, ert-test-documentation, ert-test-most-recent-result; see
cl-defstruct ert-test. And there are also some other defstructs, which
give you convenience functions like ert-test-failed-p.

> I only wish to print the extra information when there is a test failure.
> Otherwise the information in electric-tests.log would be swamped by
> pointless voluminous doc strings.

The ert explainer writes only something for failed functions.

> Or am I missing something?

<shameless advertisement>I've spent hours and hours to understand these
ert functions. You might have a look on filenotify-tests.el or
tramp-tests.el, for example.</>

>> I recommend to use it, for better readability of the test code. Examples
>> are in our test files.
>
> Thanks!

If needed, I could help you in setting upt these explainers. But I must
confess, I have no idea about electrict-tests.el.

For the beginning, you might look on this:

--8<---------------cut here---------------start------------->8---
(defun test-function ()
  "The result."
  t)

(defun test-function-explainer ()
  "The explainer, a string."
  (format "%s: %s" (ert-test-name (ert-running-test)) (ert-test-documentation (ert-running-test))))

(ert-deftest first-test ()
  "Just the first test"
  (should (test-function)))

(ert-deftest second-test ()
  "Just the second test"
  (should-not (test-function)))

(put 'test-function 'ert-explainer
     'test-function-explainer)
--8<---------------cut here---------------end--------------->8---

If you run both tests, you get

--8<---------------cut here---------------start------------->8---
.F

. first-test
    Just the first test
    passed

F second-test
    Just the second test
    (ert-test-failed
     ((should-not
       (test-function))
      :form
      (test-function)
      :value t :explanation "second-test: Just the second test"))
--8<---------------cut here---------------end--------------->8---

Best regards, Michael.





  reply	other threads:[~2021-03-23 15:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 14:24 bug#47320: Improve failure reporting in test/lisp/electrict-tests.el Alan Mackenzie
2021-03-23  8:53 ` Michael Albinus
2021-03-23 14:47   ` Alan Mackenzie
2021-03-23 15:24     ` Michael Albinus [this message]
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=877dlx3nb8.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=47320@debbugs.gnu.org \
    --cc=acm@muc.de \
    --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.