我试图找到一种在每次调用(asdf: test-system: 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"
: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))))发布于 2019-02-20 11:45:46
我这样解决了这个问题:
首先,我使用包lib- 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运行测试,请执行以下操作:
(asdf:test-system :your-app)I基于Prove:
https://stackoverflow.com/questions/54758591
复制相似问题