更改 Clojure/Leiningen 项目中的测试目录

Changing the test directory in a Clojure/Leiningen project

我创建了一个新的 Clojurescript/Om 项目。目录结构如下所示:

├── project.clj
├── resources
│   └── public
│       ├── index.html
│       └── src
│           └── om_tutorial
│               └── core.cljs
├── script
│   └── figwheel.clj
├── src
│   ├── clj
│   │   ├── test
│   │   └── example-project
│   │       └── core.clj
│   └── cljs
│       └── example-project
│           └── core.cljs
├── target
│   ├── classes
│   │   └── META-INF
│   │       └── maven
│   │           └── typing
│   │               └── typing
│   │                   └── pom.properties
│   └── stale
│       └── leiningen.core.classpath.extract-native-dependencies
└── test
    └── clj
        └── example-project
            └── test_core.clj

我的package.json非常小,看起来像这样:

(defproject typing "0.1.0-SNAPSHOT"
  :description "example-project"
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [org.clojure/clojurescript "1.7.170"]
                 [org.omcljs/om "1.0.0-alpha22"]
                 [figwheel-sidecar "0.5.0-SNAPSHOT" :scope "test"]
                 [http-kit "2.2.0-SNAPSHOT"]
                 [compojure "1.5.0"]
                 [ring "1.4.0"]
                 [cheshire "5.5.0"]]
  :test-paths ["test"])

但是,我无法让 Leiningen 识别测试路径。当我 运行 lein test 时,我看到:

Exception in thread "main" java.io.FileNotFoundException: Could not locate test/typing/test_core__init.class or test/example-project/test_core.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name., compiling:(/private/var/folders/dk/jvt798yj6ds6wnkwk_24wrcm0000gp/T/form-init5157365051258208935.clj:1:125)
...
Caused by: java.io.FileNotFoundException: Could not locate test/example-project/test_core__init.class or test/example-project/test_core.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
...
Tests failed.

我将测试从 test/clj/example-project/... 移至 test/example-project/...,并将实施从 src/clj/example-project/ 移至 src/example-project,但我仍然看到相同的错误。

如何让 Leiningen 识别我的测试?

也许 :test-paths 需要更进一步,以便 lein 可以找到源代码。

你可以试试:

:test-paths ["test/clj"]

我看到您使用基本相同的思路移动源代码。但这更容易。此外,在对 project.clj 进行任何更改后,您需要 lein clean 然后 lein deps。我的方法更多关于 deps 而你的更多关于 clean,但无论如何都是权宜之计。此外,您还需要检查 clean 是否真的删除了输出。如果不是,您始终可以通过删除文件来手动清理。