From f0025c305f543804d88a72d056864e3c774cc270 Mon Sep 17 00:00:00 2001 From: Jeremiah Coyle Date: Wed, 9 Oct 2024 03:24:16 -0600 Subject: [PATCH 1/5] Add :silence and :banner options --- .gitignore | 1 + .../src/leiningen/test_refresh.clj | 18 +++++++++++-- .../src/com/jakemccrary/test_refresh.clj | 27 +++++++++++-------- version.edn | 2 +- 4 files changed, 34 insertions(+), 14 deletions(-) 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..aac85a8 100644 --- a/lein-test-refresh/src/leiningen/test_refresh.clj +++ b/lein-test-refresh/src/leiningen/test_refresh.clj @@ -17,11 +17,23 @@ (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 project-options [project args] (let [{:keys [notify-command notify-on-success growl - silence quiet report changes-only run-once + banner silence quiet report changes-only run-once focus-flag - with-repl watch-dirs refresh-dirs stack-trace-depth]} (:test-refresh project) + with-repl watch-dirs refresh-dirs stack-trace-depth] + :or {banner :no-supplied-banner}} (:test-refresh project) + banner (if (= banner :no-supplied-banner) + default-banner + banner) 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 +53,8 @@ :nses-and-selectors (#'test/read-args args project) :test-paths (clojure-test-directories project) :quiet quiet + :banner banner + :silence silence :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..6c1c585 100644 --- a/test-refresh/src/com/jakemccrary/test_refresh.clj +++ b/test-refresh/src/com/jakemccrary/test_refresh.clj @@ -62,9 +62,8 @@ (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] + (some-> banner println)) (defn- print-end-message [run-time] (let [date-str (.format (java.text.SimpleDateFormat. "HH:mm:ss.SSS") @@ -166,14 +165,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 [m]) + (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) @@ -284,7 +284,7 @@ (when report (println "Using reporter:" report)) - (when (:quiet options) + (when (or (:quiet options) (:silence options)) (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) + (when-not (:silence options) + (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 (:silence options) ::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 (:silence options) + (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" From d1820ceb0118213ef3813ad592854cd912f563af Mon Sep 17 00:00:00 2001 From: Jeremiah Coyle Date: Wed, 9 Oct 2024 16:43:07 -0600 Subject: [PATCH 2/5] Refine banner logic --- lein-test-refresh/src/leiningen/test_refresh.clj | 12 ++++++------ test-refresh/src/com/jakemccrary/test_refresh.clj | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lein-test-refresh/src/leiningen/test_refresh.clj b/lein-test-refresh/src/leiningen/test_refresh.clj index aac85a8..8fd2074 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])) @@ -29,11 +30,10 @@ (let [{:keys [notify-command notify-on-success growl banner silence quiet report changes-only run-once focus-flag - with-repl watch-dirs refresh-dirs stack-trace-depth] - :or {banner :no-supplied-banner}} (:test-refresh project) - banner (if (= banner :no-supplied-banner) - default-banner - banner) + with-repl watch-dirs refresh-dirs stack-trace-depth]} (:test-refresh project) + banner (if (and banner (not (string/blank? banner))) + banner + (when-not (true? silence) default-banner)) 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) diff --git a/test-refresh/src/com/jakemccrary/test_refresh.clj b/test-refresh/src/com/jakemccrary/test_refresh.clj index 6c1c585..4c94fe7 100644 --- a/test-refresh/src/com/jakemccrary/test_refresh.clj +++ b/test-refresh/src/com/jakemccrary/test_refresh.clj @@ -298,8 +298,7 @@ (when (and with-repl? @monitoring? something-changed?) (println)) - (when-not (:silence options) - (print-banner (:banner options))) + (print-banner (:banner options)) (let [stack-depth (:stack-trace-depth options) was-failed (tracking-failed-tests?) From 1ffbf005fd4fd14a5160fc07681de7bc0b45e9bc Mon Sep 17 00:00:00 2001 From: Jeremiah Coyle Date: Fri, 25 Oct 2024 21:20:07 -0600 Subject: [PATCH 3/5] Add debug mode --- .../src/leiningen/test_refresh.clj | 19 ++++++++++++++----- .../src/com/jakemccrary/test_refresh.clj | 16 ++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lein-test-refresh/src/leiningen/test_refresh.clj b/lein-test-refresh/src/leiningen/test_refresh.clj index 8fd2074..04aa59c 100644 --- a/lein-test-refresh/src/leiningen/test_refresh.clj +++ b/lein-test-refresh/src/leiningen/test_refresh.clj @@ -26,14 +26,23 @@ "Running tests" side-stars)) +(defn- debug-mode-banner [banner] + ;; Needs to be tested on Linux and Windows. + (str "\033[H" ;; Send caret to home position in console + "\033[2J" ;; Clears console (preserving scrollback) + "\033[0;m" ;; Reset escape sequnce to default + (some->> banner (str "\n")))) + (defn project-options [project args] (let [{:keys [notify-command notify-on-success growl - banner silence quiet report changes-only run-once + banner debug quiet report changes-only run-once focus-flag with-repl watch-dirs refresh-dirs stack-trace-depth]} (:test-refresh project) - banner (if (and banner (not (string/blank? banner))) - banner - (when-not (true? silence) default-banner)) + banner (if (true? debug) + (debug-mode-banner banner) + (if (and banner (not (string/blank? banner))) + banner + default-banner)) 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) @@ -54,7 +63,7 @@ :test-paths (clojure-test-directories project) :quiet quiet :banner banner - :silence silence + :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 4c94fe7..f9edcf3 100644 --- a/test-refresh/src/com/jakemccrary/test_refresh.clj +++ b/test-refresh/src/com/jakemccrary/test_refresh.clj @@ -59,9 +59,6 @@ (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 [banner] (some-> banner println)) @@ -169,7 +166,7 @@ "Selects the reporting function based on user specified configuration" [report] (if (= ::no-report report) - (fn silent-report [m]) + (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))))] @@ -273,7 +270,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 +283,7 @@ (when report (println "Using reporter:" report)) - (when (or (:quiet options) (:silence options)) + (when (or (:quiet options) debug-mode?) (defmethod capture-report :begin-test-ns [m])) (loop [tracker (make-change-tracker)] @@ -305,14 +304,15 @@ changed-namespaces (if (:changes-only options) (set (:clojure.tools.namespace.track/load new-tracker)) #{}) - report (if (:silence options) ::no-report report) + 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)] - (when-not (:silence options) + (when-not (and debug-mode? + (-> result :status (not= "Error"))) (print-to-console result)) (reset! run-once-exit-code (if (passed? result) 0 1)) From 91c94eba36c741a2d9579bfa7b51cbf00a993ba3 Mon Sep 17 00:00:00 2001 From: Jeremiah Coyle Date: Sun, 27 Oct 2024 21:43:34 -0600 Subject: [PATCH 4/5] Refactor banner-printing logic --- test-refresh/src/com/jakemccrary/test_refresh.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-refresh/src/com/jakemccrary/test_refresh.clj b/test-refresh/src/com/jakemccrary/test_refresh.clj index f9edcf3..c4f30cc 100644 --- a/test-refresh/src/com/jakemccrary/test_refresh.clj +++ b/test-refresh/src/com/jakemccrary/test_refresh.clj @@ -60,7 +60,8 @@ (clojure.tools.namespace.repl/refresh)) (defn- print-banner [banner] - (some-> banner println)) + (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") From e6276dcc37dcab4f38c4d5d2bba4c29f2e264400 Mon Sep 17 00:00:00 2001 From: Jeremiah Coyle Date: Sun, 27 Oct 2024 21:43:47 -0600 Subject: [PATCH 5/5] Add clear option --- .../src/leiningen/test_refresh.clj | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lein-test-refresh/src/leiningen/test_refresh.clj b/lein-test-refresh/src/leiningen/test_refresh.clj index 04aa59c..727848c 100644 --- a/lein-test-refresh/src/leiningen/test_refresh.clj +++ b/lein-test-refresh/src/leiningen/test_refresh.clj @@ -26,23 +26,22 @@ "Running tests" side-stars)) -(defn- debug-mode-banner [banner] - ;; Needs to be tested on Linux and Windows. - (str "\033[H" ;; Send caret to home position in console - "\033[2J" ;; Clears console (preserving scrollback) - "\033[0;m" ;; Reset escape sequnce to default - (some->> banner (str "\n")))) +(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 - banner debug 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 (if (true? debug) - (debug-mode-banner banner) - (if (and banner (not (string/blank? banner))) - banner - default-banner)) + 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)