Hi Gambiters,<br><br>  I've been thinking for a long time about the simplest unit testing framework I can think of. I came up with the following:<br><br>~/testing$ cat unit-test.scm <br>(define (unit-test-create name)<br>
  (let ((unit-test-name name)<br>        (tests '()))<br><br>    (define (add name test)<br>      (set! tests (cons (cons name test) tests)))<br><br>    (define (run-tests)<br>      (map (lambda (value)<br>             (let ((x (car value))<br>
                   (y (cdr value)))<br>               (pp `(,x ,(y)))))<br>           (reverse tests)))<br><br>    (define (dispatch . cmds)<br>      (cond ((eq? (car cmds) 'run) (run-tests))<br>            ((eq? (car cmds) 'add) (add (cadr cmds) (caddr cmds)))<br>
            ((#t (error ,(command ,cmds not supported))))))<br><br>    dispatch))<br>~/testing$ cat a.scm <br>(include "unit-test.scm")<br><br>(define unit-tests (unit-test-create 'tests-a))<br><br>(unit-tests 'add '+ (lambda () (eq? (+ 1 1) 2)))<br>
(unit-tests 'add '- (lambda () (eq? (- 1 1) 0)))<br>(unit-tests 'add '* (lambda () (eq? (* 1 1) 2)))<br><br>~/testing$ gsi -e "(load \"a.scm\") (unit-tests 'run)"<br>(+ #t)<br>(- #t)<br>
(* #f)<br><br><br><br>I'm almost happy with this, except that if I have a.scm and b.scm, I have to have different names in them (I can't have them both use 'unit-tests').<br><br>Maybe I can call them 'unit-tests-a' or 'unit-tests-b' .. but then I have to deal with folder path.<br>
<br>Maybe I can call them 'unit-tests-testing-a' and 'unit-tests-testing-b' but this becomes a pain when I move files around.<br><br>What I want would be somehow, to have a variable created automatically that's _local_ to the particular file, so that I can still run something like:<br>
<br>gsi -e "(load \"a.scm\") (magic)"<br>or<br>gsi -e "(include \"a.scm\") (magic)"<br>or<br>gsi -e "(magic1 \"a.scm\") (magic2)"<br><br>and have the proper tests run.<br>
<br>How can I do this?<br><br>Thanks!<br><br><br>