From 4708279dcbd5f346a14afaca57e1cf6a8c213166 Mon Sep 17 00:00:00 2001 From: Dominic Monroe Date: Wed, 28 Mar 2018 10:23:53 +0100 Subject: [PATCH 1/2] Add support for alternative outputs --- src/cognitect/test_runner.clj | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cognitect/test_runner.clj b/src/cognitect/test_runner.clj index 54e147e..b6dacd6 100644 --- a/src/cognitect/test_runner.clj +++ b/src/cognitect/test_runner.clj @@ -48,6 +48,12 @@ (alter-meta! var #(-> % (assoc :test (::test %)) (dissoc ::test))))))) + +(defn- require-and-resolve + [sym] + (require (symbol (namespace sym))) + (resolve sym)) + (defn test [options] (let [dirs (or (:dir options) @@ -55,12 +61,16 @@ nses (->> dirs (map io/file) (mapcat find/find-namespaces-in-dir)) - nses (filter (ns-filter options) nses)] + nses (filter (ns-filter options) nses) + with-output (require-and-resolve + (:with-output options 'clojure.test/with-test-out))] + (when (not with-output) + (throw (ex-info "Specified with-output not found" {}))) (println (format "\nRunning tests in %s" dirs)) (dorun (map require nses)) (try (filter-vars! nses (var-filter options)) - (apply test/run-tests nses) + (eval `(~with-output (apply test/run-tests (quote ~nses)))) (finally (restore-vars! nses))))) @@ -91,6 +101,8 @@ ["-e" "--exclude KEYWORD" "Exclude tests with this metadata keyword." :parse-fn parse-kw :assoc-fn accumulate] + ["-w" "--with-output SYMBOL" "Symbol indicating the with output wrapper." + :parse-fn symbol] ["-H" "--test-help" "Display this help message"]]) (defn- help From 3228fb6cf5df0212be90bf97288944bd29e25bee Mon Sep 17 00:00:00 2001 From: Dominic Monroe Date: Wed, 28 Mar 2018 10:31:50 +0100 Subject: [PATCH 2/2] Add option to write test-out to file This enables writing JUnit output to a file, for CI purposes. --- src/cognitect/test_runner.clj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cognitect/test_runner.clj b/src/cognitect/test_runner.clj index b6dacd6..db56521 100644 --- a/src/cognitect/test_runner.clj +++ b/src/cognitect/test_runner.clj @@ -70,7 +70,10 @@ (dorun (map require nses)) (try (filter-vars! nses (var-filter options)) - (eval `(~with-output (apply test/run-tests (quote ~nses)))) + (binding [test/*test-out* (if (:output options) + (java.io.FileWriter. (:output options)) + test/*test-out*)] + (eval `(~with-output (apply test/run-tests (quote ~nses))))) (finally (restore-vars! nses))))) @@ -103,6 +106,7 @@ :assoc-fn accumulate] ["-w" "--with-output SYMBOL" "Symbol indicating the with output wrapper." :parse-fn symbol] + ["-o" "--output STRING" "String indicating path to file to write output to."] ["-H" "--test-help" "Display this help message"]]) (defn- help