Fixing PR10950

This commit is contained in:
Jay McCarthy 2010-06-02 10:20:05 -06:00
parent 3ff7b0461c
commit 2985001a79
4 changed files with 65 additions and 46 deletions

View File

@ -1,12 +1,21 @@
#lang racket/base
(provide (all-defined-out))
(require racket/contract
"location.rkt"
(for-syntax racket/base
unstable/syntax))
;; Structures --------------------------------------------------
;; struct check-info : symbol any
(define-struct check-info (name value))
(provide/contract
[struct check-info ([name symbol?]
[value any/c])]
[check-info-mark symbol?]
[check-info-stack (continuation-mark-set? . -> . (listof check-info?))]
[with-check-info* ((listof check-info?) (-> any) . -> . any)])
(provide with-check-info)
;; Infrastructure ----------------------------------------------
@ -33,32 +42,23 @@
(list (make-check-info name val) ...)
(lambda () body ...))]))
(define (make-check-name name)
(make-check-info 'name name))
(define (make-check-params params)
(make-check-info 'params params))
(define (make-check-location stx)
(make-check-info 'location stx))
(define (make-check-expression msg)
(make-check-info 'expression msg))
(define (make-check-message msg)
(make-check-info 'message msg))
(define (make-check-actual param)
(make-check-info 'actual param))
(define (make-check-expected param)
(make-check-info 'expected param))
(define-syntax (define-check-type stx)
(syntax-case stx ()
[(_ id contract)
(with-syntax
([make-check-id (format-id #'id "make-check-~a" #'id)]
[check-id? (format-id #'id "check-~a?" #'id)])
(syntax/loc stx
(begin (define (make-check-id a) (make-check-info 'id a))
(define (check-id? info) (eq? (check-info-name info) 'id))
(provide/contract
[make-check-id (contract . -> . check-info?)]
[check-id? (check-info? . -> . boolean?)]))))]))
(define (check-name? info)
(eq? (check-info-name info) 'name))
(define (check-params? info)
(eq? (check-info-name info) 'params))
(define (check-location? info)
(eq? (check-info-name info) 'location))
(define (check-expression? info)
(eq? (check-info-name info) 'expression))
(define (check-message? info)
(eq? (check-info-name info) 'message))
(define (check-actual? info)
(eq? (check-info-name info) 'actual))
(define (check-expected? info)
(eq? (check-info-name info) 'expected))
(define-check-type name any/c)
(define-check-type params any/c)
(define-check-type location location/c)
(define-check-type expression any/c)
(define-check-type message any/c)
(define-check-type actual any/c)
(define-check-type expected any/c)

View File

@ -119,7 +119,7 @@
(syntax
(lambda (formal ...
[message #f]
#:location [location 'unknown]
#:location [location (list 'unknown #f #f #f #f)]
#:expression [expression 'unknown])
((current-check-around)
(lambda ()

View File

@ -1,17 +1,10 @@
#lang racket/base
(require racket/list)
(provide location-source
location-line
location-column
location-position
location-span
syntax->location
location->string)
(require racket/list
racket/contract)
;; type location = (list any number/#f number/#f number/#f number/#f)
;; location : source line column position span
(define location/c (list/c any/c (or/c number? false/c) (or/c number? false/c) (or/c number? false/c) (or/c number? false/c)))
(define location-source first)
(define location-line second)
@ -19,6 +12,16 @@
(define location-position fourth)
(define location-span fifth)
(provide/contract
[location/c contract?]
[location-source (location/c . -> . any/c)]
[location-line (location/c . -> . (or/c number? false/c))]
[location-column (location/c . -> . (or/c number? false/c))]
[location-position (location/c . -> . (or/c number? false/c))]
[location-span (location/c . -> . (or/c number? false/c))]
[syntax->location (syntax? . -> . location/c)]
[location->string (location/c . -> . string?)])
;; syntax->location : syntax -> location
(define (syntax->location stx)
(list (syntax-source stx)

View File

@ -0,0 +1,16 @@
#lang racket/base
(require rackunit
rackunit/text-ui
racket/port
tests/eli-tester)
(test
(with-output-to-string
(lambda ()
(parameterize ([current-error-port (current-output-port)])
(define-check (check3)
(fail-check))
(run-tests (test-suite "tests" (let ((foo check3)) (foo)))))))
=>
"--------------------\ntests > #f\nUnnamed test \nFAILURE\nname: check3\nlocation: unknown:?:?\nparams: \n--------------------\n0 success(es) 1 failure(s) 0 error(s) 1 test(s) run\n")