简体   繁体   English

为 Clojure/boot 寻求简单的工作流程设置

[英]Seeking simple workflow set-up for Clojure/boot

How do you set up boot so that: (a) all source files are in the current directory, (b) unit tests run every time a source file is changed, (c) the REPL refreshes definitions when source files containing them change?您如何设置引导以便:(a)所有源文件都在当前目录中,(b)每次更改源文件时运行单元测试,(c)当包含它们的源文件更改时,REPL 刷新定义?

Specifically:具体来说:

  • What goes in build.boot ? build.boot什么?

  • What's the shell command to start the REPL?启动 REPL 的 shell 命令是什么? And/or what command in the REPL starts the watching of unit tests?和/或 REPL 中的什么命令开始监视单元测试?

  • What other conventional set-up do I need to do?我还需要做哪些其他常规设置?

I've read through a lot of documentation on boot , boot-test , boot-quick-test , REPL reloading in boot , and boot-refresh , but I haven't been able to get much to work.我已经阅读了很多关于bootboot-testboot-quick-test在 boot 中重新加载 REPLboot-refresh的文档,但我一直没能做很多工作。 The documentation I've found so far seems to provide tidbits and hints but not what's needed to put these things together.到目前为止,我找到的文档似乎提供了花絮和提示,但没有提供将这些东西放在一起所需的内容。

A simple example of an appropriate build.boot (and whatever else) would be especially helpful.一个适当的build.boot (以及其他任何东西)的简单示例会特别有帮助。


So far, this is what I have that (sort of) works.到目前为止,这就是我所拥有的(某种)作品。

(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))

Plus one file in the current directory, sample.clj :在当前目录中加上一个文件sample.clj

(ns sample
  (:require [clojure.test :refer :all]))

(defn myfunc [] "this string")

(deftest test-myfunc
  (is (= "this string" (myfunc))))

This gets boot to find source files in the current directory, and it enables me to manually reload changes in sample.clj by typing (refresh) in the REPL.这将启动以在当前目录中查找源文件,并且它使我能够通过在 REPL 中键入(refresh)手动重新加载sample.clj的更改。 (boot (test)) used to manually run the unit tests in a .clj file, but it failed when I tried it just now, with the error "Wrong number of args (0) passed to: core/test". (boot (test))用于手动运行.clj文件中的单元测试,但我刚才尝试时失败了,出现错误“传递给:核心/测试的 args (0) 数量错误”。

What's the right way to do this?这样做的正确方法是什么?

Due to how Boot handles watching and notifying about file changes you cannot use clojure.tools.namespace.repl/refresh directly.由于 Boot 处理监视和通知文件更改的方式,您不能直接使用clojure.tools.namespace.repl/refresh

You can use a wrapper for it - samestep/boot-refresh:您可以为其使用包装器 - 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])

Now you can start REPL server which will reload on file changes:现在您可以启动 REPL 服务器,它将在文件更改时重新加载:

boot repl -s watch refresh

And connect to it either from your IDE (eg CIDER or Cursive) or via:并从您的 IDE(例如 CIDER 或 Cursive)或通过以下方式连接到它:

boot repl -c

and whenever there are changes in your source files detected, appropriate namespaces will be reloaded and available in your client REPL session.每当检测到源文件发生更改时,相应的命名空间将被重新加载并在您的客户端 REPL 会话中可用。

You can also start boot watch test in another terminal to get auto-test behaviour.您还可以在另一个终端中启动boot watch test以获得自动测试行为。

And finally your issue with (boot (test)) giving Wrong number of args (0) passed to: core/test was caused because you didn't required adzerk.boot-test which contains a test task which you wanted to call.最后,您的(boot (test))错误数量的 args (0) 传递给:core/test是因为您不需要包含要调用的test任务的adzerk.boot-test It looks that there might be clojure.test/test available which was called instead.看起来可能有clojure.test/test可用,它被调用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM