首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ASDF中的test-op调用中重新编译组件

在ASDF中的test-op调用中重新编译组件
EN

Stack Overflow用户
提问于 2019-02-19 11:48:51
回答 1查看 134关注 0票数 0

我试图找到一种在每次调用(asdf: test-system: my-system)时总是重新编译组件(test-1、test-2、test-3、test-4)的方法,但我还不知道如何做到这一点。

代码语言:javascript
复制
(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)))

一个虚构的函数,用来显示我想去的地方:

代码语言:javascript
复制
:perform (test-op (op system)
                    (progn (recompile-components system)
                           (symbol-call :test-lib '#:run))))
EN

回答 1

Stack Overflow用户

发布于 2019-02-20 11:45:46

我这样解决了这个问题:

首先,我使用包lib- asdf.lisp -asdf.lisp创建了一个测试文件:

代码语言:javascript
复制
(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:

代码语言:javascript
复制
(:import-from #:lib-test-asdf
                #:test-file
                #:run-lib-test-asdf)

我为lib-test-asdf创建了新的系统定义:

代码语言:javascript
复制
(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运行测试,请执行以下操作:

代码语言:javascript
复制
(asdf:test-system :your-app)

I基于Prove:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54758591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档