mrroman
2023-06-06 d417c965ea699e5928583750db98f8dba2b31d2e
clojure/src/test_runner.clj
@@ -9,10 +9,25 @@
(defmulti emacs-report :type)
(defmethod emacs-report :pass
(defmethod emacs-report :fail
  [m]
  (t/with-test-out
    (println "PASS:")))
    (when-let [source-file (some-> t/*testing-vars*
                                   first
                                   meta
                                   :file)]
      (println (str "FAIL:" source-file ":" (:line m) ":" (t/testing-vars-str m) ":" (t/testing-contexts-str) ":" (:message m "FAIL"))))))
(defmethod emacs-report :error
  [m]
  (when-let [source-file (some-> t/*testing-vars*
                                 first
                                 meta
                                 :file)]
    (println (str "ERROR:" source-file ":" (:line m) ":" (t/testing-vars-str m) ":" (t/testing-contexts-str) ":" (:message m "FAIL")))))
(defmethod emacs-report :default
  [_])
(defn -main  [& [test-file]]
  (binding  [*compile-files* true]
@@ -25,4 +40,13 @@
                                (map load-file)
                                (map (comp :ns meta))
                                (into #{}))]
      (run! (fn [n] (t/run-tests n)) 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)))))