diff --git a/eftest/project.clj b/eftest/project.clj index 7222d23..fbf4608 100644 --- a/eftest/project.clj +++ b/eftest/project.clj @@ -3,10 +3,10 @@ :url "https://github.com/weavejester/eftest" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.7.0"] + :dependencies [[org.clojure/clojure "1.9.0"] [org.clojure/tools.namespace "1.3.0"] [progrock "0.1.2"] - [io.aviso/pretty "1.3"] + [org.clj-commons/pretty "2.6.0"] [mvxcvi/puget "1.3.4"]] :plugins [[lein-eftest "0.6.0"]] :aliases {"test-all" diff --git a/eftest/src/eftest/report/pretty.clj b/eftest/src/eftest/report/pretty.clj index 3f02273..1e90f32 100644 --- a/eftest/src/eftest/report/pretty.clj +++ b/eftest/src/eftest/report/pretty.clj @@ -2,9 +2,9 @@ "A test reporter with an emphasis on pretty formatting." (:require [clojure.test :as test] [clojure.data :as data] - [io.aviso.ansi :as ansi] - [io.aviso.exception :as exception] - [io.aviso.repl :as repl] + [clj-commons.ansi :as ansi] + [clj-commons.format.exceptions :as exception] + [clj-commons.pretty.repl :as repl] [puget.printer :as puget] [fipp.engine :as fipp] [eftest.output-capture :as capture] @@ -13,37 +13,43 @@ (def ^:dynamic *fonts* "The ANSI codes to use for reporting on tests." - {:exception ansi/red-font - :reset ansi/reset-font - :message ansi/italic-font - :property ansi/bold-font - :source ansi/italic-font - :function-name ansi/blue-font - :clojure-frame ansi/white-font - :java-frame ansi/reset-font - :omitted-frame ansi/reset-font - :pass ansi/green-font - :fail ansi/red-font - :error ansi/red-font - :divider ansi/yellow-font}) + {:exception :red + :message :italic + :property :bold + :source :italic + :function-name :blue + :clojure-frame :white + :java-frame nil + :omitted-frame nil + :pass :green + :fail :red + :error :red + :divider :yellow}) (def ^:dynamic *divider* "The divider to use between test failure and error reports." "\n") -(defn- testing-scope-str [{:keys [file line]}] +(defn- testing-scope-str + "Produce a composed string identifying the testing path, scope, and file and line if known." + [{:keys [file line]}] (let [[ns scope] report/*testing-path*] - (str + (list (cond (keyword? scope) - (str (:clojure-frame *fonts*) (ns-name ns) (:reset *fonts*) " during " - (:function-name *fonts*) scope (:reset *fonts*)) + (list + [(:clojure-frame *fonts*) (ns-name ns)] + " during " + [(:function-name *fonts*) scope]) (var? scope) - (str (:clojure-frame *fonts*) (ns-name ns) "/" - (:function-name *fonts*) (:name (meta scope)) (:reset *fonts*))) + [(:clojure-frame *fonts*) (ns-name ns) "/" + [(:function-name *fonts*) (:name (meta scope))]]) (when (or file line) - (str " (" (:source *fonts*) file ":" line (:reset *fonts*) ")"))))) + (list + " (" + [(:source *fonts*) file ":" line] + ")"))))) (defn- diff-all [expected actuals] (map vector actuals (map #(take 2 (data/diff expected %)) actuals))) @@ -94,12 +100,13 @@ (print-stacktrace actual))) (defn- print-output [output] - (let [c (:divider *fonts*) - r (:reset *fonts*)] + (let [divider (:divider *fonts*)] (when-not (str/blank? output) - (println (str c "---" r " Test output " c "---" r)) - (println (str/trim-newline output)) - (println (str c "-------------------" r))))) + (ansi/pcompose [divider "---"] " Test output " [divider "---"] + \n + (str/trim-newline output) + \n + [divider "-------------------"])))) (defmulti report "A reporting function compatible with clojure.test. Uses ANSI colors and @@ -115,7 +122,7 @@ (test/with-test-out (test/inc-report-counter :fail) (print *divider*) - (println (str (:fail *fonts*) "FAIL" (:reset *fonts*) " in") (testing-scope-str m)) + (ansi/pcompose [(:fail *fonts*) "FAIL"] " in " (testing-scope-str m)) (when (seq test/*testing-contexts*) (println (test/testing-contexts-str))) (when message (println message)) (if (and (sequential? expected) @@ -128,7 +135,7 @@ (test/with-test-out (test/inc-report-counter :error) (print *divider*) - (println (str (:error *fonts*) "ERROR" (:reset *fonts*) " in") (testing-scope-str m)) + (ansi/pcompose [(:error *fonts*) "ERROR"] " in " (testing-scope-str m)) (when (seq test/*testing-contexts*) (println (test/testing-contexts-str))) (when message (println message)) (error-report m) @@ -143,17 +150,16 @@ (defmethod report :long-test [{:keys [duration] :as m}] (test/with-test-out (print *divider*) - (println (str (:fail *fonts*) "LONG TEST" (:reset *fonts*) " in") (testing-scope-str m)) + (ansi/pcompose [(:fail *fonts*) "LONG TEST"] " in " (testing-scope-str m)) (when duration (println "Test took" (format-interval duration) "seconds to run")))) (defmethod report :summary [{:keys [test pass fail error duration]}] (let [total (+ pass fail error) color (if (= pass total) (:pass *fonts*) (:error *fonts*))] (test/with-test-out - (print *divider*) - (println "Ran" test "tests in" (format-interval duration)) - (println (str color - total " " (pluralize "assertion" total) ", " - fail " " (pluralize "failure" fail) ", " - error " " (pluralize "error" error) "." - (:reset *fonts*)))))) + (ansi/pcompose *divider*) + "Ran " test " tests in" (format-interval duration) + [color + total " " (pluralize "assertion" total) ", " + fail " " (pluralize "failure" fail) ", " + error " " (pluralize "error" error) "."]))) diff --git a/eftest/src/eftest/report/progress.clj b/eftest/src/eftest/report/progress.clj index d1981d4..12af005 100644 --- a/eftest/src/eftest/report/progress.clj +++ b/eftest/src/eftest/report/progress.clj @@ -1,6 +1,7 @@ (ns eftest.report.progress "A test reporter with a progress bar." - (:require [clojure.test :as test] + (:require [clj-commons.ansi :as ansi] + [clojure.test :as test] [eftest.report :as report] [eftest.report.pretty :as pretty] [progrock.core :as prog])) @@ -8,11 +9,9 @@ (def ^:private clear-line (apply str "\r" (repeat 80 " "))) (defn- colored-format [state] - (str ":progress/:total :percent% [" - (if state - (str (pretty/*fonts* state) ":bar" (pretty/*fonts* :reset)) - ":bar") - "] ETA: :remaining")) + (ansi/compose ":progress/:total :percent% [" + [(when state (pretty/*fonts* state)) ":bar"] + "] ETA: :remaining")) (defn- print-progress [{:keys [bar state]}] (prog/print bar {:format (colored-format state)}))