diff --git a/src/clojure/lazytest/reporters.clj b/src/clojure/lazytest/reporters.clj index 40f0d25..df844be 100644 --- a/src/clojure/lazytest/reporters.clj +++ b/src/clojure/lazytest/reporters.clj @@ -410,9 +410,11 @@ (count slowest-vars) (double (/ var-duration 1e9)) (double (* (/ var-duration total-duration) 100)))) - (println (->> (for [suite slowest-vars] + (println (->> (for [suite slowest-vars + :let [ns (some-> suite :source :var symbol namespace) + id (str ns (when ns "/") (s/identifier suite))]] (format " %s %.5f seconds" - (s/identifier suite) + id (double (/ (:lazytest.runner/duration suite) 1e9)))) (str/join \newline))) (flush))) diff --git a/src/clojure/lazytest/runner.clj b/src/clojure/lazytest/runner.clj index 71e310d..0061696 100644 --- a/src/clojure/lazytest/runner.clj +++ b/src/clojure/lazytest/runner.clj @@ -22,8 +22,8 @@ (let [id (:doc suite) start (System/nanoTime) config (-> config - (update :lazytest.runner/depth #(if id (inc %) %)) - (update :lazytest.runner/suite-history conj suite)) + (update ::depth #(if id (inc %) %)) + (update ::suite-history conj suite)) f (if-let [around-fn (combine-arounds suite)] #(let [ret (volatile! nil) tests (propagate-eachs suite %)] @@ -34,8 +34,8 @@ results (vec (keep f (:children suite))) duration (double (- (System/nanoTime) start))] (-> (suite-result suite results) - (assoc :lazytest.runner/source-type source-type) - (assoc :lazytest.runner/duration duration)))) + (assoc ::source-type source-type) + (assoc ::duration duration)))) (defmethod run-tree :lazytest/run run-test--lazytest-run diff --git a/test/clojure/lazytest/reporters_test.clj b/test/clojure/lazytest/reporters_test.clj index 3c50f6b..f9e0d68 100644 --- a/test/clojure/lazytest/reporters_test.clj +++ b/test/clojure/lazytest/reporters_test.clj @@ -6,9 +6,12 @@ [lazytest.core :refer [->ex-failed defdescribe describe expect expect-it it]] [lazytest.reporters :as sut] [lazytest.runner :as runner] - [lazytest.suite :as s] + [lazytest.suite :as s :refer [suite]] [lazytest.test-case :as tc] - [lazytest.test-utils :refer [with-out-str-no-color]])) + [lazytest.test-utils :refer [with-out-str-no-color]] + [lazytest.extensions.matcher-combinators :refer [match?]]) + (:import + [java.util.regex Pattern])) (set! *warn-on-reflection* true) @@ -31,37 +34,29 @@ :children results}) (defn ->passing [& {:as extra}] - (-> (tc/test-case-result - :pass - (runner/prep-test-case - (tc/test-case {:doc "example test-case" - :body (fn [])}))) + (-> (tc/test-case {:doc "example test-case" + :body (fn [] true)}) + (runner/run-tree (->config {:reporter [(constantly nil)]})) (merge extra))) (defn ->failing [& {:as extra}] - (let [data (merge {:file "example.clj" - :line 1 - :message "failing" - :evaluated (list = 1 2) - :actual false} - extra) - thrown (->ex-failed '() (= 1 2) data)] - (tc/test-case-result - :fail (runner/prep-test-case - (tc/test-case {:doc "example test-case" - :body (fn [])})) - thrown))) + (-> (tc/test-case {:doc "example test-case" + :body (fn [] (expect (= 1 2) (if (contains? extra :message) + (:message extra) + "failing")))}) + (runner/run-tree (->config {:reporter [(constantly nil)]})) + (assoc :file "example.clj") + (assoc :line 1) + (merge (dissoc extra :message)))) (defn ->erroring [& _] (let [thrown (ex-info "deliberate error" {:ex :info :file "example.clj" :line 1})] - (tc/test-case-result - :fail (runner/prep-test-case - (tc/test-case {:doc "example test-case" - :body (fn [])})) - thrown))) + (-> (tc/test-case {:doc "example test-case" + :body (fn [] (throw thrown))}) + (runner/run-tree (->config {:reporter [(constantly nil)]}))))) (defn stub-stack-trace [_ex] @@ -345,6 +340,21 @@ (expect (= (* 2 depth) (- (count out) (count (str/triml out))))))))) +(defdescribe profile-test + (it "prints the right times" + (let [test-suite (-> (describe "suite" + (it "it" (expect (= 2 1)))) + (assoc :type :lazytest/var :var #'profile-test)) + results (runner/run-test-suite + (suite {:type :lazytest/ns + :nses [*ns*] + :children [test-suite]}) + (->config {:reporter (constantly nil)})) + suite-results (assoc test-suite :type :end-test-run :results results)] + (expect (match? (Pattern/compile "Top 1 slowest test namespaces.*Top 1 slowest test vars" Pattern/DOTALL) + (-> (sut/profile nil suite-results) + (with-out-str-no-color))))))) + (defdescribe defdescribe-no-doc nil (it "works" nil)) (defdescribe defdescribe-with-doc "cool docs" (it "works" nil))