I have checked the referenced questions, and I am still puzzled. I have some tests that work in CIDER in emacs, but not via lein test. I need to make them work in lein test.
I have the following source layout in a Clojure project:
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
The files src/stack_machine/stack.clj and test/stack_machine/sm_test.clj follow here:
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))))
The test file works in CIDER when I do cider-test-run-ns-tests, but lein test produces the following error (gist: can't find 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.
How can I make lein test work for this entire project?
I'd be grateful for any advice!
I am surprised that CIDER found the test, since the namespace in
sm_testis wrong. It should be:P.S. It would be better to maintain symmetry between the names of the source & test file, eg:
P.S. I try to avoid using hyphens in a namespace so you don't have to translate to underscores in the file name & vice versa.