From: Artur Malabarba <bruce.connor.am@gmail.com>
To: Phillip Lord <phillip.lord@russet.org.uk>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: testing macros and fixtures
Date: Tue, 13 Oct 2015 10:16:56 +0100 [thread overview]
Message-ID: <CAAdUY-J+c4HncEKNOS0M7Fsgnmx1+LkOhYYRpSbqMEhNV3J9NA@mail.gmail.com> (raw)
In-Reply-To: <87h9lvkcxx.fsf@russet.org.uk>
[-- Attachment #1: Type: text/plain, Size: 2286 bytes --]
2015-10-12 22:13 GMT+01:00 Phillip Lord
> ERT is quite nice, but one of the things that I have found lacking is a
> nice set of predicates, for use within should.
>
> So, when I wrote test for my "lentic" package I needed some functions
> like, so that I could do things like:
>
> (should
> (test-eq-after-this
> "blah-before.txt"
> "blah-after.txt"
> (insert "hello")))
>
> which opens "blah-before.txt" runs (insert "hello") then compares the
> result with "blah-after.txt".
I think that's a pretty specific use-case. So it's best to let people write
their own macros for this.
(defmacro should-eq-after-body (file-before file-after &rest body)
`(let ((bef
(with-temp-buffer
(insert-file-contents file-before)
,@body
(buffer-string))))
(should (string= bef (with-temp-buffer
(insert-file-contents file-after)
(buffer-string))))))
> My version of this also does a diff of the
> results if the two are not equal.
This certainly seems very useful. Maybe ert should do this on *all*
multi-line string comparisons instead of doing its default
“different-strings” report (which, most of the time, just says “strings are
of different length”).
> I've noticed that "puppet-mode" has some thing similar. For instance:
> ...
>
> And julia-mode has indentation checking tests like so:
>
> ...
>
> My own experience is that these are actually quite hard to right. The
> ones in lentic have never worked quite right -- that is, when it all
> works they are fine, but restoring state after a crash doesn't always
> work. Similarly, checking that, for example, test files are not already
> open before a test is run interactively.
Yes, there are many packages that use custom-deisgned temp-buffers for
testing. In fact, most non-trivial packages do. I'd really like to see ert
offer a common interface for this. The difficulty for that is that each
package has very different needs when it comes to testing in buffers, so I
have no idea what this common interface could be.
> So, the point of my question is this; are there any good libraries
> providing this kind of fixture logic?
Don't know.
[-- Attachment #2: Type: text/html, Size: 2823 bytes --]
next prev parent reply other threads:[~2015-10-13 9:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-12 21:13 testing macros and fixtures Phillip Lord
2015-10-13 2:54 ` Kaushal Modi
2015-10-13 9:23 ` Phillip Lord
2015-10-13 9:16 ` Artur Malabarba [this message]
2015-10-13 11:34 ` Phillip Lord
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=CAAdUY-J+c4HncEKNOS0M7Fsgnmx1+LkOhYYRpSbqMEhNV3J9NA@mail.gmail.com \
--to=bruce.connor.am@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=phillip.lord@russet.org.uk \
/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.