Skip to content

Commit 3a4abbc

Browse files
committed
Fix boot.test/runtests, ns-interns is evaluated at task execution
In order for the autodiscovery of deftesttask to work, an ns-interns call is necessary. The problem was that before this patch boot.test/runtest was executing it at task creation time, necessitating a require in build.boot for it to work. Potentially though, the require of the test can be done in a separate task right before calling boot.test/runtest. This is why ns-interns has been moved at task execution time (inside a with-pass-thru, storing in an atom the detected commands).
1 parent cb91201 commit 3a4abbc

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

boot/core/build.boot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
:source-paths #{"test"}
33
:dependencies '[[org.clojure/tools.reader "1.0.0-alpha2"]])
44

5-
(require '[boot.test :as test :refer [runtests test-report test-exit]]
5+
(require '[boot.test :refer [runtests test-report test-exit]]
66
'boot.task.built-in-test
77
'boot.test-test)
88

@@ -12,6 +12,6 @@
1212

1313
(deftask test []
1414
(boot.util/info "Testing against version %s\n" (App/config "BOOT_VERSION"))
15-
(comp (test/runtests)
16-
(test/test-report)
17-
(test/test-exit)))
15+
(comp (runtests)
16+
(test-report)
17+
(test-exit)))

boot/core/src/boot/parallel.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The first item of the vector is timeout, the second unit"}
122122
(string/split command-str #"\s"))
123123

124124
(defn task-sync-map
125-
"Add batch-specific keys to the input sync map.
125+
"Add task-specific keys to the input sync map.
126126
127127
This function currently clones, adds keys and returns a HashMap whose
128128
values will be modified during the parallel computation. Make sure
@@ -206,7 +206,7 @@ The first item of the vector is timeout, the second unit"}
206206
sync-map (parallel-init-fn (empty-sync-map))
207207
seqs-of-cmds (partition-all n commands)
208208
seqs-of-midwares (map #(commands->parallel-task sync-map %) seqs-of-cmds)]
209-
(util/dbug "Middleware command partitions: %s.\n" (vec seqs-of-cmds))
209+
(util/dbug "Partitions: %s.\n" (vec seqs-of-cmds))
210210
(core/with-pre-wrap [fileset]
211211
(reduce (fn [prev-fs mw]
212212
(let [handler (mw identity)] ;; this triggers the parallel computation

boot/core/src/boot/test.clj

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,25 @@
253253
t threads NUMBER int "The maximum number of threads to spawn during the tests."
254254
n namespaces NAMESPACE #{sym} "The set of namespace symbols to run tests in."
255255
e exclusions NAMESPACE #{sym} "The set of namespace symbols to be excluded from test."]
256-
(let [commands (cond
257-
commands commands
258-
:default (->> (or (seq namespaces) (all-ns))
259-
(remove (or exclusions #{}) )
260-
(namespaces->vars test-me-pred)
261-
(map var->command)))]
262-
(if (seq commands)
263-
(do (assert (every? string? commands)
264-
(format "commands must be strings, got %s" commands))
265-
(binding [parallel/*parallel-hooks* {:init init-sync-map
266-
:task-init task-sync-map}]
267-
(parallel/runcommands :commands commands
268-
:batches threads)))
269-
(do (util/warn "No namespace was tested.")
270-
identity))))
256+
(assert (every? string? commands) (format "commands must be strings, got %s" commands))
257+
(let [cmd-atom (atom commands)]
258+
(comp (core/with-pass-thru _
259+
(reset! cmd-atom (->> (or (seq namespaces) (all-ns))
260+
(remove (or exclusions #{}))
261+
(namespaces->vars test-me-pred)
262+
(map var->command)
263+
(into #{}))))
264+
(core/with-pre-wrap fileset
265+
(binding [parallel/*parallel-hooks* {:init init-sync-map
266+
:batch-init identity
267+
:task-init task-sync-map}]
268+
(if-let [commands (seq @cmd-atom)]
269+
(let [middleware (parallel/runcommands :commands commands
270+
:batches threads)]
271+
;; Forcing execution of runcommands inside this task
272+
((middleware identity) fileset))
273+
(do (util/warn "No namespace was tested. Try to require your test namespaces before calling boot.test/runtests.\n")
274+
fileset)))))))
271275

272276
(comment
273277
(reset! util/*verbosity* 2)
@@ -281,5 +285,4 @@
281285
"boot.task.built-in-test/sift-to-asset-invert-tests"
282286
"boot.task.built-in-test/sift-include-tests"})
283287
(test-report)
284-
(test-exit)))
285-
)
288+
(test-exit))))

0 commit comments

Comments
 (0)