[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/1.4.2.2i |
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 http://www.ccs.neu.edu/home/matthias/Tmp/contracts.html
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.
Regards,
Peter
--
http://sjamaan.ath.cx
--
"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
pgp_3o7EKtrlu.pgp
Description: PGP signature
- [Chicken-users] Integrating unit tests into source code, felix winkelmann, 2006/12/14
- Re: [Chicken-users] Integrating unit tests into source code, elf, 2006/12/14
- Re: [Chicken-users] Integrating unit tests into source code,
Peter Bex <=
- Re: [Chicken-users] Integrating unit tests into source code, felix winkelmann, 2006/12/14
- Message not available
- Re: [Chicken-users] Re: Integrating unit tests into source code, Peter Bex, 2006/12/14
- Re: [Chicken-users] Re: Integrating unit tests into source code, Brandon J. Van Every, 2006/12/14
- Re: [Chicken-users] Re: Integrating unit tests into source code, Peter Busser, 2006/12/15
- Re: [Chicken-users] Re: Integrating unit tests into source code, Brandon J. Van Every, 2006/12/15
- Re: [Chicken-users] Re: Integrating unit tests into source code, Peter Busser, 2006/12/15