> ;;;;; > #lang racket > > (define/contract (add1 x y) > (integer? integer? . -> . integer?) > (+ x y)) > > (provide (contract-out [add2 (integer? integer? . -> . integer?)])) > (define (add2 x y) > (+ x y)) > > (module+ test > (require rackunit) > (check-exn exn:fail? (λ _ (add1 20.5 21.5))) > (check-equal? (add2 20.5 21.5) 42.0)) ; surprise! > ;;;;;
That is an interesting example and an important hint, thank you Matthew. Looking at the documentation it's interesting that your example seems to work within submodules, in contrast to your example with "contracts at the module boundary". Your modified example: ;;;; (module+ contract-test (define/contract (add1 x y) (integer? integer? . -> . integer?) (+ x y)) (provide (contract-out [add2 (integer? integer? . -> . integer?)])) (define (add2 x y) (+ x y))) (module+ test (require rackunit) (require (submod ".." contract-test)) (check-exn exn:fail? (λ _ (add1 20.5 21.5))) (check-equal? (add2 20.5 21.5) 42.0)) ;;;; ;;;; $ raco test contract-test ;;;; ... ;;;; add2: contract violation ;;;; ... Imho it would be nice if there was a small hint in the documentation about that case, perhaps there is and I didn't see it? Matthew Butterick <m...@mbtype.com> writes: >> >> Are there any advantages/disadvantages of using test submodules vs >> separate test files? Or is it just a matter of personal preference? >> >> It looks like that test submodules are more convenient and flexible but >> I observed that test submodules increase the start up time of racket >> scripts. >> > > If you're using contracts, you want your tests to cross the contract > boundaries. If you attach your contracts at the module boundary (a common > practice), then submodule tests will not trigger the contracts. (Example > below.) So putting these tests in a separate file is the better option. > > ;;;;; > #lang racket > > (define/contract (add1 x y) > (integer? integer? . -> . integer?) > (+ x y)) > > (provide (contract-out [add2 (integer? integer? . -> . integer?)])) > (define (add2 x y) > (+ x y)) > > (module+ test > (require rackunit) > (check-exn exn:fail? (λ _ (add1 20.5 21.5))) > (check-equal? (add2 20.5 21.5) 42.0)) ; surprise! > ;;;;; > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.