Page 1 of 1

How do common lisp frameworks deal with packages?

Posted: Sun May 24, 2015 9:59 pm
by npolyspace
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?

Posted: Mon May 25, 2015 12:58 am
by Goheeca
I'm not familiar with deftest.
But on the unexported symbol, they can be accessed with double colon:

Code: Select all

package::unexported-symbol

Re: How do common lisp frameworks deal with packages?

Posted: Mon May 25, 2015 1:13 am
by edgar-rft
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:

Code: Select all

(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:

Code: Select all

(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?

Posted: Sat Jun 20, 2015 9:50 am
by sinnatagg
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