- 我希望防止源代码包含测试套件。
- 我希望以便携的方式声明项目依赖项(包括src和test deps),以便我的团队成员不必修改其系统。
- 我想简化持续集成的检查,包括构建和测试。
使用ASDF或使用Allegro CL defsystem工具。
(asdf:defsystem :project-name
:description "description here"
:version "version here"
:author "your name here"
:depends-on (:a
:list
:of
:dependencie
:libraries)
:components ((:file "sourcefileone")
(:file "sourcefiletwo")))
project-test.asd(管理测试代码的包含文件)
(asdf:defsystem :project-name-test
:description "testing"
...
:depends-on (:project-name)
:components ((:file "sourcefileone-test")
(:file "sourcefiletwo-test")))
现在将这些文件的URI插入到上述命名为local-projects.txt的文件中
将项目源代码并行化到.lisp文件中,将测试调用并行化到-test.lisp文件中(* -test.lisp文件必须包含一个test-execute调用)
启动你的sbcl或者其他工具,然后使用(ql:quickload "project-name")
或者(ql:quickload "project-name-test")
,具体取决于你是要加载一个项目还是测试它。
唯一需要做的是,在复制项目的计算机上编写local-projects.txt。之后,你的同事可以在任何其他项目中使用asdf文件和quickload来依赖它。对于复制项目文件夹,你可以使用ctrl+c/v或者更先进的工具如git。
对于测试,我编写了自己的小型测试套件,但我敢打赌有更好的选择。更多关于quicklisp的信息可以在这里找到,关于asdf的信息可以在这里找到。如果你在配置quicklisp时遇到困难,也许这个问题可以帮助你。
(ql:quickload "quickproject")
(quickproject:make-project "~/src/lisp/swatchblade/"
:depends-on '(vecto hunchentoot))
package.lisp定义了包命名空间:
(defpackage #:swatchblade
(:use #:cl)
(:shadowing-import-from #:vecto
#:with-canvas
#:rounded-rectangle
#:set-rgb-fill
#:save-png-stream))
swatchblade.asd 定义了系统/项目、源代码文件、依赖项等。
(asdf:defsystem #:swatchblade
:serial t
:depends-on (#:vecto
#:hunchentoot
#:cl-colors)
:components ((:file "package")
(:file "swatchblade")))
swatchblade.lisp是源代码的位置。
您可以通过Quicklisp的quickload加载该项目:
* (ql:quickload "swatchblade")
loading output
* (swatchblade:start-web-server :port 8080)
Server started on port 8080.
quickproject:make-project "~/src/lisp/whimsytron/"
:depends-on '(swatchblade))
关于测试,您可以在package.lisp中为您的测试添加另一个命名空间:
(defpackage #:swatchblade-tests
(:use #:cl #:swatchblade))
(asdf:defsystem #:swatchblade
:serial t
:depends-on (#:vecto
#:hunchentoot
#:cl-colors)
:components ((:file "package")
(:file "swatchblade")
(:file "swatchglade-tests")))
加载swatchblade-tests命名空间以运行测试。
如果您想避免Quicklisp将所有依赖项安装到系统中,据我所知,您将不得不手动安装依赖项并加载系统。
Quicklisp的作者Zach Beane在使用quickproject上发布了更详细的帖子。
test-op
测试操作时需要先对foo-tests进行测试。这样做可以确保如果您执行(asdf:test-system "foo")
, 相应的测试系统及其依赖项将被加载,然后ASDF会执行test-op测试操作。test-op
测试操作时实际运行测试!为此,您需要在PERFORM
方法和(eql (find-system "foo-tests"))
上添加一个方法。该PERFORM
方法应调用您定义的所有FiveAM测试,并成功通过或者如果测试失败则引发错误。上述建议很好,但是如果你尝试测试未导出的内容,你会感到沮丧。一个简单的解决方法是不要定义两个包。将你的测试放在与其他源代码相同的包中。有什么坏处呢?
如果你认为会有害处,那么你将不得不像这样做:
(defpackage #:sources
(:use #:cl))
(defpackage #:tests
(:use #:cl #:lisp-unit)
(:import-from #:sources))
:import-from
而不是使用 :use
。(defun return-true () t)
Your test might look like:
(define-test test-return-true
"Make sure it works"
(assert-equal t (sources::return-true)))
(sources::return-true)
而不仅仅是 (return-true)
。对于像 'sym
这样的符号,也是一样的;将其称为 'sources::sym
。