[test] convert to new-style failure tests
This commit is contained in:
parent
8e2b458aa7
commit
44ed73877a
|
@ -53,7 +53,7 @@
|
|||
#:with (arg+* ...)
|
||||
(for/list ([a (in-syntax #'(arg* ...))]
|
||||
[t (in-syntax #'fmt.type*)])
|
||||
(if t (quasisyntax/loc #'f (ann #,a #,t)) a))
|
||||
(if (syntax-e t) (quasisyntax/loc #'f (ann #,a #,t)) a))
|
||||
(syntax/loc #'f (format 'fmt.expanded arg+* ...))]
|
||||
[f:id
|
||||
(syntax/loc #'f format)]
|
||||
|
|
|
@ -1,32 +1,15 @@
|
|||
#lang racket/base
|
||||
(require trivial/private/test-common)
|
||||
|
||||
;; `format:` expressions that should fail to compile
|
||||
|
||||
(define (expr->typed-module expr)
|
||||
#`(module t typed/racket/base
|
||||
(require trivial/format)
|
||||
#,expr))
|
||||
|
||||
(define TEST-CASE* (map expr->typed-module '(
|
||||
(module+ test (test-compile-error
|
||||
#:require trivial/format
|
||||
#:exn #rx"format::|Type Checker"
|
||||
(printf: "hello ~a" "john" "doe")
|
||||
(printf: "hello ~a" "john" "doe")
|
||||
(printf: "binary number ~b\n" 3.14)
|
||||
(printf: "character ~c\n" 88)
|
||||
(printf: "octl ~o\n" 1.0+2i)
|
||||
(printf: "hex ~o\n" (exact->inexact 0))
|
||||
)))
|
||||
|
||||
;; -----------------------------------------------------------------------------
|
||||
|
||||
(module+ test
|
||||
(require
|
||||
rackunit)
|
||||
|
||||
(define (format-eval stx)
|
||||
(lambda () ;; For `check-exn`
|
||||
(compile-syntax stx)))
|
||||
|
||||
(for ([rkt (in-list TEST-CASE*)])
|
||||
(check-exn #rx"format::|Type Checker"
|
||||
(format-eval rkt)))
|
||||
)
|
||||
))
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
#lang racket/base
|
||||
(require trivial/private/test-common)
|
||||
|
||||
|
||||
(module+ test
|
||||
(test-compile-error
|
||||
#:require trivial/function
|
||||
#:exn #rx"Type Checker"
|
||||
;; ---
|
||||
((curry: (lambda (x y) x)) 0 1)
|
||||
(((curry: (lambda (x y z) z)) 'x) 'y 'z)
|
||||
)
|
||||
)
|
||||
(module+ test (test-compile-error
|
||||
#:require trivial/function
|
||||
#:exn #rx"Type Checker"
|
||||
((curry: (lambda (x y) x)) 0 1)
|
||||
(((curry: (lambda (x y z) z)) 'x) 'y 'z)
|
||||
))
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
#lang racket/base
|
||||
(require
|
||||
trivial/private/test-common
|
||||
(only-in typed/racket/base ann lambda One Zero -> : Natural Exact-Rational))
|
||||
|
||||
;; Math expressions that fail to typecheck
|
||||
|
||||
(define (expr->typed-module expr)
|
||||
#`(module t typed/racket/base
|
||||
(require trivial/math)
|
||||
#,expr))
|
||||
|
||||
(define TEST-CASE* (map expr->typed-module '(
|
||||
(module+ test (test-compile-error
|
||||
#:require trivial/math
|
||||
#:exn #rx"/:|Type Checker"
|
||||
(ann (let ([n 2]) (+: n -2)) Zero)
|
||||
(ann (let ([n 2]) (-: 2 n)) Zero)
|
||||
(ann (let ([n 5]) (*: n 1/5 1)) One)
|
||||
|
@ -22,19 +23,4 @@
|
|||
;; -- dividing by zero => caught statically
|
||||
(/: 1 1 0)
|
||||
(/: 1 1 (+: 4 -2 -2))
|
||||
)))
|
||||
|
||||
;; -----------------------------------------------------------------------------
|
||||
|
||||
(module+ test
|
||||
(require
|
||||
rackunit)
|
||||
|
||||
(define (math-eval stx)
|
||||
(lambda () ;; For `check-exn`
|
||||
(compile-syntax stx)))
|
||||
|
||||
(for ([rkt (in-list TEST-CASE*)])
|
||||
(check-exn #rx"/:|Type Checker"
|
||||
(math-eval rkt)))
|
||||
)
|
||||
))
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#lang racket/base
|
||||
(require
|
||||
trivial/private/test-common
|
||||
(only-in typed/racket/base
|
||||
ann : -> String Listof List U Bytes))
|
||||
|
||||
;; Ill-typed `regexp:` expressions
|
||||
;;
|
||||
;; TODO why can't I catch errors for (ann ... (List String))? WhydoI need #f?
|
||||
|
||||
(define (expr->typed-module expr)
|
||||
#`(module t typed/racket/base
|
||||
(require trivial/regexp)
|
||||
#,expr))
|
||||
|
||||
(define TEST-CASE* (map expr->typed-module '(
|
||||
(module+ test (test-compile-error
|
||||
#:require trivial/regexp
|
||||
#:exn #rx"Type Checker"
|
||||
(ann (regexp-match: "hi" "hi")
|
||||
(U #f (List String String String)))
|
||||
(ann (regexp-match: #rx"(h)(i)" "hi")
|
||||
|
@ -41,20 +42,4 @@
|
|||
;; --- Can't handle |, yet
|
||||
(ann (regexp-match: "this(group)|that" "that")
|
||||
(U #f (List String String)))
|
||||
)))
|
||||
|
||||
;; -----------------------------------------------------------------------------
|
||||
|
||||
(module+ test
|
||||
(require
|
||||
rackunit)
|
||||
|
||||
(define (regexp-eval stx)
|
||||
(lambda () ;; For `check-exn`
|
||||
(compile-syntax stx)))
|
||||
|
||||
(for ([rkt (in-list TEST-CASE*)])
|
||||
(check-exn #rx"Type Checker"
|
||||
(regexp-eval rkt)))
|
||||
|
||||
)
|
||||
))
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#lang racket/base
|
||||
(require
|
||||
trivial/private/test-common)
|
||||
|
||||
(define (expr->typed-module expr)
|
||||
#`(module t typed/racket/base
|
||||
(require trivial/vector)
|
||||
#,expr))
|
||||
(module+ test (test-compile-error
|
||||
#:require trivial/vector trivial/math
|
||||
#:exn #rx"out-of-bounds|Type Checker"
|
||||
|
||||
(define TEST-CASE* (map expr->typed-module '(
|
||||
(vector-ref: (vector 1) 3)
|
||||
|
||||
(let-vector: ([v (vector 1 2 3)])
|
||||
|
@ -60,19 +60,4 @@
|
|||
(vector-drop-right: (vector 1 2) 4)
|
||||
(vector-drop-right: (vector 'a) -1)
|
||||
|
||||
)))
|
||||
|
||||
;; -----------------------------------------------------------------------------
|
||||
|
||||
(module+ test
|
||||
(require
|
||||
rackunit)
|
||||
|
||||
(define (vector-eval stx)
|
||||
(lambda () ;; For `check-exn`
|
||||
(compile-syntax stx)))
|
||||
|
||||
(for ([rkt (in-list TEST-CASE*)])
|
||||
(check-exn #rx"out-of-bounds|Type Checker"
|
||||
(vector-eval rkt)))
|
||||
)
|
||||
))
|
||||
|
|
Loading…
Reference in New Issue
Block a user