From 44ed73877aad7ff21ca3027ba3f106ca768cce1f Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 4 Mar 2016 18:32:58 -0500 Subject: [PATCH] [test] convert to new-style failure tests --- format.rkt | 2 +- test/format-fail.rkt | 27 +++++---------------------- test/function-fail.rkt | 16 ++++++---------- test/math-fail.rkt | 28 +++++++--------------------- test/regexp-fail.rkt | 31 ++++++++----------------------- test/vector-fail.rkt | 27 ++++++--------------------- 6 files changed, 33 insertions(+), 98 deletions(-) diff --git a/format.rkt b/format.rkt index bf8e3f5..f175276 100644 --- a/format.rkt +++ b/format.rkt @@ -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)] diff --git a/test/format-fail.rkt b/test/format-fail.rkt index 049d7e2..78dbb3c 100644 --- a/test/format-fail.rkt +++ b/test/format-fail.rkt @@ -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))) -) +)) diff --git a/test/function-fail.rkt b/test/function-fail.rkt index e800548..212a47c 100644 --- a/test/function-fail.rkt +++ b/test/function-fail.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) +)) diff --git a/test/math-fail.rkt b/test/math-fail.rkt index 0bd7575..617c730 100644 --- a/test/math-fail.rkt +++ b/test/math-fail.rkt @@ -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))) -) +)) diff --git a/test/regexp-fail.rkt b/test/regexp-fail.rkt index 9168bbb..df67192 100644 --- a/test/regexp-fail.rkt +++ b/test/regexp-fail.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))) - -) +)) diff --git a/test/vector-fail.rkt b/test/vector-fail.rkt index 090a719..84ad3f2 100644 --- a/test/vector-fail.rkt +++ b/test/vector-fail.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))) -) +))