From: taylanbayirli@gmail.com (Taylan Ulrich Bayırlı/Kammer)
To: Christopher Baines <mail@cbaines.net>
Cc: "guile-user@gnu.org" <guile-user@gnu.org>
Subject: Re: Failing fast in SRFI-64 test groups
Date: Sun, 13 Aug 2017 13:35:58 +0200 [thread overview]
Message-ID: <87zib3sns1.fsf@gmail.com> (raw)
In-Reply-To: <20170812193045.48fb5670@cbaines.net> (Christopher Baines's message of "Sat, 12 Aug 2017 19:30:45 +0100")
Christopher Baines <mail@cbaines.net> writes:
> Hey,
>
> If each test in a group is effectively dependent on all the tests
> before it, then it would be useful to abort the group if any tests
> fail. I had a read through the docs, and a quick look at the code, but
> didn't spot a way of doing this (short of implementing a custom test
> runner). Is if possible to do this easily?
>
> Thanks,
>
> Chris
You could define a test runner with a custom on-test-end procedure that
throws an exception if the result was a failure, and wrap all your
test-group expressions in a corresponding exception handler, possibly
with a macro to cut some boilerplate.
(define test-group-abort 'test-group-abort)
(define my-test-runner (test-runner-simple))
(test-runner-on-test-end!
my-test-runner
(lambda (runner)
(test-on-test-end-simple runner) ;call default implementation
(when (not (test-passed? runner))
(throw test-group-abort))))
(define-syntax test-group+catch
(syntax-rules ()
((_ <name> <expr> ...)
(catch test-group-abort
(lambda ()
(test-group <name> <expr> ...))
(lambda (key)
#f)))))
;; usage example:
(test-runner-current my-test-runner)
(test-begin "foo")
(test-group+catch "bar"
(test-assert "failure" #f)
(test-assert "success" #t))
(test-end "foo")
;passed: 0
;failed: 1
If using Emacs, you can run the following elisp code to make Emacs use
correct indentation for 'test-group+catch':
(put 'test-group+catch 'scheme-indent-function 1)
Taylan
prev parent reply other threads:[~2017-08-13 11:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-12 18:30 Failing fast in SRFI-64 test groups Christopher Baines
2017-08-13 11:35 ` Taylan Ulrich Bayırlı/Kammer [this message]
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
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zib3sns1.fsf@gmail.com \
--to=taylanbayirli@gmail.com \
--cc=guile-user@gnu.org \
--cc=mail@cbaines.net \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).