Skip to content

Commit

Permalink
Move :output distinct logic to ->config
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed Nov 19, 2024
1 parent d974326 commit 424e731
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
6 changes: 0 additions & 6 deletions src/clojure/lazytest/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@
{:exit-message (str/join \newline (cons "lazytest errors:" errors))
:ok false})

(defn prepare-output [output]
(->> output
(distinct)
(vec)))

(defn validate-opts
"Parse and validate opts.
Expand All @@ -83,5 +78,4 @@
errors (print-errors errors)
:else (-> options
(update :dir (comp not-empty vec concat) arguments)
(update :output prepare-output)
(update :delay #(or % 500))))))
15 changes: 9 additions & 6 deletions src/clojure/lazytest/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(defn lazytest-version [] (str "Lazytest v" @version))

(defn combine-reporters
([reporter] (fn [config m] (reporter config m) (flush) nil))
([reporter] reporter)
([reporter & reporters]
(fn [config m]
(run! (fn [reporter] (reporter config m) (flush) nil)
Expand All @@ -17,23 +17,26 @@
(defn resolve-reporter
[reporter]
(cond
(sequential? reporter) (->> (flatten reporter)
(map resolve-reporter)
(distinct)
(apply combine-reporters))
(qualified-symbol? reporter)
(if-let [r (requiring-resolve reporter)]
(resolve-reporter (var-get r))
(throw (ex-info (str "Cannot find reporter: " reporter)
{:reporter reporter})))
(symbol? reporter) (resolve-reporter (symbol "lazytest.reporters" (name reporter)))
(sequential? reporter) (->> (flatten reporter)
(map resolve-reporter)
(apply combine-reporters))
:else reporter))

(defn ->config [config]
(if (:lazytest.runner/depth config)
config
(let [reporter (resolve-reporter
(or (:output config) 'lazytest.reporters/nested))]
(let [output (or (:output config) 'lazytest.reporters/nested)
output (if (sequential? output) (distinct output) [output])
reporter (resolve-reporter output)]
(-> config
(assoc :lazytest.runner/depth 1)
(assoc :lazytest.runner/suite-history [])
(assoc :output output)
(assoc :reporter reporter)))))
4 changes: 2 additions & 2 deletions src/clojure/lazytest/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
(apply require nses)
nses))

(defn run-impl [{:keys [dir output] :as config}]
(let [config (->config (assoc config :output (not-empty output)))
(defn run-impl [{:keys [dir] :as config}]
(let [config (->config (update config :output not-empty))
nses (require-dirs config dir)]
(run-tests nses config)))

Expand Down
41 changes: 41 additions & 0 deletions test/clojure/lazytest/config_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(ns lazytest.config-test
(:require
[lazytest.config :as sut]
[lazytest.core :refer [defdescribe it expect]]
[lazytest.extensions.matcher-combinators :refer [match?]]))

(defn example-reporter [& _args])

(defdescribe ->config-test
(it "works"
(expect
(match? {:output [:keyword]
:reporter fn?}
(sut/->config {:output :keyword}))))
(it "resolves by default to lazytest.reporters"
(expect
(match? {:output ['dots]
:reporter fn?}
(sut/->config {:output 'dots}))))
(it "resolves other reporters correctly"
(expect
(match? {:output ['lazytest.config-test/example-reporter]
:reporter fn?}
(sut/->config {:output 'lazytest.config-test/example-reporter}))))
(it "resolves multiple reporters"
(expect
(match? {:output ['dots 'lazytest.config-test/example-reporter]
:reporter fn?}
(sut/->config {:output ['dots 'lazytest.config-test/example-reporter]}))))
(it "calls distinct on the input"
(expect
(match? {:output ['lazytest.config-test/example-reporter]
:reporter fn?}
(sut/->config {:output ['lazytest.config-test/example-reporter
'lazytest.config-test/example-reporter]})))
(expect
(match? {:output ['lazytest.config-test/example-reporter 'dots]
:reporter fn?}
(sut/->config {:output ['lazytest.config-test/example-reporter
'dots
'lazytest.config-test/example-reporter]})))))

0 comments on commit 424e731

Please sign in to comment.