Common lisp 在ASDF中的测试op调用中重新编译组件
我试图找到一种方法,在每次调用(asdf:testsystem:my-system)时总是重新编译组件(test-1、test-2、test-3、test-4),但我还不知道怎么做Common lisp 在ASDF中的测试op调用中重新编译组件,common-lisp,asdf,Common Lisp,Asdf,我试图找到一种方法,在每次调用(asdf:testsystem:my-system)时总是重新编译组件(test-1、test-2、test-3、test-4),但我还不知道怎么做 (defsystem :my-system/test :author "noloop" :description "Test." :depends-on (:test-lib :my-system) :components ((:module "test" :compo
(defsystem :my-system/test
:author "noloop"
:description "Test."
:depends-on (:test-lib :my-system)
:components ((:module "test"
:components
((:file "test-1")
(:file "test-2")
(:file "test-3")
(:file "test-4"))))
:perform (test-op (op system)
(symbol-call :test-lib '#:run)))
一个虚拟函数,显示我想去的地方:
:perform (test-op (op system)
(progn (recompile-components system)
(symbol-call :test-lib '#:run))))
我这样解决了这个问题: 首先,我使用lib-test-asdf.lisp包创建了一个asdf.lisp文件:
(in-package #:cl-user)
(defpackage #:lib-test-asdf
(:nicknames #:lib-test-asdf)
(:use #:common-lisp
#:asdf)
(:export #:test-file
#:run-lib-test-asdf))
(in-package #:lib-test-asdf)
(defvar *system-test-files* (make-hash-table))
(defclass test-file (asdf:cl-source-file) ())
(defmethod asdf:perform ((op asdf:compile-op) (c test-file))
;; do nothing
)
(defmethod asdf:perform ((op asdf:load-op) (c test-file))
(pushnew c (gethash (asdf:component-system c) *system-test-files*)
:key #'asdf:component-pathname
:test #'equal))
(defun run-lib-test-asdf (system-designator)
"Runs a testing ASDF system."
#+quicklisp (ql:quickload (if (typep system-designator 'asdf:system)
(asdf:component-name system-designator)
system-designator))
#-quicklisp (asdf:load-system system-designator)
(restart-case
(dolist (c (reverse
(gethash (asdf:find-system system-designator) *system-test-files*)))
(restart-case
(asdf:perform 'asdf:load-source-op c)))))
(import 'test-file :asdf)
然后,我将以下lib test asdf函数导入package.lisp文件,其中是我的lib test的defpackage:
(:import-from #:lib-test-asdf
#:test-file
#:run-lib-test-asdf)
我为lib test asdf创建了一个新的系统定义:
(defsystem :lib-test-asdf
:components ((:module "src"
:components
((:file "asdf")))))
With this I can use lib-test like this in my apps:
(defsystem :your-app
;; ...
:in-order-to ((test-op (test-op your-app/test))))
(defsystem :your-app/test
:author "your <your@youremail.com>"
:depends-on (:your-app :lib-test)
:defsystem-depends-on (:lib-test-asdf)
:components ((:module "test"
:components
((:test-file "your-app-test"))))
:perform (test-op :after (op c)
(progn (funcall (intern #.(string :run-lib-test-asdf) :lib-test) c)
(symbol-call :lib-test '#:run))))
我基于证明:
(asdf:test-system :your-app)