Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:paths ["src"]
:deps {org.clojure/tools.namespace {:mvn/version "0.2.11"}
org.clojure/tools.cli {:mvn/version "0.3.5"}
org.clojure/clojure {:mvn/version "1.7.0"}}
org.clojure/clojure {:mvn/version "1.9.0"}}
:aliases {:test {:extra-paths ["test" "dev"]
:extra-deps {org.clojure/test.check {:mvn/version "0.9.0"}}
:main-opts ["-m" "cognitect.test-runner"]}}
Expand Down
30 changes: 23 additions & 7 deletions src/cognitect/test_runner.clj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
[s]
(if (.startsWith s ":") (read-string s) (keyword s)))


(defn- accumulate [m k v]
(update-in m [k] (fnil conj #{}) v))

Expand All @@ -93,6 +92,12 @@
["-e" "--exclude KEYWORD" "Exclude tests with this metadata keyword."
:parse-fn parse-kw
:assoc-fn accumulate]
["-b" "--before SYMBOL" "Symbol indicating the fully qualified name of a specific function to run before tests."
:parse-fn symbol
:assoc-fn accumulate]
["-a" "--after SYMBOL" "Symbol indicating the fully qualified name of a specific function to run after tests."
:parse-fn symbol
:assoc-fn accumulate]
["-H" "--test-help" "Display this help message"]])

(defn- help
Expand All @@ -102,6 +107,14 @@
(println (:summary args))
(println "\nAll options may be repeated multiple times for a logical OR effect."))

(defn before [args]
(doseq [f (-> args :options :before)]
((resolve f))))

(defn after [args]
(doseq [f (-> args :options :after)]
((resolve f))))

(defn -main
"Entry point for the test runner"
[& args]
Expand All @@ -112,9 +125,12 @@
(help args))
(if (-> args :options :test-help)
(help args)
(try
(let [{:keys [fail error]} (test (:options args))]
(System/exit (if (zero? (+ fail error)) 0 1)))
(finally
;; Only called if `test` raises an exception
(shutdown-agents)))))))
(do (before args)
(try
(let [{:keys [fail error]} (test (:options args))]
(after args)
(System/exit (if (zero? (+ fail error)) 0 1)))
(finally
;; Only called if `test` raises an exception
(after args)
(shutdown-agents))))))))