如何设置 boot 以便:(a) 所有源文件都在当前目录中,(b) 每次更改源文件时运行单元测试,(c) REPL当包含它们的源文件更改时刷新定义?
具体来说:
build.boot
里有什么?启动 REPL 的 shell 命令是什么?和/或 REPL 中的什么命令开始监视单元测试?
我还需要进行哪些常规设置?
我已经阅读了大量有关 boot 的文档, boot-test , boot-quick-test , REPL reloading in boot , 和 boot-refresh ,但我没能得到太多的工作。到目前为止,我找到的文档似乎提供了花絮和提示,但没有提供将这些东西放在一起所需的内容。
适当的 build.boot
(以及其他任何内容)的简单示例将特别有用。
到目前为止,这就是我所拥有的(某种)作品。
(set-env!
:dependencies '[
[adzerk/boot-test "1.1.2" :scope "test"]
[org.clojure/tools.namespace "0.2.11"]]
:source-paths #{"."})
(require '[clojure.tools.namespace.repl :as repl :refer [refresh]])
(apply repl/set-refresh-dirs (get-env :directories))
在当前目录下加上一个文件,sample.clj
:
(ns sample
(:require [clojure.test :refer :all]))
(defn myfunc [] "this string")
(deftest test-myfunc
(is (= "this string" (myfunc))))
这让 boot 在当前目录中找到源文件,它使我能够通过键入 (refresh)< 手动重新加载
在 REPL 中。 sample.clj
中的更改(boot (test))
以前在.clj
文件中手动运行单元测试,但是刚才试的时候失败了,报错“Wrong number of args (0) 传递给:核心/测试”。
正确的做法是什么?
最佳答案
您可以为其使用包装器 - samestep/boot-refresh:
(set-env!
:dependencies '[[adzerk/boot-test "1.1.2" :scope "test"]
[samestep/boot-refresh "0.1.0" :scope "test"]]
:source-paths #{"."})
(require '[samestep.boot-refresh :refer [refresh]]
'[adzerk.boot-test :refer :all])
现在您可以启动 REPL 服务器,它将在文件更改时重新加载:
boot repl -s watch refresh
然后从您的 IDE(例如 CIDER 或 Cursive)或通过以下方式连接到它:
boot repl -c
每当检测到您的源文件发生变化时,适当的命名空间将被重新加载并在您的客户端 REPL session 中可用。
您还可以在另一个终端启动boot watch test
以获得自动测试行为。
最后你的问题 (boot (test))
giving Wrong number of args (0) passed to: core/test 是因为你不需要adzerk.boot-test
,其中包含您要调用的 test
任务。看起来可能有可用的 clojure.test/test
被调用。
关于clojure - 为 Clojure/boot 寻求简单的工作流程设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41817065/