[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

with-exception-handler experiment

From: Jérémy Korwin-Zmijowski
Subject: with-exception-handler experiment
Date: Tue, 8 Mar 2022 23:10:26 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0

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)])
          [() (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)
          (lambda (e)
        (list (1+ (car result)) (1+ (cadr result))))
        (lambda ()
          (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: OpenPGP_0x700F5E0CCBB2E2D1.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]