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 0911a97
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 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))))))
13 changes: 8 additions & 5 deletions src/clojure/lazytest/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 0911a97

Please sign in to comment.