As I mentioned in my previous post, the "unit" that can succeed or fail is
the "test case", and this will work:
#lang racket
(require rackunit)
(define-test-suite hw
(test-case "one" (check-equal? 1 1))
(test-case "two" (check-equal? 1 (/ 1 0)))
(test-case "three" (check-equal? 1 2)))
(foldts-test-suite
(λ (suite name before after seed) (before) seed)
(λ (suite name before after seed kid-seed) (after) (append seed kid-seed))
(λ (case name action seed)
(let ([outcome (run-test-case name action)])
(cons outcome seed)))
empty
hw)
;; Produces:
;; '(#<test-failure> #<test-error> #<test-success>)
You won't be able to catch errors from the test case in a handler -- this
is handled by rackunit, so the `with-handlers` is useless there.
Alex.
On Saturday, May 23, 2020 at 10:47:53 PM UTC+8, sk wrote:
>
> Sorry to be thinking out loud here…
>
> I thought the reason Alex might be using `foldts-test-suite` instead of
> `fold-test-results` is because the latter automatically runs each test but
> the former leaves that in programmatic control. I thought this would enable
> me to catch exceptions, thus (using Alex's really good names for the
> pieces). E.g.:
>
> (define-test-suite hw
> (check-equal? 1 1)
> (check-equal? 1 (/ 1 0))
> (check-equal? 1 2))
>
> (foldts-test-suite
> (λ (suite name before after seed) (before) seed)
> (λ (suite name before after seed kid-seed) (after) (append seed kid-seed))
> (λ (case name action seed)
> (let ([outcome (with-handlers ([exn:fail?
> (λ (e)
> (println "got here")
> (cons 'test-failed seed))])
> (run-test-case name action))])
> (cons outcome seed)))
> empty
> hw)
>
> Unfortunately, the `with-handers` does not seem to be taking effect at
> all: the runner still halts with an error. Can anyone see what I'm missing?
>
> Shriram
>
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/71d75396-8df2-4dfb-9963-f1e8d6eaee16%40googlegroups.com.