diff --git a/src/cognitect/test_runner.clj b/src/cognitect/test_runner.clj index 54e147e..db56521 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,19 @@ 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) + (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))))) @@ -91,6 +104,9 @@ ["-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] + ["-o" "--output STRING" "String indicating path to file to write output to."] ["-H" "--test-help" "Display this help message"]]) (defn- help