Greetings, Gentlebeings.
I was cleaning up some old lisp code tonight, and
"discovered" the following macro lurking in my code:
(defmacro ut (def &rest tests)
`(prog1 ,def
,@(mapcar #'(lambda (ut)
`(format t "~&~A:~40T~:[FAILED!!!~;ok~]"
,(first ut) ,(second ut)))
tests)))
(ut
(defun sum (x y)
(+ x y))
("1+1" (= (sum 1 1) 2))
("2+2" (= (sum 2 2) 4)))
It's usage has two main advantages:
1. If you move the function around, you'll take the unit tests with you
2. Unit tests are automatically executed at load time (at least in LW)
I'd be interested to see other solutions with similar effects.
Regards,
s.
Stefan Schmiedl <·@xss.de> wrote in message
···················@ID-57631.news.dfncis.de...
> Greetings, Gentlebeings.
>
> I was cleaning up some old lisp code tonight, and
> "discovered" the following macro lurking in my code:
>
> (defmacro ut (def &rest tests)
> `(prog1 ,def
> ,@(mapcar #'(lambda (ut)
> `(format t "~&~A:~40T~:[FAILED!!!~;ok~]"
> ,(first ut) ,(second ut)))
> tests)))
>
> (ut
> (defun sum (x y)
> (+ x y))
> ("1+1" (= (sum 1 1) 2))
> ("2+2" (= (sum 2 2) 4)))
I'm a big fan of formal unit tests, but..
> It's usage has two main advantages:
> 1. If you move the function around, you'll take the unit tests with you
This is cumbersome and inconvenient. A delivered application should not
always be full of its unit tests. The ratio of lines to actuall function is
way too high to make readable code.
> 2. Unit tests are automatically executed at load time (at least in LW)
This is not desirable. I'd rather call (run-all-tests) or something when I
feel like it.
Just some thoughts, YMMV!
--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
Greetings, Coby.
On Tue, 07 May 2002 18:57:00 GMT,
Coby Beck <·····@mercury.bc.ca> wrote:
>
> I'm a big fan of formal unit tests, but..
>
>> It's usage has two main advantages:
>> 1. If you move the function around, you'll take the unit tests with you
>
> This is cumbersome and inconvenient. A delivered application should not
> always be full of its unit tests. The ratio of lines to actuall function is
> way too high to make readable code.
I have one (Delphi) app out in production, where my customer can
access the unit testing GUI via the right most menu just below the
"Info" item. "Officially" it is used only after updates, to "prove"
that the new code is tested and issues with existing code have been
taken care of. But I like to imagine sitting my customer in the office
running the unit tests, getting a warm feeling out of the green bar
appearing on the screen :-)
Another thought crosses my mind: what does application delivery (in LW)
do to code which is only being evaluated without side effects?
And finally I just like to see the code being tested and the test
on the same screen. As you said, YMMV.
>
>> 2. Unit tests are automatically executed at load time (at least in LW)
>
> This is not desirable. I'd rather call (run-all-tests) or something when I
> feel like it.
This will be the second stage :-)
Collecting the tests in suites to run all of them.
The advantage here is that you use one keystroke (Alt-Meta-X in LW)
to define or modify the function and execute it's immediate unit tests
at the same time. If they don't run, I don't have to care for the
other tests.
>
> Just some thoughts, YMMV!
I was asking for them. Thank you!
s.
Stefan Schmiedl <·@xss.de> wrote in message
···················@ID-57631.news.dfncis.de...
> Greetings, Coby.
>
> On Tue, 07 May 2002 18:57:00 GMT,
> Coby Beck <·····@mercury.bc.ca> wrote:
> >> It's usage has two main advantages:
> >> 1. If you move the function around, you'll take the unit tests with you
> >
> > This is cumbersome and inconvenient. A delivered application should not
> > always be full of its unit tests. The ratio of lines to actuall
function is
> > way too high to make readable code.
[snip]
> Another thought crosses my mind: what does application delivery (in LW)
> do to code which is only being evaluated without side effects?
Good point. I can't imagine there being any effect on a delivered app from
those kinds of forms. Then again, I'm only imagining..
> And finally I just like to see the code being tested and the test
> on the same screen. As you said, YMMV.
>
> >
> >> 2. Unit tests are automatically executed at load time (at least in LW)
> >
> > This is not desirable. I'd rather call (run-all-tests) or something
when I
> > feel like it.
>
> This will be the second stage :-)
> Collecting the tests in suites to run all of them.
> The advantage here is that you use one keystroke (Alt-Meta-X in LW)
> to define or modify the function and execute it's immediate unit tests
> at the same time. If they don't run, I don't have to care for the
> other tests.
I can see the warm feeling from that ;)
--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
On 6 May 2002 22:00:53 GMT, Stefan Schmiedl <·@xss.de> wrote:
> I'd be interested to see other solutions with similar effects.
You may check RT by Richard Waters at the CMU Common Lisp Repository and a
similar tool--I don't remember its name right now--in CLOCC.
Paolo
--
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://www.paoloamoroso.it/ency/README
[http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/]
Hi Paolo,
will do as you suggested.
Thanks.
s.
On Thu, 09 May 2002 15:54:15 +0200,
Paolo Amoroso <·······@mclink.it> wrote:
> On 6 May 2002 22:00:53 GMT, Stefan Schmiedl <·@xss.de> wrote:
>
>> I'd be interested to see other solutions with similar effects.
>
> You may check RT by Richard Waters at the CMU Common Lisp Repository and a
> similar tool--I don't remember its name right now--in CLOCC.
>
>
> Paolo