From ace704ae3b92a882e231ee50b3d8e760591844fb Mon Sep 17 00:00:00 2001
From: Noah Bogart <noah.bogart@hey.com>
Date: Mon, 18 Nov 2024 22:30:37 -0500
Subject: [PATCH 1/5] Make :reporter "internal"

---
 src/clojure/lazytest/config.clj          |  2 +-
 src/clojure/lazytest/main.clj            |  3 +--
 src/clojure/lazytest/repl.clj            |  6 +++++-
 src/clojure/lazytest/runner.clj          |  4 ++--
 test/clojure/lazytest/libs_test.clj      |  2 +-
 test/clojure/lazytest/reporters_test.clj | 12 ++++++------
 test/clojure/lazytest/runner_test.clj    |  4 ++--
 7 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/clojure/lazytest/config.clj b/src/clojure/lazytest/config.clj
index 1e9eb69..559d60f 100644
--- a/src/clojure/lazytest/config.clj
+++ b/src/clojure/lazytest/config.clj
@@ -33,7 +33,7 @@
   (if (:lazytest.runner/depth config)
     config
     (let [reporter (resolve-reporter
-                    (or (:reporter config) 'lazytest.reporters/nested))]
+                    (or (:output config) 'lazytest.reporters/nested))]
       (-> config
           (assoc :lazytest.runner/depth 1)
           (assoc :lazytest.runner/suite-history [])
diff --git a/src/clojure/lazytest/main.clj b/src/clojure/lazytest/main.clj
index b9fdc4d..639e75f 100644
--- a/src/clojure/lazytest/main.clj
+++ b/src/clojure/lazytest/main.clj
@@ -47,8 +47,7 @@
     nses))
 
 (defn run-impl [{:keys [dir output] :as config}]
-  (let [output (or (not-empty output) ['lazytest.reporters/nested])
-        config (->config (assoc config :output output :reporter output))
+  (let [config (->config (assoc config :output (not-empty output)))
         nses (require-dirs config dir)]
     (run-tests nses config)))
 
diff --git a/src/clojure/lazytest/repl.clj b/src/clojure/lazytest/repl.clj
index 4d5007e..c475501 100644
--- a/src/clojure/lazytest/repl.clj
+++ b/src/clojure/lazytest/repl.clj
@@ -6,10 +6,11 @@
    [lazytest.runner :as runner]))
 
 (def repl-config
-  {:reporter [r/focused r/results r/summary]})
+  {:output [r/focused r/results r/summary]})
 
 (defn run-tests
   "Runs tests defined in the given namespaces."
+  {:arglists '([namespaces] [namespaces {:keys [output] :as config}])}
   ([namespaces] (run-tests namespaces repl-config))
   ([namespaces config]
    (if (sequential? namespaces)
@@ -18,11 +19,14 @@
 
 (defn run-all-tests
   "Run tests defined in all namespaces."
+  {:arglists '([] [{:keys [output] :as config}])}
   ([] (run-all-tests repl-config))
   ([config]
    (summarize (runner/run-all-tests (->config config)))))
 
 (defn run-test-var
+  "Run test var."
+  {:arglists '([var] [var {:keys [output] :as config}])}
   ([v] (run-test-var v repl-config))
   ([v config]
    (summarize (runner/run-test-var v (->config config)))))
diff --git a/src/clojure/lazytest/runner.clj b/src/clojure/lazytest/runner.clj
index cab6652..a82efe5 100644
--- a/src/clojure/lazytest/runner.clj
+++ b/src/clojure/lazytest/runner.clj
@@ -5,7 +5,7 @@
                              run-afters run-before-eachs run-befores]]
    [lazytest.filter :refer [filter-tree]]
    [lazytest.find :refer [find-suite find-var-test-value]]
-   [lazytest.reporters :as r :refer [nested report]]
+   [lazytest.reporters :as r :refer [report]]
    [lazytest.suite :as s :refer [suite suite-result suite?]]
    [lazytest.test-case :refer [try-test-case]]))
 
@@ -109,7 +109,7 @@
 
 (defn run-tests
   "Runs tests defined in the given namespaces. Applies filters in config."
-  ([namespaces] (run-tests namespaces (->config {:reporter nested})))
+  ([namespaces] (run-tests namespaces (->config nil)))
   ([namespaces config]
    (-> (apply find-suite namespaces)
        (filter-and-run config))))
diff --git a/test/clojure/lazytest/libs_test.clj b/test/clojure/lazytest/libs_test.clj
index 46c94ac..b61e41c 100644
--- a/test/clojure/lazytest/libs_test.clj
+++ b/test/clojure/lazytest/libs_test.clj
@@ -29,4 +29,4 @@
           (match? {:total 80 :pass 80 :fail 0}
                   (summarize
                    (lr/run-tests [(the-ns honeysql-ns)]
-                                 (->config {:reporter ['lazytest.reporters/quiet]})))))))))
+                                 (->config {:output ['lazytest.reporters/quiet]})))))))))
diff --git a/test/clojure/lazytest/reporters_test.clj b/test/clojure/lazytest/reporters_test.clj
index 79e7950..c22ae19 100644
--- a/test/clojure/lazytest/reporters_test.clj
+++ b/test/clojure/lazytest/reporters_test.clj
@@ -35,7 +35,7 @@
 (defn ->passing [& {:as extra}]
   (-> (tc/test-case {:doc "example test-case"
                      :body (fn [] true)})
-      (runner/run-tree (->config {:reporter [(constantly nil)]}))
+      (runner/run-tree (->config {:output [(constantly nil)]}))
       (merge extra)))
 
 (defn ->failing [& {:as extra}]
@@ -43,7 +43,7 @@
                      :body (fn [] (expect (= 1 2) (if (contains? extra :message)
                                                     (:message extra)
                                                     "failing")))})
-      (runner/run-tree (->config {:reporter [(constantly nil)]}))
+      (runner/run-tree (->config {:output [(constantly nil)]}))
       (assoc :file "example.clj")
       (assoc :line 1)
       (merge (dissoc extra :message))))
@@ -55,7 +55,7 @@
                          :line 1})]
     (-> (tc/test-case {:doc "example test-case"
                        :body (fn [] (throw thrown))})
-        (runner/run-tree (->config {:reporter [(constantly nil)]})))))
+        (runner/run-tree (->config {:output [(constantly nil)]})))))
 
 (defn stub-stack-trace
   [_ex]
@@ -348,7 +348,7 @@
                     (suite {:type :lazytest/ns
                             :nses [*ns*]
                             :children [test-suite]})
-                    (->config {:reporter (constantly nil)}))
+                    (->config {:output (constantly nil)}))
           suite-results (assoc test-suite :type :end-test-run :results results)]
       (expect (match? (re-compile "Top 1 slowest test namespaces.*Top 1 slowest test vars" :dotall)
                       (-> (sut/profile nil suite-results)
@@ -361,10 +361,10 @@
   (it "uses the var if given no doc string"
     (expect (= "  defdescribe-no-doc\n    √ works\n\n"
                (-> (runner/run-test-var #'defdescribe-no-doc
-                                        (->config {:reporter sut/nested*}))
+                                        (->config {:output sut/nested*}))
                    (with-out-str-no-color)))))
   (it "uses the doc string when available"
     (expect (= "  cool docs\n    √ works\n\n"
                (-> (runner/run-test-var #'defdescribe-with-doc
-                                        (->config {:reporter sut/nested*}))
+                                        (->config {:output sut/nested*}))
                    (with-out-str-no-color))))))
diff --git a/test/clojure/lazytest/runner_test.clj b/test/clojure/lazytest/runner_test.clj
index 40edb9f..fbfa8c6 100644
--- a/test/clojure/lazytest/runner_test.clj
+++ b/test/clojure/lazytest/runner_test.clj
@@ -20,7 +20,7 @@
                             ""
                             ""])
                  (-> (sut/run-test-suite test-suite
-                       (->config {:reporter reporters/nested*}))
+                       (->config {:output reporters/nested*}))
                      (with-out-str-no-color)))))))
 
 (defdescribe run-test-var-test
@@ -32,5 +32,5 @@
                     ""
                     ""])
          (-> (sut/run-test-var #'run-test-suite-test
-               (->config {:reporter reporters/nested*}))
+               (->config {:output reporters/nested*}))
              (with-out-str-no-color))))))

