Page 1 of 1

PCL: unit test frame work, stuck.

Posted: Tue Feb 02, 2010 4:30 pm
by lithos
I'm going through Practical common lisp right now I'm stuck on the unit testing frame work. I've been checking and rechecking the syntax, closed the IDE and even copied the examples from the website to compare on the screen and I'm not seeing anything wrong.

As a side note I don't get how the macros combine-results and check interact with each other so an explanation would be nice. Does the loop run twice? because that seems like it would be bad form.

running (test-+) gives me an error. EVAL: variable RESULT has no value
[Condition of type SYSTEM::SIMPLE-UNBOUND-VARIABLE]

Code: Select all

(defun report-result (result form)
  (format t "~:[FAIL~;passs~] ... ~a~%" result form))

(defmacro check (&body forms)
  `(combine-results
    ,@(loop for f in forms collect `(report-result ,f ',f))))

(defmacro combine-results (&body forms)
  (with-gensyms (result)
    `(let ((,result t))
      ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
      ,result)))

(defun test-+ ()
  (check (= (+ 1 2) 3)
         (= (+ 1 2) 3)))

Re: PCL: unit test frame work, stuck.

Posted: Tue Feb 02, 2010 9:29 pm
by nuntius
lithos wrote:As a side note I don't get how the macros combine-results and check interact with each other so an explanation would be nice. Does the loop run twice? because that seems like it would be bad form.
Macroexpand is your friend. Most CL editors have a shortcut to macroexpand the current form.

Code: Select all

* (macroexpand-1 '(check (= (+ 1 2) 3) (= (+ 1 2) 3)))
(COMBINE-RESULTS (REPORT-RESULT (= (+ 1 2) 3) '(= (+ 1 2) 3))
                 (REPORT-RESULT (= (+ 1 2) 3) '(= (+ 1 2) 3)))
* (macroexpand-1 *)
; LET: variable RESULT has no value
RESULT should be defined in WITH-GENSYMS; but you don't have such a macro defined in your snippet, so CL thinks it is an ordinary function and RESULT is another function.

Re: PCL: unit test frame work, stuck.

Posted: Wed Feb 03, 2010 8:15 am
by lithos
That got it. When I defined "with-gensyms" it said that it was already defined and a scary message asking if I wanted to overwrite it, So I thought it was in already. I made a new one with a different name and it mostly works.

thanks for the help.