考虑以下 leiningen 项目core.clj
文件
(ns records.core)
(defn hello [] "hello")
(defprotocol my-sequence
(add [seqq item]))
(defrecord my-vector [coll]
my-sequence
(add [_ item] (conj coll item)))
我可以编译它并在 REPL 中测试它,如下所示:
records.core> (hello)
"hello"
records.core> (add (my-vector. []) 42)
[42]
但是,当我将其转录到 leiningen 单元测试文件中时,如下所示:
(ns records.core-test
(:require [clojure.test :refer :all]
[records.core :refer :all]))
(deftest a-test
(testing "adding to a my-vector"
(is (= (hello) "hello"))
#_(is (= [42] (add (my-vector. []) 42)))))
第一个测试成功,表明符号hello
已正确移动到records.core-test
命名空间,但测试my-vector
抛出编译器错误(删除#_
上面第二行的):
clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException:
Unable to resolve classname: my-vector, compiling:
(.../records/test/records/core_test.clj:8:22)
这似乎不是这个 SO 问题的重复,因为我正在使用require
and refer
,正如该问题的答案所建议的那样。
编辑:以下也无济于事
(add (records.core/my-vector. []) 42)
(add (#'records.core/my-vector. []) 42)
(add (@#'records.core/my-vector. []) 42)