PasteRack.org
Paste # 1501
2017-01-17 19:48:34

Fork as a new paste.

Paste viewed 894 times.


Embed:

  1. #lang racket
  2.  
  3. (require rackunit)
  4.  
  5. (define (check-stack->hash lst)
  6.   (for/hash ([info (in-list lst)])
  7.     (values (check-info-name info)
  8.             (check-info-value info))))
  9.  
  10. (define-check (check-exn-info? proc message info)
  11.   (define failure (with-handlers ([exn:test:check? identity])
  12.                     (parameterize ([current-check-around (λ (proc) (proc))])
  13.                       (proc))
  14.                     #f))
  15.   (unless failure
  16.     (fail-check "no exn raised"))
  17.   (define info-hash (check-stack->hash (exn:test:check-stack failure)))
  18.   (unless (equal? (exn-message failure) message)
  19.     (with-check-info (['actual (exn-message failure)]
  20.                       ['expected message])
  21.       (fail-check "message didn’t match")))
  22.   (for ([(k v) (in-hash info)])
  23.     (unless (equal? (hash-ref info-hash k (not v)) v)
  24.       (with-check-info (['info-name k]
  25.                         ['actual (hash-ref info-hash k '(not present))]
  26.                         ['expected v])
  27.         (fail-check "info didn’t match")))))
  28.  
  29. (check-exn-info? (thunk (check-equal? 'one 'two))
  30.                  "Check failure"
  31.                  (hash 'actual 'one
  32.                        'foobar 'two))

=>

--------------------

FAILURE

info-name:  foobar

actual:     (not present)

expected:   two

name:       check-exn-info?

location:   (eval 4 0 4 1)

expression: (check-exn-info? (thunk (check-equal? (quote one) (quote two))) "Check failure" (hash (quote actual) (quote one) (quote foobar) (quote two)))

info didn’t match

--------------------