Back

*testing-vars* (clj)

(source)

variable

Examples

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*}))))