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.

How do common lisp frameworks deal with packages?

4 posts · 5559 views

How can one do unit testing in common lisp?
I started with the unit test framework of practical Common Lisp chapter 9.
As I have needed more features, I have been gradually adding them, but my most recent issue is stumping me.
How can I handle packages?
I have several different packages. How can one write a "deftest" that will take an additional argument specifying what package to use?
Every package has many functions that are not exported, so how does a test function in some other "test" package access non-exported symbols?

At first I thought I might be able to do something like:
(defmacro pdeftest (name package parameters &body body)
`(deftest ,name ,parameters :body (prog1 (progn (in-package ,package) ,@body) (in-package test))))

But this doesn't work, and it doesn't look like this is even an approach that could work. Do any of the test frameworks out there work with packages?

Re: How do common lisp frameworks deal with packages?

I'm not familiar with deftest.
But on the unexported symbol, they can be accessed with double colon:
package::unexported-symbol
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Re: How do common lisp frameworks deal with packages?

npolyspace wrote:How can one write a "deftest" that will take an additional argument specifying what package to use?
I wouldn't recommend to pass package names as arguments at all.

Usually you define a test-package that uses the respective other package(s), and then you write and run your deftests inside that test-package:
(defpackage :test-package
  (:use :common-lisp
        :other-package))

(in-package :test-package)

(deftest ...)
:use :other-package will save you from fiddeling with package names as parameters.

Non-exported functions of the other-package can be called from the test-package by using double-colon syntax like this:
(other-package::non-exported-function ...)
Using double-colon syntax in test-packages is o.k., but it's not a good idea to use non-exported symbols of other packages in public production code.

- edgar

Note to the board administrator: It's extremely annoying that I need to escape :other-package with [color=#000000]:o[/color]ther-package only to make that stupid smiley disappear. Overloading software with so-called "convenience" stuff inevitably leads to bullshit-quality. Please either remove that function or report it as a bug to the author(s) of the forum software. Thank you.

Re: How do common lisp frameworks deal with packages?

There are several unit test packages for CL. I use one called five-am.

You can import the symbols you need into a separate test package, there is no need to mess up your original package when running tests.

-a