0

I'm trying to find a way to always recompile the components (test-1, test-2, test-3, test-4) every time I call (asdf: test-system: my-system), but I do not know how to do it yet.

(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)))

An imaginary function to show where I want to go:

:perform (test-op (op system)
                    (progn (recompile-components system)
                           (symbol-call :test-lib '#:run))))
Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
PerduGames
  • 1,108
  • 8
  • 19

1 Answers1

0

I solved the question thus:

First I created an asdf.lisp file with a package lib-test-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)

then I imported the following lib-test-asdf functions into the package.lisp file, where it is my defpackage of lib-test:

(:import-from #:lib-test-asdf
                #:test-file
                #:run-lib-test-asdf)

I created a new system definition for 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))))

To run tests with ASDF:

(asdf:test-system :your-app)

I based on Prove: https://github.com/fukamachi/prove/blob/master/src/asdf.lisp

PerduGames
  • 1,108
  • 8
  • 19