From 2c210a37c68304ec9111007af34ce6309dd0701c Mon Sep 17 00:00:00 2001 From: Konrad Mrożek <konrad.mrozek@shareablee.com> Date: Thu, 15 Jun 2023 09:03:25 +0000 Subject: [PATCH] Support for expected and actual --- clojure/src/test_runner.clj | 37 ++++++++++++++++++++++++++++++++++--- 1 files changed, 34 insertions(+), 3 deletions(-) diff --git a/clojure/src/test_runner.clj b/clojure/src/test_runner.clj index 2868c26..d7c5118 100644 --- a/clojure/src/test_runner.clj +++ b/clojure/src/test_runner.clj @@ -9,10 +9,32 @@ (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"))) + (println (str "FAIL-CONTINUE:EXPECTED:" (pr-str (:expected m)))) + (println (str "FAIL-CONTINUE:ACTUAL:" (pr-str (:actual m))))))) + +(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"))) + (println (str "ERROR-CONTINUE:EXPECTED:" (pr-str (:expected m)))) + (println (str "ERROR-CONTINUE:ACTUAL:" + (if (instance? Throwable (:actual m)) + (ex-message (:actual m)) + (pr-str (:actual m))))))) + +(defmethod emacs-report :default + [_]) (defn -main [& [test-file]] (binding [*compile-files* true] @@ -25,4 +47,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))))) -- Gitblit v1.9.3