From d974326e500275031272386ffbcb3cffa7af171c Mon Sep 17 00:00:00 2001
From: Noah Bogart <noah.bogart@hey.com>
Date: Mon, 18 Nov 2024 23:00:23 -0500
Subject: [PATCH 2/5] Move --output parsing logic to ->config

---
 src/clojure/lazytest/cli.clj    | 8 ++------
 src/clojure/lazytest/config.clj | 3 +--
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/clojure/lazytest/cli.clj b/src/clojure/lazytest/cli.clj
index 9202453..658dfee 100644
--- a/src/clojure/lazytest/cli.clj
+++ b/src/clojure/lazytest/cli.clj
@@ -29,12 +29,8 @@
     :parse-fn #(keyword (if (str/starts-with? % ":") (subs % 1) %))
     :assoc-fn update-set]
    [nil "--output SYMBOL" "Output format. Can be given multiple times. (Defaults to \"nested\".)"
-    :parse-fn read-string
-    :assoc-fn (fn [args k v]
-                (let [output (if (qualified-symbol? v)
-                               v
-                               (symbol "lazytest.reporters" (name v)))]
-                  (update-vec args k output)))]
+    :parse-fn symbol
+    :assoc-fn update-vec]
    [nil "--md FILE" "Run doctests for given markdown file. Can be given multiple times."
     :parse-fn io/file
     :assoc-fn update-vec]
