unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Need help with catching reader error
@ 2009-04-22 14:32 Mike Gran
  2009-04-22 14:53 ` Andreas Rottmann
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Gran @ 2009-04-22 14:32 UTC (permalink / raw)
  To: Guile Devel

Hi-

Here's a puzzle for you.

I want to write a test for the test suite to catch a lexical syntax
error, like the following non-existent named character.  But I need to
somehow introduce another layer of evaluation.  In the following, Guile
would tell me that my test script has an error and then quit, instead of
catching the error and moving on.

(use-modules (test-suite lib))

(define exception:read-error
  (cons 'read-error "^.*"))

(with-test-prefix "basic char handling"
 (pass-if-exception "non-existent named character" 
		    exception:read-error
		    #\foobar))

Thanks,

Mike Gran





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Need help with catching reader error
  2009-04-22 14:32 Need help with catching reader error Mike Gran
@ 2009-04-22 14:53 ` Andreas Rottmann
  2009-04-22 15:40   ` Mike Gran
  2009-04-22 20:15   ` Ludovic Courtès
  0 siblings, 2 replies; 4+ messages in thread
From: Andreas Rottmann @ 2009-04-22 14:53 UTC (permalink / raw)
  To: Mike Gran; +Cc: Guile Devel

Mike Gran <spk121@yahoo.com> writes:

> Hi-
>
> Here's a puzzle for you.
>
> I want to write a test for the test suite to catch a lexical syntax
> error, like the following non-existent named character.  But I need to
> somehow introduce another layer of evaluation.  In the following, Guile
> would tell me that my test script has an error and then quit, instead of
> catching the error and moving on.
>
> (use-modules (test-suite lib))
>
> (define exception:read-error
>   (cons 'read-error "^.*"))
>
> (with-test-prefix "basic char handling"
>  (pass-if-exception "non-existent named character" 
> 		    exception:read-error
> 		    #\foobar))
>
You have a syntax error in your source script, which will hence not be
able to be read and consequently not be able to be evaluated.

Use this instead of #\foobar in the source text:

(with-input-from-string "#\\foobar" read)

This way, your source has legal syntax.

--Rotty




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Need help with catching reader error
  2009-04-22 14:53 ` Andreas Rottmann
@ 2009-04-22 15:40   ` Mike Gran
  2009-04-22 20:15   ` Ludovic Courtès
  1 sibling, 0 replies; 4+ messages in thread
From: Mike Gran @ 2009-04-22 15:40 UTC (permalink / raw)
  To: Andreas Rottmann; +Cc: Guile Devel

On Wed, 2009-04-22 at 16:53 +0200, Andreas Rottmann wrote:
> Mike Gran <spk121@yahoo.com> writes:
> > (with-test-prefix "basic char handling"
> >  (pass-if-exception "non-existent named character" 
> > 		    exception:read-error
> > 		    #\foobar))
> >
> You have a syntax error in your source script, which will hence not be
> able to be read and consequently not be able to be evaluated.
> 
> Use this instead of #\foobar in the source text:
> 
> (with-input-from-string "#\\foobar" read)
> 
> This way, your source has legal syntax.

> --Rotty

Nice.  It works great.  Thanks.

-Mike Gran





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Need help with catching reader error
  2009-04-22 14:53 ` Andreas Rottmann
  2009-04-22 15:40   ` Mike Gran
@ 2009-04-22 20:15   ` Ludovic Courtès
  1 sibling, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2009-04-22 20:15 UTC (permalink / raw)
  To: guile-devel

Hi,

Andreas Rottmann <a.rottmann@gmx.at> writes:

> Use this instead of #\foobar in the source text:
>
> (with-input-from-string "#\\foobar" read)
>
> This way, your source has legal syntax.

Yes, there are other examples of this in `readers.test'.

Thanks,
Ludo'.






^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-04-22 20:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-22 14:32 Need help with catching reader error Mike Gran
2009-04-22 14:53 ` Andreas Rottmann
2009-04-22 15:40   ` Mike Gran
2009-04-22 20:15   ` Ludovic Courtès

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).