PCL: unit test frame work, stuck.

Discussion of Common Lisp

PCL: unit test frame work, stuck.

Postby lithos » Tue Feb 02, 2010 4:30 pm

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)))
lithos
 
Posts: 14
Joined: Tue Feb 02, 2010 4:11 pm

Re: PCL: unit test frame work, stuck.

Postby nuntius » Tue Feb 02, 2010 9:29 pm

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.
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: PCL: unit test frame work, stuck.

Postby lithos » Wed Feb 03, 2010 8:15 am

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.
lithos
 
Posts: 14
Joined: Tue Feb 02, 2010 4:11 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 2 guests