Install the check-info stack in continuation marks. This means that if an exception is thrown within a check some useful information about that check (e.g. name, location) can still be extracted.

svn: r15147

original commit: 7b5753163c42dbfbd70721b20f193e20d67c2129
This commit is contained in:
Noel Welsh 2009-06-11 16:22:55 +00:00
commit 2e06dce4a1
5 changed files with 74 additions and 66 deletions

View File

@ -50,5 +50,6 @@
(test-case "Also intended to fail" (check-eq? 'apples 'orange)) (test-case "Also intended to fail" (check-eq? 'apples 'orange))
(test-equal? "Yet again intended to fail" "apples" "oranges") (test-equal? "Yet again intended to fail" "apples" "oranges")
(test-case "Intended to throw error" (error 'testing "<<This is an error message>>")) (test-case "Intended to throw error" (error 'testing "<<This is an error message>>"))
(test-case "Error within a check" (check error 'foo 'bar))
)) ))

View File

@ -1,6 +1,6 @@
;;; ;;;
;;; <check-util-test.ss> ---- Tests for check-util ;;; <check-util-test.ss> ---- Tests for check-util
;;; Time-stamp: <2008-06-19 21:04:14 noel> ;;; Time-stamp: <2009-06-11 17:03:21 noel>
;;; ;;;
;;; Copyright (C) 2003 by Noel Welsh. ;;; Copyright (C) 2003 by Noel Welsh.
;;; ;;;
@ -40,7 +40,7 @@
(('1 1) (('1 1)
('2 2) ('2 2)
('3 3)) ('3 3))
(check-info-stack)))) (check-info-stack (current-continuation-marks)))))
(for-each (lambda (actual expected) (for-each (lambda (actual expected)
(check-eq? (check-info-name actual) (check-eq? (check-info-name actual)
expected)) expected))
@ -57,7 +57,7 @@
(('4 4) (('4 4)
('5 5) ('5 5)
('6 6)) ('6 6))
(check-info-stack))))) (check-info-stack (current-continuation-marks))))))
(for-each (lambda (actual expected) (for-each (lambda (actual expected)
(check-eq? (check-info-name actual) (check-eq? (check-info-name actual)
expected)) expected))

View File

@ -10,29 +10,28 @@
;; Infrastructure ---------------------------------------------- ;; Infrastructure ----------------------------------------------
;; parameter check-info-stack : (listof check-info) ;; The continuation mark under which all check-info is keyed
(define check-info-stack (define check-info-mark (gensym 'schemeunit))
(make-parameter
(list) ;; (continuation-mark-set -> (listof check-info))
(lambda (v) (define (check-info-stack marks)
(if (list? v) (apply append (continuation-mark-set->list marks check-info-mark)))
v
(raise-type-error 'check-info-stack "list" v)))))
;; with-check-info* : (list-of check-info) thunk -> any ;; with-check-info* : (list-of check-info) thunk -> any
(define (with-check-info* info thunk) (define (with-check-info* info thunk)
(parameterize (define current-marks
((check-info-stack (append (check-info-stack) info))) (continuation-mark-set-first #f check-info-mark))
(with-continuation-mark
check-info-mark
(append (if current-marks current-marks null) info)
(thunk))) (thunk)))
(define-syntax with-check-info (define-syntax with-check-info
(syntax-rules () (syntax-rules ()
((_ ((name val) ...) body ...) [(_ ((name val) ...) body ...)
(with-check-info* (with-check-info*
(list (make-check-info name val) ...) (list (make-check-info name val) ...)
(lambda () (lambda () body ...))]))
body ...)))))
(define (make-check-name name) (define (make-check-name name)
(make-check-info 'name name)) (make-check-info 'name name))

View File

@ -75,20 +75,22 @@
(define-syntax fail-check (define-syntax fail-check
(syntax-rules () (syntax-rules ()
((_) ((_)
(let ([marks (current-continuation-marks)])
(raise (raise
(make-exn:test:check (make-exn:test:check
"Check failure" "Check failure"
(current-continuation-marks) marks
(check-info-stack)))))) (check-info-stack marks)))))))
(define-syntax fail-internal (define-syntax fail-internal
(syntax-rules () (syntax-rules ()
((_) ((_)
(let ([marks (current-continuation-marks)])
(raise (raise
(make-exn:test:check:internal (make-exn:test:check:internal
"Internal failure" "Internal failure"
(current-continuation-marks) marks
(check-info-stack)))))) (check-info-stack marks)))))))
;; refail-check : exn:test:check -> (exception raised) ;; refail-check : exn:test:check -> (exception raised)
;; ;;

View File

@ -1,5 +1,5 @@
;;; ;;;
;;; Time-stamp: <2008-08-08 21:38:07 noel> ;;; Time-stamp: <2009-06-11 17:11:22 noel>
;;; ;;;
;;; Copyright (C) 2005 by Noel Welsh. ;;; Copyright (C) 2005 by Noel Welsh.
;;; ;;;
@ -39,6 +39,7 @@
"location.ss" "location.ss"
"result.ss" "result.ss"
"test.ss" "test.ss"
"check-info.ss"
"monad.ss" "monad.ss"
"hash-monad.ss" "hash-monad.ss"
"name-collector.ss" "name-collector.ss"
@ -127,6 +128,14 @@
[(test-failure? result) [(test-failure? result)
(let* ([exn (test-failure-result result)] (let* ([exn (test-failure-result result)]
[stack (exn:test:check-stack exn)]) [stack (exn:test:check-stack exn)])
(textui-display-check-info-stack stack verbose?))]
[(test-error? result)
(let ([exn (test-error-result result)])
(textui-display-check-info-stack (check-info-stack (exn-continuation-marks exn)))
(display-exn exn))]
[else (void)]))
(define (textui-display-check-info-stack stack [verbose? #f])
(for-each (for-each
(lambda (info) (lambda (info)
(cond (cond
@ -161,10 +170,7 @@
(display-check-info info)])) (display-check-info info)]))
(if verbose? (if verbose?
stack stack
(strip-redundant-params stack))))] (strip-redundant-params stack))))
[(test-error? result)
(display-exn (test-error-result result))]
[else (void)]))
;; display-verbose-check-info : test-result -> void ;; display-verbose-check-info : test-result -> void
(define (display-verbose-check-info result) (define (display-verbose-check-info result)