我正在尝试使用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))
答案 0 :(得分:4)
根据http://github.com/OdonataResearchLLC/lisp-unit/wiki的文档,你可以使用
(lisp-unit:run-tests '(greater))
或
(lisp-unit:run-tests :all)