This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

problem with lisp-unit

2 posts · 2170 views

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:
; 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:
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:
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?

Re: problem with lisp-unit

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.