This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
forked from shopsmart/clj-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot_cloverage.clj
37 lines (31 loc) · 1.77 KB
/
boot_cloverage.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(ns clj-boot.boot-cloverage
"A (cloverage) task to add to a test pipeline to generate coverage data.
From https://raw.githubusercontent.com/FossiFoo/cloverage/boot/boot-cloverage/src/cloverage/boot_cloverage.clj
until the corresponding PR is merged."
(:require [boot.core :as core]
[boot.pod :as pod]
[boot.util :as util]
[clojure.string :as s]
[clojure.set :as set]))
(core/deftask cloverage
"Run cloverage in a pod.
Expects test namespaces to be included in :source-paths."
[m test-matcher VAL regex "Regex used to select test namespaces"
o opts VAL str "other arguments passed to cloverage"]
(let [pod (-> (core/get-env)
pod/make-pod
future)]
(core/with-post-wrap fileset
(let [namespaces (core/fileset-namespaces fileset)
test-matcher-or-default (or test-matcher #".*-test")
[code-namespaces test-namespaces] ((juxt remove filter) #(re-matches test-matcher-or-default (name %)) namespaces)
code-ns-names (map name code-namespaces)
test-ns-names (map name test-namespaces)
test-args (interleave (repeat "-x") test-ns-names)
more-opts (when opts (s/split opts #"\s+"))
args (concat more-opts test-args code-ns-names)]
(util/info "running cloverage with %s%n" (pr-str args))
(pod/with-eval-in @pod
(doseq [ns '~code-namespaces] (require ns)) ; puts the code-namespaces on the classpatch and requires them
(require 'cloverage.coverage) ; we also need to resolve cloverage itself
(cloverage.coverage/-main ~@args)))))) ; args include code-namespace names, so cloverage does not need to resolve them, test-dir will be scanned for tests