[plt-scheme] Unit testing with typed-scheme (test-engine/scheme-tests)

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Sun Oct 25 16:27:51 EDT 2009

On Sun, Oct 25, 2009 at 4:18 PM, Scott McLoughlin <scott at adrenaline.com> wrote:
> Kind Schemely PLT Folk,
> So I'm finally trying to get all "instrumented" for getting my
> typed-scheme project really organized and off the ground and am
> having trouble with testing.
> ;;; Here is the short module that just defines my little typed
> ;;;   vector enumerate function/constructor.
> (module typscm typed-scheme
>   (require test-engine/scheme-tests)
>   (provide enumerate)
>   ;;; enumerate Vectorof constructor, sml style
>   (define: (x) (enumerate [size : Integer] [init : (Integer -> x)]) :
> (Vectorof x)
>     (build-vector size init))
>   ;(print (enumerate 3 (lambda: ([y : Integer]) (make-string y #\c))))
>   (check-expect
>    (enumerate 3 (lambda: ([y : Integer]) (make-string y #\c)))
>    #("" "c" "cc"))
>     (test)
>   )
> And here is the error output - *VERY* sorry for the long error message, but
> it
> might help someone in the know here on the list help me figure things out.
> typecheck: Error in macro expansion -- Untyped definition : (test5117) in:
> (define-values (test5117) (let-values (((test-info) (#%app
> namespace-variable-value (quote test~object) (quote #f) builder (#%app
> current-namespace)))) (if test-info (begin (#%app insert-test test-info
> (lambda () (#%app check-values-expected (#%app car (#%app list (lambda ()
> (#%app enumerate (quote 3) (lambda (y) (#%app make-string y (quote #\c)))))
> (#%app void))) (quote #("" "c" "cc")) (#%app list (quote #<path:C:\Documents
> and Settings\scottmcl\My Documents\scottmcl\src\ss\ssutil\typscm.ss>) (quote
> 15) (quote 2) (quote 377) (quote 97)) test-info)))) (#%app void))))
> Any and all help *most kindly* appreciated regarded automating the testing
> of typed-scheme code.
> Scott


I think the problem you have run into is that check-expect (and
related forms like test) are not typed, and are not written in a way
Typed Scheme can infer types for.  The upshot being, I don't think you
can use check-expect inside typed modules.

The good news is, you can write a separate untyped module, require the
typed binding of enumerate into it, and run check-expect on enumerate
in the untyped setting.

Something like this: [note that I did not run this, there may be typos]

;; save in "typscm.ss":
(module typscm typed-scheme
  (provide enumerate)

  ;;; enumerate Vectorof constructor, sml style
  (define: (x) (enumerate [size : Integer] [init : (Integer -> x)]) :
(Vectorof x)
    (build-vector size init))

 ) ;; close typed module

;; save in "untyp.ss":
(module untyp scheme
  (require test-engine/scheme-tests)
  (require "typscm.ss")

  ;(print (enumerate 3 (lambda (y) (make-string y #\c))))

   (enumerate 3 (lambda (y) (make-string y #\c)))
   #("" "c" "cc"))

  ) ;; close untyped module

Carl Eastlund

Posted on the users mailing list.