How do common lisp frameworks deal with packages?

Discussion of Common Lisp
Post Reply
npolyspace
Posts: 8
Joined: Wed Mar 17, 2010 6:03 pm

How do common lisp frameworks deal with packages?

Post by npolyspace » Sun May 24, 2015 9:59 pm

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?

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: How do common lisp frameworks deal with packages?

Post by Goheeca » Mon May 25, 2015 12:58 am

I'm not familiar with deftest.
But on the unexported symbol, they can be accessed with double colon:

Code: Select all

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.

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: How do common lisp frameworks deal with packages?

Post by edgar-rft » Mon May 25, 2015 1:13 am

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.

sinnatagg
Posts: 29
Joined: Tue Apr 21, 2009 3:04 am

Re: How do common lisp frameworks deal with packages?

Post by sinnatagg » Sat Jun 20, 2015 9:50 am

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

Post Reply