Seeking simple workflow set-up for Clojure/boot

353 Views Asked by At

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?

Specifically:

  • What goes in build.boot?

  • What's the shell command to start the REPL? And/or what command in the REPL starts the watching of unit tests?

  • 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. 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.


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:

(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. (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".

What's the right way to do this?

1

There are 1 best solutions below

5
On

Due to how Boot handles watching and notifying about file changes you cannot use clojure.tools.namespace.repl/refresh directly.

You can use a wrapper for it - 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:

boot repl -s watch refresh

And connect to it either from your IDE (e.g. CIDER or Cursive) or via:

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.

You can also start boot watch test in another terminal to get auto-test behaviour.

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. It looks that there might be clojure.test/test available which was called instead.