unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "John Trammell" <johntrammell@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guile-user@gnu.org
Subject: Re: Trigger action at exit?
Date: Mon, 3 Mar 2008 16:27:09 -0600	[thread overview]
Message-ID: <68dbb6fe0803031427k66bb76e4la558b35d0db3c975@mail.gmail.com> (raw)
In-Reply-To: <87bq5v5vwp.fsf@gnu.org>

On Mon, Mar 3, 2008 at 3:40 PM, Ludovic Courtès <ludo@gnu.org> wrote:
>  No, you would want to enclose the body of your code in `catch', i.e.,
>
>   (catch 'quit
>      (lambda ()
>        ;; your code
>        ...)
>      (lambda (key . args)
>        ...))
>
>  Anyway, this isn't good, because if your code doesn't call `exit', then
>  the `quit' exception is never raised.
>
>  `dynamic-wind' provides a better solution, since the "handler" is called
>  whenever the dynamic extent of the body is left:
>
>   (dynamic-wind
>     (lambda ()
>       ;; nothing to do here
>       #t)
>     (lambda ()
>       ;; the code body
>       ;; ...
>       )
>     (lambda ()
>       ;; the "exit guard" or "handler", which gets called whenever the
>       ;; body's extent is left, including via an `exit' call
>       ))
>
>  If your code uses C code that may exit in other ways (e.g., C code that
>  calls `exit(3)' or similar), then you need an `atexit' similar to what
>  Neil described.

Thanks, this conversation is really clarifying things for me.
Unfortunately as written neither solution is really what I'm looking
for; since I haven't been too clear I'll try to explain.

Perl uses a unit testing framework written around the "Test Anything
Protocol" aka. "TAP" (see www.testanything.org).  At its simplest, TAP
consists of a header describing the number of tests to run (the
"plan"), then the results of the tests as they are run.  One option is
to tell the test framework you don't know how many tests you'll be
running, and have it display the number at the end of the run ("no
plan").  Here's some working code that generates TAP output:

(use-modules (test TAP estry))
(load-from-path "atom_p.scm")
(plan 4)
(ok (atom? 'abc))
(is (atom? 'abc) #t)
(isnt (atom? '()) #t)
(isnt (atom? '(foo)) #t)

The contents of test/TAP/estry.scm are about what you'd expect--some
local state, plus exporting the helper functions (plan, ok, is, isnt,
...) to the caller.

I'd like to be able to replace "(plan 4)" with "(no-plan)" and have
the module register some handler to be run at script exit (or object
destruction, or something else) that would check state, see we need to
output a terminal plan, and do so.  I'm not too keen on cluttering up
the script with a lot of extra code.

Alternatively, we could go OO if I can hook in a handler to the guile
object destruction process.  Is that an option?




  reply	other threads:[~2008-03-03 22:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-29 22:30 Trigger action at exit? John Trammell
2008-03-02 17:25 ` Ludovic Courtès
2008-03-03 20:44   ` Neil Jerram
2008-03-03 21:53     ` Ludovic Courtès
2008-03-03 22:17       ` Neil Jerram
2008-03-04 10:25         ` Ludovic Courtès
2008-03-04 17:03           ` John Trammell
2008-03-05 21:14           ` Neil Jerram
2008-03-03 21:22   ` John Trammell
2008-03-03 21:40     ` Ludovic Courtès
2008-03-03 22:27       ` John Trammell [this message]
2008-03-05 21:27         ` Neil Jerram

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=68dbb6fe0803031427k66bb76e4la558b35d0db3c975@mail.gmail.com \
    --to=johntrammell@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=ludo@gnu.org \
    /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).