problem with lisp-unit

Discussion of Common Lisp

problem with lisp-unit

Postby chrm » Wed Jul 11, 2012 2:15 pm

I'm having a problem with lisp-unit. Some asserts don't return the correct value and there is a difference between tests defined in the REPL and tests defined in a lisp buffer.

Starting slime and loading project:
Code: Select all
; SLIME 2012-04-07
CL-USER> (ql:quickload :testproject)
To load "testproject":
  Load 1 ASDF system:
    testproject
; Loading "testproject"

(:TESTPROJECT)
CL-USER> (in-package :testproject)
#<PACKAGE "TESTPROJECT">


Run tests, defined in testproject.lisp:
Code: Select all
TESTPROJECT> (run-tests)
FOOBAR: (FIND '(BAR) '(FOO (BAR) BAZ)) failed:
Expected NIL but saw (BAR)
FOOBAR: (FIND '(BAR) '(FOO (BAR) BAZ) :TEST #'EQ) failed:
Expected NIL but saw (BAR)
FOOBAR: 4 assertions passed, 2 failed.


Redefine tests in REPL an run them:
Code: Select all
TESTPROJECT> (define-test foobar
  (assert-false (find '(bar) '(foo (bar) baz)))
  (assert-false (find '(bar) (list 'foo (list 'bar) 'baz)))
  (assert-false (find '(bar) '(foo (bar) baz) :test #'eq))
  (assert-false (find '(bar) (list 'foo (list 'bar) 'baz) :test #'eq))
  (assert-true  (find '(bar) '(foo (bar) baz) :test #'equal))
  (assert-true  (find '(bar) (list 'foo (list 'bar) 'baz) :test #'equal))
  )
FOOBAR
TESTPROJECT> (run-tests foobar)
FOOBAR: 6 assertions passed, 0 failed.


The only thing in testproject.lisp is the foobar test, otherwise it's a fresh project created with quicklisp.

How can there be a difference between the tests defined in the REPL and the tests defined in the lisp buffer?

Is there something I'm missing?
chrm
 
Posts: 1
Joined: Wed Feb 18, 2009 5:46 pm

Re: problem with lisp-unit

Postby Konfusius » Wed Jul 11, 2012 3:51 pm

FOOBAR is a bad test because a Lisp implementation may choose to fold literal lists in which case both occurences of (BAR) in FIND may become eq (SBCL does so). Whether that is done depends on the compilation optimization options. Since it doesn't make much sense to compile a repl input with the highest optimization settings the literal lists in the repl will not be folded but they will when compiled with compile-file. Therefore both occurences of (BAR) are eq in the compiled file but not eq in the repl.

This behaviour does perfectly conform to the ANSI standard.
Konfusius
 
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 2 guests