Hi all,

I have been trying for a while to write proper unit tests for a language implementation I am working on. By "proper" tests I mean tests that are run using raco test just like any other tests. Until now, I have a separate shell-script based testing framework that runs scripts written
in my own #lang, but all too often I forgot to run those tests.

For a standard s-exp based language, this is not difficult:

(module+ test

  (module demo lazy
    (provide foo)
    (define (foo x) (* 2 x)))

  (require (only-in 'demo foo))

  (check-equal? (force (foo 2)) 4))

But for a #lang that uses a different reader, I haven't found a working solution yet. Even if I am willing to re-write my examples in s-exp syntax, I run into problems:

(module+ test

  (module example scribble/base
    (section "Introduction"))

  (require (only-in 'example doc))

  (check-equal? (force (foo 2)) 4))

This yields the error message

  module: no #%module-begin binding in the module's language

Anyway, what I really want is use the #lang's standard syntax. Reading it isn't much of a problem:

(parameterize ([read-accept-lang #t]
                [read-accept-reader #t])
   (read-syntax "test-module"
(open-input-string "#lang scribble/base\n@section[Introduction]")))

But then I get a syntax-object for my module, which I need to evaluate somehow. I'd expect eval-syntax to do the job, but...

(eval-syntax
 (parameterize ([read-accept-lang #t]
                [read-accept-reader #t])
   (read-syntax "test-module"
(open-input-string "#lang scribble/base\n@section[Introduction]")))
 (module->namespace 'racket/base))

only says

; test-module::1: module: unbound identifier;
;  also, no #%app syntax transformer is bound
;   at: module

although both module and %app are defined in racket/base.

Any ideas (or pointers to examples) for doing this correctly?

Thanks in advance,
  Konrad.

--
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.

Reply via email to