Konrad Mrożek
2023-06-22 f5c51800f90878d1318ea54b2df35d7755170738
Improved detection of test namespaces
1 files added
1 files modified
47 ■■■■■ changed files
.gitignore 3 ●●●●● patch | view | raw | blame | history
clojure/src/test_runner.clj 44 ●●●●● patch | view | raw | blame | history
.gitignore
New file
@@ -0,0 +1,3 @@
.clj-kondo
.cpcache
.lsp
clojure/src/test_runner.clj
@@ -39,21 +39,29 @@
(defn -main  [& [test-file]]
  (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)))))
    (let [test-files (->> (or test-file  "test")
                          (java.io.File.)
                          (file-seq)
                          (filter (memfn isFile))
                          (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))))))