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?
How do common lisp frameworks deal with packages?
-
- Posts: 8
- Joined: Wed Mar 17, 2010 6:03 pm
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:
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.
Re: How do common lisp frameworks deal with packages?
I wouldn't recommend to pass package names as arguments at all.npolyspace wrote:How can one write a "deftest" that will take an additional argument specifying what package to use?
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 ...)

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 ...)
- edgar
Note to the board administrator: It's extremely annoying that I need to escape :other-package with [color=#000000]

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