diff --git a/README.md b/README.md index 16d876e..3cb9c9f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [](dependency) ```clojure -[seancorfield/boot-expectations "1.0.2"] ;; latest release +[seancorfield/boot-expectations "1.0.3"] ;; latest release ``` [](/dependency) @@ -51,6 +51,7 @@ boot watch speak expectations ## Changes +1.0.3 - 12/25/2015 - Add `--requires` / `--shutdown` options. 1.0.2 - 12/24/2015 - Create pod before task body for efficiency. 1.0.1 - 12/20/2015 - Add `distinct` to dedupe list of namespaces (#7). 1.0.0 - 12/19/2015 - Initial public release. diff --git a/build.boot b/build.boot index d141309..c621b94 100644 --- a/build.boot +++ b/build.boot @@ -1,7 +1,7 @@ (set-env! :resource-paths #{"src"}) -(def version "1.0.2") +(def version "1.0.3") (task-options! pom {:project 'seancorfield/boot-expectations diff --git a/src/seancorfield/boot_expectations.clj b/src/seancorfield/boot_expectations.clj index cde4f5c..c96e123 100644 --- a/src/seancorfield/boot_expectations.clj +++ b/src/seancorfield/boot_expectations.clj @@ -8,7 +8,7 @@ '[[expectations "2.1.4"] [org.clojure/tools.namespace "0.2.11"]])) -(defn init [fresh-pod] +(defn init [requires fresh-pod] (doseq [r '[[clojure.java.io :as io] [clojure.tools.namespace.find :as f]]] (pod/require-in fresh-pod r))) @@ -28,19 +28,23 @@ will be used. You can specify regular expressions for namespaces to include and exclude." - [c clojure VERSION str "the version of Clojure for testing." - e exclude REGEX regex "the filter for excluded namespaces" - i include REGEX regex "the filter for included namespaces" - v verbose bool "Display each namespace completed"] - (let [pod-deps (update-in (core/get-env) [:dependencies] + [c clojure VERSION str "the version of Clojure for testing." + e exclude REGEX regex "the filter for excluded namespaces" + i include REGEX regex "the filter for included namespaces" + r requires NS #{sym} "namespaces to be required at pod startup" + s shutdown FN #{sym} "functions to be called prior to pod shutdown" + v verbose bool "Display each namespace completed"] + (let [exclude (or exclude #"^$") + include (or include #".*") + requires (or requires #{}) + shutdown (or shutdown #{}) + pod-deps (update-in (core/get-env) [:dependencies] (fn [deps] (cond->> (into deps (pod-deps)) clojure (mapv (partial replace-clojure-version clojure))))) - pods (pod/pod-pool pod-deps :init init)] + pods (pod/pod-pool pod-deps :init (partial init requires))] (core/with-pass-thru [fs] - (let [dirs (mapv (memfn getPath) (core/input-dirs fs)) - include (or include #".*") - exclude (or exclude #"^$")] + (let [dirs (mapv (memfn getPath) (core/input-dirs fs))] (core/cleanup (pods :shutdown)) (let [{:keys [fail error] :as summary} (pod/with-eval-in (pods :refresh) @@ -50,7 +54,11 @@ :when (and (re-find ~include (name n)) (not (re-find ~exclude (name n))))] (require n)) - (binding [e/ns-finished (if ~verbose (fn [ns] (println "\nCompleted" ns)) (constantly nil))] - (e/run-all-tests)))] + (try + (binding [e/ns-finished (if ~verbose (fn [ns] (println "\nCompleted" ns)) (constantly nil))] + (e/run-all-tests)) + (finally + (doseq [f ~shutdown] + (f)))))] (when (pos? (+ fail error)) (throw (ex-info "Some tests failed or errored" summary))))))))