Back

test-vars (clj)

(source)

function

(test-vars vars)
Groups vars by their namespace and runs test-var on them with appropriate fixtures applied.

Examples

babashka/nbb
(ns nbb.test-test
  (:require  [clojure.string :as str]
             [clojure.test :as t :refer [deftest is async]]
             [nbb.core :as nbb]
             [sci.core :as sci])
  (:require-macros [nbb.macros :refer [with-async-bindings]]
                   [nbb.test-macros :refer [deftest-async]]))

(deftest use-fixtures-test
  (async done
         (-> (with-async-bindings
               {sci/print-fn (fn [_])}
               (nbb/load-string "
(ns foo3 (:require [clojure.test :as t :refer [deftest test-vars async is testing use-fixtures]]))

(test-vars [#'foo3/foo #'foo3/bar])

(swap! state conj :after-test-vars)

@state
"))
             (.then
              (fn [m]
                (is (= [:once-before :each-before :each-after :each-before :each-after :once-after
                        :after-test-vars
                        :once-before :each-before :each-after :each-before :each-after :once-after] m))
                (done))))))
liquidz/vim-iced
(do (require 'clojure.test)
    (let [ignore-keys [%s]
          summary (atom {:test 0 :pass 0 :fail 0 :error 0 :var 0})
          results (atom {})
          testing-var (atom nil)
          testing-ns (atom nil)
          to-str (fn [x]
                   (if (instance? Throwable x)
                     (str (class x) ": " (.getMessage x) (ex-data x))
                     (pr-str x)))
          report (fn [m]
                   (case (:type m)
                     (:pass :fail :error) (let [ns' (some-> @testing-var namespace)
                                                var' (some-> @testing-var name)
                                                m (-> (assoc m :ns ns' :var var')
                                                      (update :expected to-str)
                                                      (update :actual to-str))
                                                m (apply dissoc m ignore-keys)]
                                            (swap! summary update (:type m) inc)
                                            (swap! results update-in [ns' var'] conj m))

                     :end-test-var (reset! testing-var nil)
                     nil))]
      (binding [clojure.test/report report]
        ;; Use `test-vars` instead of `test-var` to support fixtures
        (clojure.test/test-vars %s))
      (cond-> {:summary @summary
               :results @results}
        @testing-ns (assoc :testing-ns @testing-ns))))
tonsky/tongue
(ns tongue.test.core
  (:require
    [tongue.core :as tongue]
    #?(:clj  [clojure.test :refer [deftest is are testing]]
       :cljs [cljs.test :as test :refer-macros [deftest is are testing]]))
  (:import #?(:clj [clojure.lang ExceptionInfo])))

#_(clojure.test/test-vars [#'test-errors])
kumarshantanu/dime

(ns dime.var-test
  (:require
    [clojure.test :refer :all]
    [dime.core :as di]
    [dime.var  :as dv]
    [foo.db])
  (:import
    [clojure.lang ArityException]))


(deftest test-vars-inject
  (let [di-graph (dv/vars->graph [#'foo.db/make-conn-pool
                                  #'foo.db/make-conn-pool2
                                  #'foo.db/db-find-items
                                  #'foo.db/db-create-order])
        seed-map {:db-host "localhost"
                  :db-port 3306
                  :username "dbuser"
                  :password "s3cr3t"}]
    (testing "default config"
      (reset! foo.db/init-count 0)
      (let [injected (di/inject-all di-graph seed-map)
            {:keys [connection-pool
                    db-create-order
                    find-items]} injected]
        (is (= 2 @foo.db/init-count) "Initialization must happen exactly twice")
        (is (= :dummy-pool                 connection-pool))
        (is (= {:items :dummy}             (find-items :dummy)))
        (is (= {:created-order :dummy}     (db-create-order :dummy)))
        (with-redefs [foo.db/db-create-order (constantly :foo)]
          (is (= :foo (db-create-order :dummy)) "Var must be associated with partial"))))
    (testing "pre-inject dissociates from var"
      (reset! foo.db/init-count 0)
      (let [injected (di/inject-all di-graph seed-map {:pre-inject-processor (fn [pre-inject the-var args] @the-var)})
            {:keys [connection-pool
                    db-create-order
                    find-items]} injected]
        (is (= 2 @foo.db/init-count) "Initialization must happen exactly twice")
        (with-redefs [foo.db/db-create-order (constantly :foo)]
          (is (= {:created-order :dummy} (db-create-order :dummy)) "Var must be dissociated with partial"))))))
infi-nl/alibi
(ns alibi.datasource.sqlite.app-svc-test
  (:require
    [alibi.datasource.sqlite.fixtures :refer [sqlite-fixture]]
    [clojure.test :refer [test-vars deftest is]]
    [alibi.domain.entry-app-svc-test :as entry]
    [alibi.domain.project-admin-app-svc-test :as project-admin]
    [alibi.domain.task-admin-app-svc-test :as task-admin]
    [alibi.domain.task-repository-test :as task-repo]
    [alibi.config :refer [config]]
    [alibi.db-tools :as db-tools]
    [alibi.domain.queries.entry-screen.entries-for-day-test]
    [alibi.domain.queries.entry-screen.list-all-bookable-projects-and-tasks-test]
    [alibi.domain.queries.entry-screen.activity-graphic-test]
    ))

(comment
  (test-vars [#'get-task]))