Question

I'm trying to to use asdf's functionality to run my test suite from the repl but when using quicklisps quickload if fails on the first attempt to load foo and success on the second.

(in-package :cl-user)
(defpackage :foo-system
  (:use :cl :asdf))
(in-package :foo-system)

(asdf:defsystem :foo
  :components ((:file "foo")))

(asdf:defsystem :foo-tests
  :depends-on (:foo)
  :components ((:file "foo-tests")))

(defmethod asdf:perform ((op test-op) (system (eql (find-system :foo))))
  (asdf:load-system 'foo-tests)
  (foo-tests:run-tests))

It makes sense because when I compile the asd file the error appears to be in the second form of the asdf:perfom defmethod. The error, replacing nclack by foo, is:

../../nclack/nclack.asd:36:27: read-error: READ error during COMPILE-FILE:

  Package NCLACK-TESTS does not exist.

    Line: 36, Column: 27, File-Position: 1034

    Stream: #<SB-SYS:FD-STREAM
              for "file /Users/PuercoPop/quicklisp/local-projects/nclack/nclack.asd"
              {1005DB11A3}>

which matches the (foo-tests:run-tests) line. So it appears to be that 'loading' a system is different from compiling its forms? Or why is the package not defined after loading the system? Any ideas? I'm at a loss.

Was it helpful?

Solution

When you compile-file this:

(defmethod asdf:perform ((op test-op) (system (eql (find-system :foo))))
  (asdf:load-system 'foo-tests)
  (foo-tests:run-tests))

the first step is to read the entire form. Reading includes interning of all symbols found. However, at read time, the form has not executed, so the system foo-tests is not yet loaded. Since that system includes the package foo-tests, and that is not loaded yet either, you cannot intern any symbols into that package at read time of this form.

That's why compile-file gives the error shown when trying to read the form.

It seems to me that you would need to (funcall (find-symbol "RUN-TESTS" #:foo-tests)).

OTHER TIPS

First:

If you define a new package FOO-SYSTEM and use the package ASDF and then use the asdf symbols still with the prefix, then you kind of defeated the using of the package. Why use it, when you prefix the symbols anyway?

It is hard to say what the error is, since we don't see a backtrace and don't see the files.

Anyway, you need to make sure that a package is available during compilation of a file. For example compiling a DEFPACKAGE form may not change the compile-time environment. You need to execute the DEFPACKAGE form. You also need to make sure that the package definition gets loaded during a load system operation.

If the package does not exist, you need to make sure that it exists.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top