From 9ae31ad67fe1c4decfc8a262834085eab8a178db Mon Sep 17 00:00:00 2001 From: Konrad Mrożek <konrad.mrozek@shareablee.com> Date: Thu, 13 Jul 2023 10:04:37 +0000 Subject: [PATCH] Fix not working tests on folder --- clojure/src/test_runner.clj | 77 ++++++++++++++++++++++++++++---------- 1 files changed, 56 insertions(+), 21 deletions(-) diff --git a/clojure/src/test_runner.clj b/clojure/src/test_runner.clj index 648e58a..ed5ab46 100644 --- a/clojure/src/test_runner.clj +++ b/clojure/src/test_runner.clj @@ -9,29 +9,64 @@ (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))))))) -(defn -main [& [test-file]] +(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- 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)))))) -- Gitblit v1.9.3