0

我试图找到一种方法来每次调用(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))))
4

1 回答 1

0

我这样解决了这个问题:

首先,我使用包 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 运行测试:

(asdf:test-system :your-app)

我基于 Prove: https ://github.com/fukamachi/prove/blob/master/src/asdf.lisp

于 2019-02-20T03:45:45.870 回答