[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Integrating unit tests into source code

From: Peter Bex
Subject: Re: [Chicken-users] Integrating unit tests into source code
Date: Thu, 14 Dec 2006 11:05:15 +0100
User-agent: Mutt/

On Thu, Dec 14, 2006 at 10:51:46AM +0100, felix winkelmann wrote:
> Hi!
> While reading a bit about "doctest" (the Python utility), I thought
> it would be relatively easy to support embedded documentation
> in definitions, like:
> (define (foo ...)
>   '(test (...))
>   <body>...)
> The basic idea is to extend the idea of Lisp/Scheme docstrings
> (a string as the first form inside a procedure, when the body
> has more than one expression) to doc-sexprs.
> So one could embed test-cases directly in the code, in a backwards-
> and R5RS-compatible way.
> It's no big deal to extend the compiler to extract this info. What I'm
> looking for is ideas about the exact mechanism, the syntax, etc.
> Pointless or useful?

It might be useful, but typically tests are much bigger than a single
sexpr.  If you really want to test a function well, you'll have to
write tests around all the corner cases and weird combinations.
How bigger a function is, the more tests you'll need.  I'm not sure
I'd want to clutter up my code with tests like that.

I like the idea of 'contracts' a lot more.  PLT scheme has a library
for those.  See
for a draft manual/guide on how to use them.  Contracts specify the
how a function should behave.  With a library like this you don't
need to hack the core compiler either.

The major difference between contracts and tests is that contracts
are of a declarative nature while tests are more like exhaustive
example uses of a function and what the result ought to be.

Also, if we're lucky we can snarf the existing PLT code and modify
it, which would save a lot of work.

By the way, I never liked the way traditional Lisp docstrings work,
they're an ugly hack IMHO.  I can't really explain why, but putting
the string right inside the function body without any structure to
indicate it's a docstring just gives me a bad taste in my mouth.
It fits with Common Lisp, but not with Scheme IMHO.

"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth

Attachment: pgp_3o7EKtrlu.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]