add keyword argument to eli-tester that allows for silent successes
This commit is contained in:
parent
e847632456
commit
2f730f479c
|
@ -62,12 +62,12 @@
|
||||||
[prefix (continuation-mark-set->list (current-continuation-marks)
|
[prefix (continuation-mark-set->list (current-continuation-marks)
|
||||||
failure-prefix-mark)])
|
failure-prefix-mark)])
|
||||||
(error 'loc "~a" (form prefix 'e fmt arg ...)))))
|
(error 'loc "~a" (form prefix 'e fmt arg ...)))))
|
||||||
(define (t1 x)
|
(define (test-1 x)
|
||||||
#`(let ([x (safe #,x)])
|
#`(let ([x (safe #,x)])
|
||||||
(unless (and (eq? 'values (car x)) (= 2 (length x)) (cadr x))
|
(unless (and (eq? 'values (car x)) (= 2 (length x)) (cadr x))
|
||||||
#,(blame x "expected: non-#f single value\n got: ~a"
|
#,(blame x "expected: non-#f single value\n got: ~a"
|
||||||
#'(show x)))))
|
#'(show x)))))
|
||||||
(define (t2 x y [eval2? #t])
|
(define (test-2 x y [eval2? #t])
|
||||||
#`(let* ([x (safe #,x)] [xtag (car x)]
|
#`(let* ([x (safe #,x)] [xtag (car x)]
|
||||||
[y #,(if eval2? #`(safe #,y) y)] [ytag (car y)])
|
[y #,(if eval2? #`(safe #,y) y)] [ytag (car y)])
|
||||||
(cond
|
(cond
|
||||||
|
@ -96,13 +96,13 @@
|
||||||
#,(blame x "bad error message, expected ~a: ~s\ngot: ~s"
|
#,(blame x "bad error message, expected ~a: ~s\ngot: ~s"
|
||||||
"an exception satisfying" #'yerr #'xerr))]
|
"an exception satisfying" #'yerr #'xerr))]
|
||||||
[else (error 'test "bad error specification: ~e" yerr)]))])))
|
[else (error 'test "bad error specification: ~e" yerr)]))])))
|
||||||
(define (te x y) (t2 x #`(list 'error #,y #f) #f))
|
(define (test-error x y) (test-2 x #`(list 'error #,y #f) #f))
|
||||||
(define (try t . args)
|
(define (try t . args)
|
||||||
#`(let ([c (test-context)])
|
#`(let ([c (test-context)])
|
||||||
(with-handlers ([exn? (lambda (e) (set-mcdr! c (cons e (mcdr c))))])
|
(with-handlers ([exn? (lambda (e) (set-mcdr! c (cons e (mcdr c))))])
|
||||||
(set-mcar! c (add1 (mcar c)))
|
(set-mcar! c (add1 (mcar c)))
|
||||||
#,(apply t args))))
|
#,(apply t args))))
|
||||||
(define (tb x) x)
|
(define (test-0 x) x)
|
||||||
(let loop ([xs (map (lambda (x)
|
(let loop ([xs (map (lambda (x)
|
||||||
(let ([e (syntax-e x)])
|
(let ([e (syntax-e x)])
|
||||||
(if (or (memq e '(do => <= =error> <error=))
|
(if (or (memq e '(do => <= =error> <error=))
|
||||||
|
@ -129,23 +129,24 @@
|
||||||
(cdr r))
|
(cdr r))
|
||||||
r))]
|
r))]
|
||||||
[(list* 'do x r) ; to avoid counting non-test exprs as tests
|
[(list* 'do x r) ; to avoid counting non-test exprs as tests
|
||||||
(cons (tb x) r)]
|
(cons (test-0 x) r)]
|
||||||
[(list* x '=> y r) (cons (try t2 x y) r)]
|
[(list* x '=> y r) (cons (try test-2 x y) r)]
|
||||||
[(list* y '<= x r) (cons (try t2 x y) r)]
|
[(list* y '<= x r) (cons (try test-2 x y) r)]
|
||||||
[(list* x '=error> y r) (cons (try te x y) r)]
|
[(list* x '=error> y r) (cons (try test-error x y) r)]
|
||||||
[(list* y '<error= x r) (cons (try te x y) r)]
|
[(list* y '<error= x r) (cons (try test-error x y) r)]
|
||||||
[(list* x r)
|
[(list* x r)
|
||||||
;; if x = (test ...), then it's implicitly in a `do'
|
;; if x = (test ...), then it's implicitly in a `do'
|
||||||
;; (not really needed, but avoids an extra count of tests)
|
;; (not really needed, but avoids an extra count of tests)
|
||||||
(syntax-case x (test)
|
(syntax-case x (test)
|
||||||
[(test x0 x1 ...) (cons (tb x) r)]
|
[(test x0 x1 ...) (cons (test-0 x) r)]
|
||||||
[_ (cons (try t1 x) r)])]
|
[_ (cons (try test-1 x) r)])]
|
||||||
[(list) '()]))])
|
[(list) '()]))])
|
||||||
(if (pair? t)
|
(if (pair? t)
|
||||||
(loop (cdr t) (cons (car t) r))
|
(loop (cdr t) (cons (car t) r))
|
||||||
#`(lambda () #,@(reverse r))))))
|
#`(lambda () #,@(reverse r))))))
|
||||||
|
|
||||||
(define (run-tests thunk force-new-context?)
|
;; pass 'quiet to have nothing printed on success
|
||||||
|
(define (run-tests thunk force-new-context? #:on-pass [pass 'loud])
|
||||||
(if (and (test-context) (not force-new-context?))
|
(if (and (test-context) (not force-new-context?))
|
||||||
(thunk)
|
(thunk)
|
||||||
(let ([c (mcons 0 '())])
|
(let ([c (mcons 0 '())])
|
||||||
|
@ -157,15 +158,25 @@
|
||||||
(test-context #f)
|
(test-context #f)
|
||||||
(let ([num (mcar c)] [exns (mcdr c)])
|
(let ([num (mcar c)] [exns (mcdr c)])
|
||||||
(if (null? exns)
|
(if (null? exns)
|
||||||
(printf "~a test~a passed\n" num (if (= num 1) "" "s"))
|
(case pass
|
||||||
|
[(loud) (printf "~a test~a passed\n" num (if (= num 1) "" "s"))]
|
||||||
|
[(quiet) (void)])
|
||||||
(error 'test "~a/~a test failures:~a" (length exns) num
|
(error 'test "~a/~a test failures:~a" (length exns) num
|
||||||
(string-append*
|
(string-append*
|
||||||
(append-map (lambda (e) (list "\n" (exn-message e)))
|
(append-map (lambda (e) (list "\n" (exn-message e)))
|
||||||
(reverse exns))))))))))))
|
(reverse exns))))))))))))
|
||||||
|
|
||||||
|
(define-syntax-rule (define-test name force-context)
|
||||||
|
(define-syntax (name stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ #:on-pass pass x0 x (... ...))
|
||||||
|
#'(run-tests #:on-pass pass (test-thunk x0 x (... ...)) force-context)]
|
||||||
|
[(_ x0 x (... ...))
|
||||||
|
#'(run-tests (test-thunk x0 x (... ...)) force-context)])))
|
||||||
|
|
||||||
(provide test test*)
|
(provide test test*)
|
||||||
(define-syntax-rule (test x0 x ...) (run-tests (test-thunk x0 x ...) #f))
|
(define-test test #f)
|
||||||
(define-syntax-rule (test* x0 x ...) (run-tests (test-thunk x0 x ...) #t))
|
(define-test test* #t)
|
||||||
|
|
||||||
#; ; test the `test' macro
|
#; ; test the `test' macro
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user