Common lisp——为什么这个符号不是外部的?
Common lisp — why isn't this symbol external?
我正在尝试 运行 在 ASDF 中进行测试,它看起来像这样:
;;;; foo.asd
(defsystem "foo/tests"
:depends-on ("foo"
"fiveam")
:components ((:module "tests"
:components
((:file "main"))))
:perform (test-op (op c) (symbol-call :fiveam '#:run! 'foo/tests:all-tests))
我的 tests/main.lisp
文件是这样开始的:
;;;; tests/main.lisp
(defpackage foo/tests
(:use :cl
:foo
:fiveam)
(:export :#run! :#all-tests))
(in-package :foo/tests)
当我在我的 REPL 中 运行 (asdf:test-system 'foo)
时,我进入了带有 LOAD-SYSTEM-DEFINITION-ERROR
的调试器。调试器抱怨 The symbol "ALL-TESTS" is not external in the FOO/TESTS package.
但是,我明明是在foo/tests
包中导出符号。有人能告诉我我在这里遗漏了什么以及为什么 Lisp 编译器看不到外部符号吗?非常感谢。
uninterned 符号的语法是 #:foo
,而不是 :#foo
。
您还需要在 运行 时解析 :perform
形式的符号,例如。 G。通过 uiop:find-symbol*
,就像你在那里使用 uiop:symbol-call
。
:perform (test-op (op c)
(symbol-call :fiveam '#:run!
(find-symbol* '#:all-tests '#:foo/tests)))
或者,由于您似乎从测试包中导出了一个 run!
函数,您可能希望调用它而不是 fiveam:run!
:
:perform (test-op (op c)
(symbol-call '#:foo/tests '#:run!))
我正在尝试 运行 在 ASDF 中进行测试,它看起来像这样:
;;;; foo.asd
(defsystem "foo/tests"
:depends-on ("foo"
"fiveam")
:components ((:module "tests"
:components
((:file "main"))))
:perform (test-op (op c) (symbol-call :fiveam '#:run! 'foo/tests:all-tests))
我的 tests/main.lisp
文件是这样开始的:
;;;; tests/main.lisp
(defpackage foo/tests
(:use :cl
:foo
:fiveam)
(:export :#run! :#all-tests))
(in-package :foo/tests)
当我在我的 REPL 中 运行 (asdf:test-system 'foo)
时,我进入了带有 LOAD-SYSTEM-DEFINITION-ERROR
的调试器。调试器抱怨 The symbol "ALL-TESTS" is not external in the FOO/TESTS package.
但是,我明明是在foo/tests
包中导出符号。有人能告诉我我在这里遗漏了什么以及为什么 Lisp 编译器看不到外部符号吗?非常感谢。
uninterned 符号的语法是 #:foo
,而不是 :#foo
。
您还需要在 运行 时解析 :perform
形式的符号,例如。 G。通过 uiop:find-symbol*
,就像你在那里使用 uiop:symbol-call
。
:perform (test-op (op c)
(symbol-call :fiveam '#:run!
(find-symbol* '#:all-tests '#:foo/tests)))
或者,由于您似乎从测试包中导出了一个 run!
函数,您可能希望调用它而不是 fiveam:run!
:
:perform (test-op (op c)
(symbol-call '#:foo/tests '#:run!))