我正在尝试使用lisp-unit。
我可以用quicklisp安装 lisp-unit : (ql:quickload "lisp-unit")
。
按照 lisp-unit 主页中的说明,我可以定义一个函数并生成define-test
.
(defun greater (x y) (if (> x y) x y))
(use-package :lisp-unit)
(define-test greater
(assert-equal 2 (greater 1 2))
(assert-equal 2 (greater 2 1))
(assert-equal -1 (greater -5 -1))
(assert-equal 0 (greater -2 0))
(assert-equal 3 (greater 3 3))
)
但是,当我尝试执行时(run-tests greater)
,我收到此错误消息。
EVAL: variable GREATER has no value
[Condition of type SYSTEM::SIMPLE-UNBOUND-VARIABLE]
Backtrace:
0: [1956] frame binding variables (~ = dynamically):
| ~ SWANK::*SLDB-STEPPING-P* <--> NIL
1: [1953] frame binding variables (~ = dynamically):
| ~ SWANK::*SLDB-LEVEL* <--> 7
2: [1950] frame binding variables (~ = dynamically):
| ~ *PACKAGE* <--> #<PACKAGE COMMON-LISP-USER>
可能有什么问题?这是我使用的完整源代码:
(ql:quickload "lisp-unit")
(use-package :lisp-unit)
(defpackage :bob
(:use :common-lisp)
(:export #:greater))
(in-package bob)
(defun greater (x y) (if (> x y) x y))
(lisp-unit:define-test greater
(assert-equal 2 (greater 1 2))
(assert-equal 2 (greater 2 1))
(assert-equal -1 (greater -5 -1))
(assert-equal 0 (greater -2 0))
(assert-equal 3 (greater 3 3))
)
(lisp-unit:run-tests greater)
添加
这是工作测试代码:
(ql:quickload "lisp-unit")
(use-package :lisp-unit)
(defun greater (x y) (if (> x y) x y))
(define-test test-greater
(assert-equal 2 (greater 1 2))
(assert-equal 2 (greater 2 1))
(assert-equal -1 (greater -5 -1))
(assert-equal 0 (greater -2 0))
(assert-equal 3 (greater 3 3))
)
(run-tests '(test-greater))