diff --git a/.gitignore b/.gitignore index ffcdaea..9f141e1 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ pom.xml.asc .cpcache .clj-kondo/cache +test-refresh/.clj-kondo/.cache diff --git a/lein-test-refresh/src/leiningen/test_refresh.clj b/lein-test-refresh/src/leiningen/test_refresh.clj index 764bd0b..727848c 100644 --- a/lein-test-refresh/src/leiningen/test_refresh.clj +++ b/lein-test-refresh/src/leiningen/test_refresh.clj @@ -1,5 +1,6 @@ (ns leiningen.test-refresh - (:require [leiningen.test :as test] + (:require [clojure.string :as string] + [leiningen.test :as test] [leiningen.core.project :as project] [leiningen.core.eval :as eval])) @@ -17,11 +18,30 @@ (vec (concat (:test-path project []) (:test-paths project [])))) +(def ^:private top-stars (apply str (repeat 45 "*"))) +(def ^:private side-stars (apply str (repeat 15 "*"))) +(def ^:private default-banner (str top-stars + "\n" + side-stars + "Running tests" + side-stars)) + +(defn- resolve-banner [banner clear debug] + (let [banner (or banner default-banner)] + (if (or (true? clear) + (and debug + (not (false? clear)))) + (str "\033[H" ;; Send caret to home position in console + "\033[2J" ;; Clears console (preserving scrollback) + (when-not (string/blank? banner) (str "\n" banner))) + banner))) + (defn project-options [project args] (let [{:keys [notify-command notify-on-success growl - silence quiet report changes-only run-once + banner debug clear quiet report changes-only run-once focus-flag with-repl watch-dirs refresh-dirs stack-trace-depth]} (:test-refresh project) + banner (resolve-banner banner clear debug) growl? (or (some #{:growl ":growl" "growl"} args) growl) changes-only (or (some #{:changes-only ":changes-only" "changes-only"} args) changes-only) run-once? (or (some #{:run-once ":run-once" "run-once"} args) run-once) @@ -41,6 +61,8 @@ :nses-and-selectors (#'test/read-args args project) :test-paths (clojure-test-directories project) :quiet quiet + :banner banner + :debug debug :report report :run-once run-once? :with-repl with-repl? diff --git a/test-refresh/src/com/jakemccrary/test_refresh.clj b/test-refresh/src/com/jakemccrary/test_refresh.clj index 8517517..c4f30cc 100644 --- a/test-refresh/src/com/jakemccrary/test_refresh.clj +++ b/test-refresh/src/com/jakemccrary/test_refresh.clj @@ -59,12 +59,9 @@ (defn- refresh-environment [] (clojure.tools.namespace.repl/refresh)) -(def ^:private top-stars (apply str (repeat 45 "*"))) -(def ^:private side-stars (apply str (repeat 15 "*"))) - -(defn- print-banner [] - (println top-stars) - (println side-stars "Running tests" side-stars)) +(defn- print-banner [banner] + (when (and banner (not (string/blank? banner))) + (println banner))) (defn- print-end-message [run-time] (let [date-str (.format (java.text.SimpleDateFormat. "HH:mm:ss.SSS") @@ -166,14 +163,15 @@ selectors)] ns))) - (defn- select-reporting-fn "Selects the reporting function based on user specified configuration" [report] - (when report (require (symbol (namespace (symbol report))))) - (let [resolved-report (when report (let [rr (resolve (symbol report))] - (if rr rr (println "Unable to locate report method:" report))))] - (if resolved-report resolved-report capture-report))) + (if (= ::no-report report) + (fn silent-report [report]) + (do (when report (require (symbol (namespace (symbol report))))) + (let [resolved-report (when report (let [rr (resolve (symbol report))] + (if rr rr (println "Unable to locate report method:" report))))] + (if resolved-report resolved-report capture-report))))) (defn run-selected-tests [stack-depth test-paths selectors report namespaces-to-run] (let [test-namespaces (namespaces-in-directories test-paths) @@ -273,7 +271,9 @@ monitoring? (atom false) do-not-monitor-keystrokes? (:do-not-monitor-keystrokes options false) - keystroke-pressed (atom nil)] + keystroke-pressed (atom nil) + debug-mode? (:debug options) + test-paths (if debug-mode? [] test-paths)] (vreset! focus-flag (or (:focus-flag options) :test-refresh/focus)) @@ -284,7 +284,7 @@ (when report (println "Using reporter:" report)) - (when (:quiet options) + (when (or (:quiet options) debug-mode?) (defmethod capture-report :begin-test-ns [m])) (loop [tracker (make-change-tracker)] @@ -298,19 +298,24 @@ (when (and with-repl? @monitoring? something-changed?) (println)) - (print-banner) + (print-banner (:banner options)) (let [stack-depth (:stack-trace-depth options) was-failed (tracking-failed-tests?) changed-namespaces (if (:changes-only options) (set (:clojure.tools.namespace.track/load new-tracker)) #{}) + report (if debug-mode? ::no-report report) result (run-tests stack-depth test-paths selectors report changed-namespaces) ;; tests need to be run once a failed test is resolved result (if (and was-failed (passed? result)) (run-tests stack-depth test-paths selectors report) result)] - (print-to-console result) + + (when-not (and debug-mode? + (-> result :status (not= "Error"))) + (print-to-console result)) + (reset! run-once-exit-code (if (passed? result) 0 1)) (when (should-notify? result) (when growl? diff --git a/version.edn b/version.edn index 5ec9f53..8ea81e3 100644 --- a/version.edn +++ b/version.edn @@ -1 +1 @@ -"0.25.1-SNAPSHOT" +"0.26.0"