user11460387
user11460387

Reputation:

How to use the Common Lisp testing framework 'Prove'?

So I have this file named test.lisp. Here it is:

(in-package :cl-user)
(defpackage test
  (:use :cl
    :prove))
(in-package :test)

(defun square (x) (* x x))

(plan 3)

(ok (not (find 4 '(1 2 3))))
(is 4 4)
(is (square 3) 9)

(finalize)

When I load this file ie

(load "test.lisp")

the 3 tests get completed - it is successful; but when I try to call the function square I get an error saying that square is undefined.

Why is this happening?

I would like to know how to use Prove given a src file.

Thanks

Upvotes: 0

Views: 222

Answers (3)

user11460387
user11460387

Reputation:

I solved it by exporting the square procedure; like so:

(in-package :cl-user)
(defpackage test
  (:use :cl
    :prove)
  (:export :square)) ; like so - exporting `square`
(in-package :test)

(defun square (x) (* x x))

(plan 3)

(ok (not (find 4 '(1 2 3))))
(is 4 4)
(is (square 3) 9)

(finalize)

I then loaded the file and evaluated:

(use-package :test)

I was able to call square. Woohoo!

Upvotes: 0

Gwang-Jin Kim
Gwang-Jin Kim

Reputation: 9865

Your package definition should export the names in the package which you want access to from outside the package:

(in-package :cl-user)

(defpackage test
  (:use :cl
    :prove)
  (:documentation "My new test package.")
  (:export :square)) ;; add more functions/variables if you want to make them
                     ;; available for user who imports this package 'test'

(in-package :test)

Now, after (load "test.lisp") the :exported names are available outside the package. Or do how @coredump suggested - without :exporting -:

access the non-:exported names inside the package by test::square (<packagename>::<func/var-name>).

Upvotes: 1

Martin Buchmann
Martin Buchmann

Reputation: 1231

As coredump‘s comment suggest your problem might be unrelated to prove and you should get used to the logic of CL packages.

If you need more information about testing there are very good examples in the CL cookbook.

Upvotes: 2

Related Questions