提问人:Reb.Cabin 提问时间:2/14/2023 最后编辑:Reb.Cabin 更新时间:2/14/2023 访问量:51
Leiningen 找不到额外的测试文件(CIDER 可以)
Leiningen not finding extra test files (CIDER does)
问:
我已经检查了参考问题,我仍然感到困惑。我有一些测试可以在 emacs 的 CIDER 中工作,但不能通过 .我需要让它们在.lein test
lein test
我在 Clojure 项目中有以下源代码布局:
ClojureProjects002/asr (master ✖ ✹ ✭)──>
tree src
src
├── asr
│ ├── arithmetic.clj
│ ├── asr.clj
... many files ...
│ ├── core.clj <~~~~~~~ notice this one
... more files ...
│ └── utils.clj
└── stack_machine <~~~~~~~ notice underscore
└── stack.clj
5 directories, 23 files
ClojureProjects002/asr (master ✖ ✹ ✭)──>
tree test
test
├── asr
│ └── core_test.clj <~~~~~~~ this one works in lein
└── stack_machine <~~~~~~~ this one doesn't
└── sm_test.clj <~~~~~~~ notice underscores
文件并遵循此处:src/stack_machine/stack.clj
test/stack_machine/sm_test.clj
stack.clj
:
(ns stack-machine.stack ;; <~~~~~~~ notice dash
(:import java.util.concurrent.Executors))
;;; blah blah blah
(def thread-pool
(Executors/newFixedThreadPool
(+ 2 (.availableProcessors (Runtime/getRuntime)))))
;;; blah blah blah
sm_test.clj
:
(ns sm-test ;; <~~~~~~~ notice dashes here
(:use [stack-machine.stack]) ;; ~~~~ and here
(:require [clojure.test :as t]))
(t/deftest test-test-itself
(t/testing "tests in the namespace 'stack machine.'"
(t/is (== 1 1.0))))
当我这样做时,测试文件可以在 CIDER 中工作,但会产生以下错误(要点:找不到cider-test-run-ns-tests
lein test
sm_test.clj
)
(it does the tests on asr namespace, then)
Execution error (FileNotFoundException) at user/eval227 (form-init3759808036021590492.clj:1).
Could not locate sm_test__init.class, sm_test.clj or sm_test.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
我怎样才能使lein测试适用于整个项目?
我将不胜感激任何建议!
答:
2赞
Alan Thompson
2/14/2023
#1
我很惊讶 CIDER 找到了测试,因为 in 中的命名空间是错误的。它应该是:sm_test
(ns stack-machine.sm-test ; added `stack-machine`
(:use stack-machine.stack clojure.test)) ; removed unneed square brackets
(deftest test-test-itself
(testing "tests in the namespace 'stack-machine.'"
(is (= 5 (+ 2 3))))) ; avoid int vs float comparisons!
P.S. 最好保持源文件和测试文件名称之间的对称性,例如:
src/stack_machine/stack.clj
test/stack_machine/stack_test.clj
P.S. 我尽量避免在命名空间中使用连字符,这样你就不必在文件名中转换为下划线,反之亦然。
评论