[plt-scheme] testing a module

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Wed Mar 30 16:56:20 EST 2005

> > what is the most sensible way to include tests in a module?
> >
> > python uses an idiom where
> >
> > if __name__ == '__main__':
> >    do_the_tests()

[some text cut]

> The SchemeUnit docs (available from PLaneT) give some pointers on how to
> set up your modules such that hitting "Execute" will run all of your
> test cases; see the sections on "Glassbox testing", "Tips for Using
> SchemeUnit", and "Extended Example."


Hi everyone,

I'm also curious to know if there's a fairly close equivalent to Python's
"if __name__ == __main__" idiom.  Having something like this makes it to
see example usage of a module without having to jump into a separate file.


mzscheme appears to support the -C switch to run a program through a
'main' entrypoint, but I don't see an analogous switch for main entry
through a module.  The closest I can see is --require-script or some
combination of the other execution flags with '-e'.

I'm just dreaming, but I think it would be neat to be able to have a
single flag '--require-main' that has symmetry with '--main', something
like:

###### (imaginary mzscheme)
$ mzscheme --require-main pair.ss
1 success(es)  0 error(s)  0 failure(s)
######


I know that we can already do something like this:

######
bash-2.05b$ mzscheme -tmv pair.ss -e "(main '(pair.ss))"
1 success(es)  0 error(s)  0 failure(s)
######

But this feels really ugly, and doesn't make it easy to take additional
command line arguments.



And I'd still want the module to be requireable, which means I can't do:

######
(module pair mzscheme
   ...)
(require pair)
(define (main args) ...)
######

and execute the module with -C, since, even though this might work as a
script, it no longer works with the module resolver:

######
> (require "pair.ss")
default-load-handler: expected only a `module' declaration for `pair', but
found an extra expression in: /home/dyoo/pair.ss
######


So I think that having a flag that's a combination of '--require' and
'--main' would be excellent.



Posted on the users mailing list.