Back

*report-counters* (clj)

(source)

variable

Examples

babashka/babashka
(ns httpkit.client-test
  (:require [cheshire.core :as json]
            [clojure.test :refer [deftest is testing #_*report-counters*]]
            [org.httpkit.client :as client]))

#_(defmethod clojure.test/report :end-test-var [_m]
  (let [{:keys [:fail :error]} @*report-counters*]
    (when (and (= "true" (System/getenv "BABASHKA_FAIL_FAST"))
               (or (pos? fail) (pos? error)))
      (println "=== Failing fast")
      (System/exit 1))))
babashka/nbb
(ns test-utils
  (:require [clojure.string :as str]
            [clojure.test :refer [*report-counters*]]))

(defmethod clojure.test/report :end-test-var [_m]
  (when-let [rc *report-counters*]
    (let [{:keys [:fail :error]} @rc]
      (when (and (= "true" (System/getenv "FAIL_FAST"))
                 (or (pos? fail) (pos? error)))
        (println "=== Failing fast")
        (System/exit 1)))))
lambdaisland/kaocha
(ns kaocha.test-util
  (:require [clojure.test :as t]
            [clojure.spec.alpha :as spec]
            [expound.alpha :as expound]
            [kaocha.report :as report]
            [kaocha.testable :as testable]
            [kaocha.output :as output]
            [kaocha.type :as type]))

(defmacro with-test-ctx
  "When testing lower level functions, make sure the necessary shared state is set
  up. This also helps to isolate us from the outer test runner state."
  [opts & body]
  `(binding [t/*report-counters* (ref type/initial-counters)
             t/*testing-vars* (list)
             *report-history* (atom [])
             testable/*fail-fast?* (:fail-fast? ~opts)]
     (with-redefs [t/report (fn [m#]
                              (swap! *report-history* conj m#)
                              (report/report-counters m#)
                              (when (:fail-fast? ~opts) (report/fail-fast m#)))]
       (let [result# (do ~@body)]
         {:result result#
          :report @*report-history*}))))
nubank/state-flow
(ns state-flow.cljtest-test
  (:require [clojure.test :as t :refer [deftest is testing]]
            [matcher-combinators.result :as result]
            [matcher-combinators.test :refer [match?]]
            [state-flow.assertions.matcher-combinators :as mc]
            [state-flow.cljtest :refer [defflow] :as cljtest]
            [state-flow.core :as state-flow]
            [state-flow.state :as state]))

(deftest run-a-flow
  ;; NOTE:(sovelten,2020-12-15) This test works when called via clojure.test/run-tests
  ;; It doesn't work when called independently as (run-a-flow) because t/*report-counters* is not initialized then
  (let [report-counters-before (deref t/*report-counters*)
        [ret state]            ((:test (meta #'my-flow)))
        report-counters-after  (deref t/*report-counters*)]
    (testing "flow returns a match report state remains as set"
      (is (match? [{:match/result :match
                    :match/actual {:a 1 :b 2}}
                   {:value 1
                    :map   {:a 1 :b 2}}]
                  [ret state])))
    (testing "meta of state contains the test report"
      (is (match? {:test-report {:assertions [{:match/result :match
                                               :match/expected 1
                                               :match/actual 1}
                                              {:match/result :match
                                               :match/expected {:b 2}
                                               :match/actual {:a 1 :b 2}}]}}
                  (meta state))))
    (testing "we have reported the assertions"
      (is (match? {:test 0 :pass 2 :fail 0 :error 0}
                  (merge-with - report-counters-after report-counters-before))))))
sritchie/midje-cascalog
(deftask midje
  "Run midje and clojure.test tests"
  (bake (:use [bake.core :only [with-context]])
	(:require [clojure test string])
	[namespaces (concat (find-namespaces-in-dir (java.io.File. "test"))
			    (find-namespaces-in-dir (java.io.File. "src")))]
	(with-context :test
       	  ;; This turns off "Testing ...." lines, which I hate, especially
       	  ;; when there's no failure output.
       	  (defmethod clojure.test/report :begin-test-ns [m])

       	  (alter-var-root (var clojure.test/*report-counters*)
       			  (fn [_] (ref clojure.test/*initial-report-counters*)))
       	  (doseq [n namespaces] (require n :reload))


       	  (let [midje-passes    (:pass @clojure.test/*report-counters*)
       		midje-fails     (:fail @clojure.test/*report-counters*)
                midje-failure-message
                (condp = midje-fails
                    0 (format "All claimed facts (%d) have been confirmed." midje-passes)
                    1 (format "FAILURE: %d fact was not confirmed." midje-fails)
                    (format "FAILURE: %d facts were not confirmed." midje-fails))
                potential-consolation
                (condp = midje-passes
                    0 ""
                    1 "(But 1 was.)"
                    (format "(But %d were.)" midje-passes))
                midje-consolation
                (if (> midje-fails 0) potential-consolation "")