diff --git a/src/clojure/lazytest/config.clj b/src/clojure/lazytest/config.clj
index 559d60f..ba95ba8 100644
--- a/src/clojure/lazytest/config.clj
+++ b/src/clojure/lazytest/config.clj
@@ -22,8 +22,7 @@
       (resolve-reporter (var-get r))
       (throw (ex-info (str "Cannot find reporter: " reporter)
                       {:reporter reporter})))
-    (symbol? reporter) (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))

From 0911a97fa9e146f477031649bed13f297fa76658 Mon Sep 17 00:00:00 2001
From: Noah Bogart <noah.bogart@hey.com>
Date: Mon, 18 Nov 2024 23:42:59 -0500
Subject: [PATCH 3/5] Move :output distinct logic to ->config

---
 src/clojure/lazytest/cli.clj          |  6 ----
 src/clojure/lazytest/config.clj       | 13 +++++----
 src/clojure/lazytest/main.clj         |  4 +--
 test/clojure/lazytest/config_test.clj | 41 +++++++++++++++++++++++++++
 4 files changed, 51 insertions(+), 13 deletions(-)
 create mode 100644 test/clojure/lazytest/config_test.clj

diff --git a/src/clojure/lazytest/cli.clj b/src/clojure/lazytest/cli.clj
index 658dfee..9656c93 100644
--- a/src/clojure/lazytest/cli.clj
+++ b/src/clojure/lazytest/cli.clj
@@ -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.
 
@@ -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))))))
diff --git a/src/clojure/lazytest/config.clj b/src/clojure/lazytest/config.clj
index ba95ba8..34bde8c 100644
--- a/src/clojure/lazytest/config.clj
+++ b/src/clojure/lazytest/config.clj
@@ -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)))))
diff --git a/src/clojure/lazytest/main.clj b/src/clojure/lazytest/main.clj
index 639e75f..f519bc6 100644
--- a/src/clojure/lazytest/main.clj
+++ b/src/clojure/lazytest/main.clj
@@ -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)))
 
diff --git a/test/clojure/lazytest/config_test.clj b/test/clojure/lazytest/config_test.clj
new file mode 100644
index 0000000..a455d48
--- /dev/null
+++ b/test/clojure/lazytest/config_test.clj
@@ -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]})))))

From baca398e027c447567147e622ae38161d99c58b8 Mon Sep 17 00:00:00 2001
From: Noah Bogart <noah.bogart@hey.com>
Date: Mon, 18 Nov 2024 23:52:08 -0500
Subject: [PATCH 4/5] Remove unnecessary update

---
 src/clojure/lazytest/main.clj | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/clojure/lazytest/main.clj b/src/clojure/lazytest/main.clj
