* with-exception-handler experiment
@ 2022-03-08 22:10 Jérémy Korwin-Zmijowski
2022-03-09 14:34 ` Olivier Dion via General Guile related discussions
0 siblings, 1 reply; 3+ messages in thread
From: Jérémy Korwin-Zmijowski @ 2022-03-08 22:10 UTC (permalink / raw)
To: guile-user
[-- Attachment #1.1.1: Type: text/plain, Size: 1648 bytes --]
Hello Guilers,
Hope you are all fine and safe.
In the following code, I have a test which should check if my result is
correct.
If you change the expected string value "1 run, 1 failed" the assert
procedure does not throw.
What happen ? The doc about *with-exception-handler* say things about
unwinding, dynamic environment, continuation of the error… Which I
barely understand. And here I guess I miss something.
;;;; code under test
(define runner
(let ([result '(0 0)])
(case-lambda
[() (lambda (proc) (run-and-count proc result) result)]
[(setup) (lambda (proc) (setup) (run-and-count proc result))]
[(setup teardown) (lambda (proc) (setup) (run-and-count proc
result) (teardown))])))
(define (run-and-count proc result)
(with-exception-handler
(lambda (e)
(list (1+ (car result)) (1+ (cadr result))))
(lambda ()
(proc)
(list (1+ (car result)) (cadr result)))
#:unwind? #t))
(define (summary result) (format #f "~A run, ~A failed" (car result)
(cadr result)))
;;;; tests
(import (rnrs))
(define (test-failed-result)
(let ([test-proc (lambda () (raise-exception (make-exception)))])
(define test-run (runner))
(define result (test-run test-proc))
(assert (string=? "1 run, 1 failed" (summary result)))))
(define run (runner))
(run test-failed-result)
--
Jérémy Korwin-Zmijowski
GPG: 036B 4D54 B7B4 D6C8 DA62 2746 700F 5E0C CBB2 E2D1
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 2525 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 665 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: with-exception-handler experiment
2022-03-08 22:10 with-exception-handler experiment Jérémy Korwin-Zmijowski
@ 2022-03-09 14:34 ` Olivier Dion via General Guile related discussions
2022-03-09 16:54 ` Jérémy Korwin-Zmijowski
0 siblings, 1 reply; 3+ messages in thread
From: Olivier Dion via General Guile related discussions @ 2022-03-09 14:34 UTC (permalink / raw)
To: Jérémy Korwin-Zmijowski, guile-user
On Tue, 08 Mar 2022, Jérémy Korwin-Zmijowski <jeremy@korwin-zmijowski.fr> wrote:
> Hello Guilers,
>
> Hope you are all fine and safe.
>
> In the following code, I have a test which should check if my result is
> correct.
>
> If you change the expected string value "1 run, 1 failed" the assert
> procedure does not throw.
>
> ;;;; code under test
> (define runner
> (let ([result '(0 0)])
> (case-lambda
> [() (lambda (proc) (run-and-count proc result) result)]
I'm pretty sure the problem is here. You're returning the initial
result (0 0) and thus you're ending up with 0 run, 0 failed.
Try with [() (lambda (proc) (run-and-count proc result)] like you did
for the other cases.
Regards,
old
--
Olivier Dion
Polymtl
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: with-exception-handler experiment
2022-03-09 14:34 ` Olivier Dion via General Guile related discussions
@ 2022-03-09 16:54 ` Jérémy Korwin-Zmijowski
0 siblings, 0 replies; 3+ messages in thread
From: Jérémy Korwin-Zmijowski @ 2022-03-09 16:54 UTC (permalink / raw)
To: Olivier Dion, guile-user
Oh thank you! I missed this even after reading the code dozens of times haha
Cheers!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-09 16:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 22:10 with-exception-handler experiment Jérémy Korwin-Zmijowski
2022-03-09 14:34 ` Olivier Dion via General Guile related discussions
2022-03-09 16:54 ` Jérémy Korwin-Zmijowski
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).