improve error reporting ands doc for check-expect (PR 9499 and 9500)
svn: r10257
This commit is contained in:
parent
63311353d7
commit
938df1800c
|
@ -39,9 +39,11 @@
|
||||||
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
||||||
local let let* letrec time begin begin0 set! delay shared recur when case unless
|
local let let* letrec time begin begin0 set! delay shared recur when case unless
|
||||||
check-expect check-within check-error)
|
check-expect check-within check-error)
|
||||||
|
(check-expect check-within check-error require)
|
||||||
[program (code:line def-or-expr ...)]
|
[program (code:line def-or-expr ...)]
|
||||||
[def-or-expr definition
|
[def-or-expr definition
|
||||||
expr
|
expr
|
||||||
|
test-case
|
||||||
library-require]
|
library-require]
|
||||||
[definition (define (id id id ...) expr)
|
[definition (define (id id id ...) expr)
|
||||||
(define id expr)
|
(define id expr)
|
||||||
|
@ -71,7 +73,6 @@
|
||||||
(and expr expr expr ...)
|
(and expr expr expr ...)
|
||||||
(or expr expr expr ...)
|
(or expr expr expr ...)
|
||||||
(time expr)
|
(time expr)
|
||||||
test-case
|
|
||||||
empty
|
empty
|
||||||
(code:line id (code:comment #, @seclink["intermediate-id"]{identifier}))
|
(code:line id (code:comment #, @seclink["intermediate-id"]{identifier}))
|
||||||
(code:line prim-op (code:comment #, @seclink["intermediate-lambda-prim-op"]{primitive operation}))
|
(code:line prim-op (code:comment #, @seclink["intermediate-lambda-prim-op"]{primitive operation}))
|
||||||
|
|
|
@ -25,9 +25,11 @@
|
||||||
@schemegrammar*+qq[
|
@schemegrammar*+qq[
|
||||||
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
||||||
check-expect check-within check-error)
|
check-expect check-within check-error)
|
||||||
|
(check-expect check-within check-error require)
|
||||||
[program (code:line def-or-expr ...)]
|
[program (code:line def-or-expr ...)]
|
||||||
[def-or-expr definition
|
[def-or-expr definition
|
||||||
expr
|
expr
|
||||||
|
test-case
|
||||||
library-require]
|
library-require]
|
||||||
[definition (define (id id id ...) expr)
|
[definition (define (id id id ...) expr)
|
||||||
(define id expr)
|
(define id expr)
|
||||||
|
@ -40,7 +42,6 @@
|
||||||
(if expr expr expr)
|
(if expr expr expr)
|
||||||
(and expr expr expr ...)
|
(and expr expr expr ...)
|
||||||
(or expr expr expr ...)
|
(or expr expr expr ...)
|
||||||
test-case
|
|
||||||
empty
|
empty
|
||||||
id
|
id
|
||||||
(code:line #, @elem{@schemevalfont{'}@scheme[quoted]} (code:comment #, @seclink["beginner-abbr-quote"]{quoted value}))
|
(code:line #, @elem{@schemevalfont{'}@scheme[quoted]} (code:comment #, @seclink["beginner-abbr-quote"]{quoted value}))
|
||||||
|
|
|
@ -12,10 +12,11 @@
|
||||||
@schemegrammar*+library[
|
@schemegrammar*+library[
|
||||||
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
||||||
check-expect check-within check-error)
|
check-expect check-within check-error)
|
||||||
|
(check-expect check-within check-error require)
|
||||||
[program (code:line def-or-expr ...)]
|
[program (code:line def-or-expr ...)]
|
||||||
[def-or-expr definition
|
[def-or-expr definition
|
||||||
expr
|
expr
|
||||||
|
test-case
|
||||||
library-require]
|
library-require]
|
||||||
[definition (define (id id id ...) expr)
|
[definition (define (id id id ...) expr)
|
||||||
(define id expr)
|
(define id expr)
|
||||||
|
@ -28,7 +29,6 @@
|
||||||
(if expr expr expr)
|
(if expr expr expr)
|
||||||
(and expr expr expr ...)
|
(and expr expr expr ...)
|
||||||
(or expr expr expr ...)
|
(or expr expr expr ...)
|
||||||
test-case
|
|
||||||
empty
|
empty
|
||||||
id
|
id
|
||||||
(code:line id (code:comment #, @seclink["beginner-id"]{identifier}))
|
(code:line id (code:comment #, @seclink["beginner-id"]{identifier}))
|
||||||
|
|
|
@ -37,9 +37,11 @@
|
||||||
@schemegrammar*+qq[
|
@schemegrammar*+qq[
|
||||||
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
||||||
local let let* letrec time check-expect check-within check-error)
|
local let let* letrec time check-expect check-within check-error)
|
||||||
|
(check-expect check-within check-error require)
|
||||||
[program (code:line def-or-expr ...)]
|
[program (code:line def-or-expr ...)]
|
||||||
[def-or-expr definition
|
[def-or-expr definition
|
||||||
expr
|
expr
|
||||||
|
test-case
|
||||||
library-require]
|
library-require]
|
||||||
[definition (define (id id id ...) expr)
|
[definition (define (id id id ...) expr)
|
||||||
(define id expr)
|
(define id expr)
|
||||||
|
@ -56,7 +58,6 @@
|
||||||
(and expr expr expr ...)
|
(and expr expr expr ...)
|
||||||
(or expr expr expr ...)
|
(or expr expr expr ...)
|
||||||
(time expr)
|
(time expr)
|
||||||
test-case
|
|
||||||
empty
|
empty
|
||||||
(code:line id (code:comment #, @seclink["intermediate-id"]{identifier}))
|
(code:line id (code:comment #, @seclink["intermediate-id"]{identifier}))
|
||||||
(code:line prim-op (code:comment #, @seclink["intermediate-lambda-prim-op"]{primitive operation}))
|
(code:line prim-op (code:comment #, @seclink["intermediate-lambda-prim-op"]{primitive operation}))
|
||||||
|
|
|
@ -24,9 +24,11 @@
|
||||||
@schemegrammar*+qq[
|
@schemegrammar*+qq[
|
||||||
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
#:literals (define define-struct lambda cond else if and or empty true false require lib planet
|
||||||
local let let* letrec time check-expect check-within check-error)
|
local let let* letrec time check-expect check-within check-error)
|
||||||
|
(check-expect check-within check-error require)
|
||||||
[program (code:line def-or-expr ...)]
|
[program (code:line def-or-expr ...)]
|
||||||
[def-or-expr definition
|
[def-or-expr definition
|
||||||
expr
|
expr
|
||||||
|
test-case
|
||||||
library-require]
|
library-require]
|
||||||
[definition (define (id id id ...) expr)
|
[definition (define (id id id ...) expr)
|
||||||
(define id expr)
|
(define id expr)
|
||||||
|
@ -44,7 +46,6 @@
|
||||||
(and expr expr expr ...)
|
(and expr expr expr ...)
|
||||||
(or expr expr expr ...)
|
(or expr expr expr ...)
|
||||||
(time expr)
|
(time expr)
|
||||||
test-case
|
|
||||||
empty
|
empty
|
||||||
(code:line id (code:comment #, @seclink["intermediate-id"]{identifier}))
|
(code:line id (code:comment #, @seclink["intermediate-id"]{identifier}))
|
||||||
(code:line prim-op (code:comment #, @seclink["intermediate-prim-op"]{primitive operation}))
|
(code:line prim-op (code:comment #, @seclink["intermediate-prim-op"]{primitive operation}))
|
||||||
|
|
|
@ -10,21 +10,30 @@
|
||||||
|
|
||||||
(define ex-str "This is a string with \" inside")
|
(define ex-str "This is a string with \" inside")
|
||||||
|
|
||||||
(define-syntax-rule (schemegrammar*+library form ...)
|
(define-syntax-rule (schemegrammar*+library
|
||||||
|
#:literals lits
|
||||||
|
(check-expect check-within check-error require)
|
||||||
|
form ...)
|
||||||
(schemegrammar*
|
(schemegrammar*
|
||||||
|
#:literals lits
|
||||||
form ...
|
form ...
|
||||||
[test-case #, @scheme[(check-expect expr expr)]
|
[test-case #, @scheme[(check-expect expr expr)]
|
||||||
#, @scheme[(check-within expr expr expr)]
|
#, @scheme[(check-within expr expr expr)]
|
||||||
#, @scheme[(check-error expr expr)]]
|
#, @scheme[(check-error expr expr)]]
|
||||||
(...
|
(...
|
||||||
[libray-require #, @scheme[(require string)]
|
[library-require #, @scheme[(require string)]
|
||||||
#, @scheme[(require (lib string string ...))]
|
#, @scheme[(require (lib string string ...))]
|
||||||
#, @scheme[(require (planet string package))]])
|
#, @scheme[(require (planet string package))]])
|
||||||
(...
|
(...
|
||||||
[package #, @scheme[(string string number number)]])))
|
[package #, @scheme[(string string number number)]])))
|
||||||
|
|
||||||
(define-syntax-rule (schemegrammar*+qq form ...)
|
(define-syntax-rule (schemegrammar*+qq
|
||||||
|
#:literals lits
|
||||||
|
(check-expect check-within check-error require)
|
||||||
|
form ...)
|
||||||
(schemegrammar*+library
|
(schemegrammar*+library
|
||||||
|
#:literals lits
|
||||||
|
(check-expect check-within check-error require)
|
||||||
form ...
|
form ...
|
||||||
(...
|
(...
|
||||||
[quoted id
|
[quoted id
|
||||||
|
|
|
@ -30,11 +30,11 @@
|
||||||
"check-within requires three expressions. Try (check-within test expected range).")
|
"check-within requires three expressions. Try (check-within test expected range).")
|
||||||
|
|
||||||
(define-for-syntax CHECK-EXPECT-DEFN-STR
|
(define-for-syntax CHECK-EXPECT-DEFN-STR
|
||||||
"check-expect cannot be used as an expression")
|
"found a test that is not at the top level")
|
||||||
(define-for-syntax CHECK-WITHIN-DEFN-STR
|
(define-for-syntax CHECK-WITHIN-DEFN-STR
|
||||||
"check-within cannot be used as an expression")
|
CHECK-EXPECT-DEFN-STR)
|
||||||
(define-for-syntax CHECK-ERROR-DEFN-STR
|
(define-for-syntax CHECK-ERROR-DEFN-STR
|
||||||
"check-error cannot be used as an expression")
|
CHECK-EXPECT-DEFN-STR)
|
||||||
|
|
||||||
(define-struct check-fail (src))
|
(define-struct check-fail (src))
|
||||||
|
|
||||||
|
@ -84,21 +84,24 @@
|
||||||
'(syntax-e cdr cdr syntax-e car) ;; lambda
|
'(syntax-e cdr cdr syntax-e car) ;; lambda
|
||||||
))))))
|
))))))
|
||||||
|
|
||||||
|
(define-for-syntax (check-context?)
|
||||||
|
(let ([c (syntax-local-context)])
|
||||||
|
(memq c '(module top-level))))
|
||||||
|
|
||||||
;; check-expect
|
;; check-expect
|
||||||
(define-syntax (check-expect stx)
|
(define-syntax (check-expect stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ test actual)
|
[(_ test actual)
|
||||||
(not (eq? (syntax-local-context) 'expression))
|
(check-context?)
|
||||||
(check-expect-maker stx #'check-values-expected (list #`(lambda () test) #`actual) 'comes-from-check-expect)]
|
(check-expect-maker stx #'check-values-expected (list #`(lambda () test) #`actual) 'comes-from-check-expect)]
|
||||||
[(_ test)
|
[(_ test)
|
||||||
(not (eq? (syntax-local-context) 'expression))
|
(check-context?)
|
||||||
(raise-syntax-error 'check-expect CHECK-EXPECT-STR stx)]
|
(raise-syntax-error 'check-expect CHECK-EXPECT-STR stx)]
|
||||||
[(_ test actual extra ...)
|
[(_ test actual extra ...)
|
||||||
(not (eq? (syntax-local-context) 'expression))
|
(check-context?)
|
||||||
(raise-syntax-error 'check-expect CHECK-EXPECT-STR stx)]
|
(raise-syntax-error 'check-expect CHECK-EXPECT-STR stx)]
|
||||||
[(_ test ...)
|
[(_ test ...)
|
||||||
(eq? (syntax-local-context) 'expression)
|
(not (check-context?))
|
||||||
(raise-syntax-error 'check-expect CHECK-EXPECT-DEFN-STR stx)]))
|
(raise-syntax-error 'check-expect CHECK-EXPECT-DEFN-STR stx)]))
|
||||||
|
|
||||||
;; check-values-expected: (-> scheme-val) scheme-val src -> void
|
;; check-values-expected: (-> scheme-val) scheme-val src -> void
|
||||||
|
@ -113,19 +116,19 @@
|
||||||
(define-syntax (check-within stx)
|
(define-syntax (check-within stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ test actual within)
|
[(_ test actual within)
|
||||||
(not (eq? (syntax-local-context) 'expression))
|
(check-context?)
|
||||||
(check-expect-maker stx #'check-values-within (list #`(lambda () test) #`actual #`within) 'comes-from-check-within)]
|
(check-expect-maker stx #'check-values-within (list #`(lambda () test) #`actual #`within) 'comes-from-check-within)]
|
||||||
[(_ test actual)
|
[(_ test actual)
|
||||||
(not (eq? (syntax-local-context) 'expression))
|
(check-context?)
|
||||||
(raise-syntax-error 'check-within CHECK-WITHIN-STR stx)]
|
(raise-syntax-error 'check-within CHECK-WITHIN-STR stx)]
|
||||||
[(_ test)
|
[(_ test)
|
||||||
(not (eq? (syntax-local-context) 'expression))
|
(check-context?)
|
||||||
(raise-syntax-error 'check-within CHECK-WITHIN-STR stx)]
|
(raise-syntax-error 'check-within CHECK-WITHIN-STR stx)]
|
||||||
[(_ test actual within extra ...)
|
[(_ test actual within extra ...)
|
||||||
(not (eq? (syntax-local-context) 'expression))
|
(check-context?)
|
||||||
(raise-syntax-error 'check-within CHECK-WITHIN-STR stx)]
|
(raise-syntax-error 'check-within CHECK-WITHIN-STR stx)]
|
||||||
[(_ test ...)
|
[(_ test ...)
|
||||||
(eq? (syntax-local-context) 'expression)
|
(not (check-context?))
|
||||||
(raise-syntax-error 'check-within CHECK-WITHIN-DEFN-STR stx)]))
|
(raise-syntax-error 'check-within CHECK-WITHIN-DEFN-STR stx)]))
|
||||||
|
|
||||||
(define (check-values-within test actual within src test-info)
|
(define (check-values-within test actual within src test-info)
|
||||||
|
@ -139,13 +142,13 @@
|
||||||
(define-syntax (check-error stx)
|
(define-syntax (check-error stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ test error)
|
[(_ test error)
|
||||||
(not (eq? (syntax-local-context) 'expression))
|
(check-context?)
|
||||||
(check-expect-maker stx #'check-values-error (list #'(lambda () test) #`error) 'comes-from-check-error)]
|
(check-expect-maker stx #'check-values-error (list #'(lambda () test) #`error) 'comes-from-check-error)]
|
||||||
[(_ test)
|
[(_ test)
|
||||||
(not (eq? (syntax-local-context) 'expression))
|
(check-context?)
|
||||||
(raise-syntax-error 'check-error CHECK-ERROR-STR stx)]
|
(raise-syntax-error 'check-error CHECK-ERROR-STR stx)]
|
||||||
[(_ test ...)
|
[(_ test ...)
|
||||||
(eq? (syntax-local-context) 'expression)
|
(not (check-context?))
|
||||||
(raise-syntax-error 'check-error CHECK-ERROR-DEFN-STR stx)]))
|
(raise-syntax-error 'check-error CHECK-ERROR-DEFN-STR stx)]))
|
||||||
|
|
||||||
(define (check-values-error test error src test-info)
|
(define (check-values-error test error src test-info)
|
||||||
|
@ -162,7 +165,11 @@
|
||||||
(begin
|
(begin
|
||||||
(send (send test-info get-info) check-failed
|
(send (send test-info get-info) check-failed
|
||||||
(check->message result) (check-fail-src result))
|
(check->message result) (check-fail-src result))
|
||||||
(list 'check-error-failed (incorrect-error-message result) error))
|
(list 'check-error-failed
|
||||||
|
(if (expected-error? result)
|
||||||
|
(expected-error-message result)
|
||||||
|
(incorrect-error-message result))
|
||||||
|
error))
|
||||||
(list 'check-error-succeeded error error))))
|
(list 'check-error-succeeded error error))))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user