index f519bc6..71ceb33 100644
--- a/src/clojure/lazytest/main.clj
+++ b/src/clojure/lazytest/main.clj
@@ -47,7 +47,7 @@
     nses))
 
 (defn run-impl [{:keys [dir] :as config}]
-  (let [config (->config (update config :output not-empty))
+  (let [config (->config config)
         nses (require-dirs config dir)]
     (run-tests nses config)))
 

From 7a7a1d6e51a9f9ba0a0ea9af2ff01d911f585b9d Mon Sep 17 00:00:00 2001
From: Noah Bogart <noah.bogart@hey.com>
Date: Tue, 19 Nov 2024 13:42:51 -0500
Subject: [PATCH 5/5] Fix namespace filtering

---
 src/clojure/lazytest/filter.clj     |  8 ++++----
 src/clojure/lazytest/main.clj       | 21 +++++++--------------
 test/clojure/lazytest/find_test.clj |  3 +--
 3 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/src/clojure/lazytest/filter.clj b/src/clojure/lazytest/filter.clj
index cb09f1d..ba725b0 100644
--- a/src/clojure/lazytest/filter.clj
+++ b/src/clojure/lazytest/filter.clj
@@ -87,10 +87,10 @@
   [ns-suite config]
   (let [var-filter (map (comp symbol namespace) (:var-filter config))
         ns-filter (not-empty (into #{} (concat var-filter (:ns-filter config))))]
-    (when (and ns-filter
-               (ns-filter (:doc ns-suite)))
-      (filter-suite ns-suite config))
-    (filter-suite ns-suite config)))
+    (if ns-filter
+      (when (ns-filter (:doc ns-suite))
+        (filter-suite ns-suite config))
+      (filter-suite ns-suite config))))
 
 (defmethod filter-tree :lazytest/run
   filter-tree--lazytest-run
diff --git a/src/clojure/lazytest/main.clj b/src/clojure/lazytest/main.clj
index 71ceb33..41db606 100644
--- a/src/clojure/lazytest/main.clj
+++ b/src/clojure/lazytest/main.clj
@@ -3,7 +3,6 @@
   (:gen-class)
   (:require
    [clojure.java.io :as io]
-   [clojure.set :as set]
    [clojure.tools.namespace.file :refer [read-file-ns-decl]]
    [clojure.tools.namespace.find :refer [find-sources-in-dir]]
    [lazytest.cli :refer [validate-opts]]
@@ -13,18 +12,12 @@
    [lazytest.runner :refer [run-tests]]
    [lazytest.watch :as watch]))
 
-(defn find-ns-decls [config dirs]
-  (let [var-filter-nses (->> (:var-filter config)
-                             (map (comp symbol namespace))
-                             (into #{}))
-        ns-filter (or (not-empty (set/union (:ns-filter config) var-filter-nses))
-                      any?)]
-    (into []
-          (comp (mapcat find-sources-in-dir)
-                (keep read-file-ns-decl)
-                (keep second)
-                (filter ns-filter))
-          dirs)))
+(defn find-ns-decls [dirs]
+  (into []
+        (comp (mapcat find-sources-in-dir)
+              (keep read-file-ns-decl)
+              (keep second))
+        dirs))
 
 (defn add-md-tests
   [config dirs]
@@ -39,7 +32,7 @@
 (defn require-dirs [config dir]
   (let [dirs (map io/file (or dir #{"test"}))
         md-nses (add-md-tests config dirs)
-        nses (into (find-ns-decls config dirs)
+        nses (into (find-ns-decls dirs)
                    md-nses)]
     (when (empty? nses)
       (throw (ex-info "No namespaces to run" {:dir dir})))
diff --git a/test/clojure/lazytest/find_test.clj b/test/clojure/lazytest/find_test.clj
index ab73e07..9ddc523 100644
--- a/test/clojure/lazytest/find_test.clj
+++ b/test/clojure/lazytest/find_test.clj
@@ -16,8 +16,7 @@
                   (vreset! output (with-out-str-data-map
                                     (main/run ["--dir" "corpus/find_tests"
                                                "--output" "nested*"]))))
-                 (after (remove-ns 'find-tests.examples)
-                        (vreset! output nil))]}
+                 (after (vreset! output nil))]}
       (it "runs all suites"
         (expect
           (match?