[rucksack-devel] Re: Rucksack Unit tests
Arthur Lemmens
alemmens at xs4all.nl
Thu Jan 24 12:32:59 UTC 2008
Brad Beveridge wrote:
> I have attached a tgz file that contains the beginnings of a basic
> test suite for Rucksack.
Thank you very much.
I noticed you used FiveAM as the test framework. I want to minimize
external dependencies for Rucksack, and I found FiveAM bigger and more
complicated than I would like for Rucksack. So I looked around for
something smaller and simpler; after reading
http://aperiodic.net/phil/archives/Geekery/notes-on-lisp-testing-frameworks.html
I decided to go for Chris Riesbeck's lisp-unit library. See
http://www.cs.northwestern.edu/academics/courses/325/readings/lisp-unit.html.
The lisp-unit library consists of a single file; I just added it to
the CVS repository and the rucksack-test ASDF file, and I rewrote
your tests to work with lisp-unit.
As you mentioned in your file, your tests uncovered a few bugs and
holes in Rucksack. I think these are all fixed now (except that
P-REPLACE isn't implemented yet for persistent lists).
Your code looked good to me, except for the BASIC-ROLLBACK test.
Instead of calling TRANSACTION-ROLLBACK explicitly within a
WITH-TRANSACTION form, you should just call ABORT or throw an
error. WITH-TRANSACTION will ensure that TRANSACTION-ROLLBACK is
called when its body wasn't completed normally.
So your test now looks like this:
(define-test basic-rollback
(with-rucksack-and-transaction (:if-exists :supersede)
(add-rucksack-root (p-cons 1 2) rs))
(with-rucksack-and-transaction ()
(let ((pc (first (rucksack-roots rs))))
(setf (p-car pc) 4)
;; Abort the transaction. WITH-TRANSACTION will take care
;; of calling TRANSACTION-ROLLBACK.
(abort)))
(with-rucksack-and-transaction ()
(let ((pc (first (rucksack-roots rs))))
(assert-equal 1 (p-car pc))))
;; Test that transactions are also rolled back when we throw an
;; error inside the body of a WITH-TRANSACTION form.
(assert-error 'error
(with-rucksack-and-transaction ()
(let ((pc (first (rucksack-roots rs))))
(setf (p-car pc) 5)
;; Abort the transaction by causing an error.
(error "Something went wrong"))))
(with-rucksack-and-transaction ()
;; Verify that the error caused a transaction rollback.
(let ((pc (first (rucksack-roots rs))))
(assert-equal 1 (p-car pc)))))
Arthur
More information about the rucksack-devel
mailing list