Leiningen not finding extra test files (CIDER does)

58 views Asked by At

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!

1

There are 1 answers

0
Alan Thompson On

I am surprised that CIDER found the test, since the namespace in sm_test is wrong. It should be:

(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. It would be better to maintain symmetry between the names of the source & test file, eg:

src/stack_machine/stack.clj
test/stack_machine/stack_test.clj

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.

Related Questions in CIDER