diff --git a/pkgs/rackunit-pkgs/rackunit-doc/rackunit/scribblings/check.scrbl b/pkgs/rackunit-pkgs/rackunit-doc/rackunit/scribblings/check.scrbl index 5d511a0c98..e868fa344c 100644 --- a/pkgs/rackunit-pkgs/rackunit-doc/rackunit/scribblings/check.scrbl +++ b/pkgs/rackunit-pkgs/rackunit-doc/rackunit/scribblings/check.scrbl @@ -419,10 +419,12 @@ if the macro @racket[fail-check] is called in the body of the check. This allows more flexible checks, and in particular more flexible reporting options.} -@defform[(fail-check)]{ +@defform*[[(fail-check) + (fail-check message-expr)]]{ The @racket[fail-check] macro raises an @racket[exn:test:check] with -the contents of the check information stack. +the contents of the check information stack. The optional message +is used as the exception's message. } diff --git a/pkgs/rackunit-pkgs/rackunit-lib/rackunit/private/check.rkt b/pkgs/rackunit-pkgs/rackunit-lib/rackunit/private/check.rkt index 900521857c..191de1990f 100644 --- a/pkgs/rackunit-pkgs/rackunit-lib/rackunit/private/check.rkt +++ b/pkgs/rackunit-pkgs/rackunit-lib/rackunit/private/check.rkt @@ -70,14 +70,19 @@ (define-syntax fail-check (syntax-rules () - ((_) - (let ([marks (current-continuation-marks)]) + ((_ message*) + (let ([message message*] + [marks (current-continuation-marks)]) + (unless (string? message) + (raise-type-error 'fail-check "string" message)) (test-log! #f) (raise (make-exn:test:check - "Check failure" + message marks - (check-info-stack marks))))))) + (check-info-stack marks))))) + ((_) + (fail-check "Check failure")))) (define-syntax fail-internal (syntax-rules () diff --git a/pkgs/rackunit-pkgs/rackunit-lib/rackunit/private/format.rkt b/pkgs/rackunit-pkgs/rackunit-lib/rackunit/private/format.rkt index b18f5d5a44..f17ae37d3c 100644 --- a/pkgs/rackunit-pkgs/rackunit-lib/rackunit/private/format.rkt +++ b/pkgs/rackunit-pkgs/rackunit-lib/rackunit/private/format.rkt @@ -37,7 +37,7 @@ [(m . < . n) (string-append s (make-string (- n m) #\space))] [else - (substring s n)])) + (substring s 0 n)])) (define (display-check-info-name-value name value [value-printer write]) (display (string-pad-right