Konrad Mrożek
2023-07-13 9ae31ad67fe1c4decfc8a262834085eab8a178db
clojure/src/test_runner.clj
@@ -36,24 +36,37 @@
(defmethod emacs-report :default
  [_])
(defn -main  [& [test-file]]
(defn- clj-file? [f]
  (re-matches #"^.*\.cljs?$" (.getName f)))
(defn -main  [& {:strs [-test-file] :or {-test-file "test"}}]
  (binding  [*compile-files* true]
    (compile 'test-runner)
    (let  [test-namespaces (->> (or test-file  "test")
                                (java.io.File.)
                                (file-seq)
                                (filter (memfn isFile))
                                (map (memfn getPath))
                                (map load-file)
                                (map (comp :ns meta))
                                (into #{}))]
      (System/exit (if (pos? (reduce (fn [total-fails n]
                                       (with-redefs [t/report emacs-report]
                                         (let [results  (t/run-tests n)]
                                           (+ total-fails
                                              (:fail results 0)
                                              (:error results 0)))))
                                     0
                                     test-namespaces))
                     1
                     0)))))
    (println "Detecting test files in" -test-file)
    (let [test-files (->> -test-file
                          (java.io.File.)
                          (file-seq)
                          (filter (memfn isFile))
                          (filter clj-file?)
                          (map (memfn getAbsolutePath))
                          (set))]
      (println "Loading test files...")
      (run! load-file test-files)
      (let [test-namespaces (->> (all-ns)
                                 (mapcat ns-publics)
                                 (map (comp meta second))
                                 (filter :test)
                                 (filter (comp test-files :file))
                                 (map :ns)
                                 (set))]
        (println "Running tests on:" (map ns-name test-namespaces))
        (System/exit (if (pos? (reduce (fn [total-fails n]
                                         (with-redefs [t/report emacs-report]
                                           (let [results  (t/run-tests n)]
                                             (+ total-fails
                                                (:fail results 0)
                                                (:error results 0)))))
                                       0
                                       test-namespaces))
                       1
                       0))))))