(module schemeunit mzscheme (require "random.ss" (lib "etc.ss") (planet "test.ss" ("schematics" "schemeunit.plt" 2 8))) (require-for-syntax (planet "syntax-utils.ss" ("cce" "syntax-utils.plt" 1 1)) (planet "combinators.ss" ("cce" "combinators.plt" 1 4))) (provide check-randomly test-randomly) (define-for-syntax (check-stx! ok? desc stx err-stx) (unless (ok? (syntax-e stx)) (raise-syntax-error #f (format "expected ~a" desc) stx err-stx))) (define-for-syntax (check-stx-list! ok? desc stx err-stx) (for-each (lambda (elem) (check-stx! ok? desc elem err-stx)) (syntax->list stx))) (define-syntax (check-randomly stx) (syntax-case stx () [(c-r ([var gen . optional] . rest) . body) (quasisyntax/loc stx (let*-random ([var gen . optional]) (with-check-info (['#,(syntax-prefix "random-" #'var) var]) (c-r rest . body))))] [(c-r () . body) (syntax/loc stx (let* () . body))])) (define-syntax (test-randomly stx) (syntax-case stx () [(t-r name count clauses . body) (syntax/loc stx (apply test-suite name (build-list count (lambda (index) (test-case (number->string (+ index 1)) (check-randomly clauses . body))))))])) )