Skip to content

Commit

Permalink
migrated to cljs.test
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Jun 25, 2015
1 parent 690c05e commit de84aef
Show file tree
Hide file tree
Showing 32 changed files with 226 additions and 199 deletions.
5 changes: 0 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
:source-paths ["bench/src" "test"]
:plugins [
[lein-cljsbuild "1.0.6"]
[com.cemerick/clojurescript.test "0.3.3"]
]
:cljsbuild {
:builds [
Expand Down Expand Up @@ -68,10 +67,6 @@
:recompile-dependents false
}}
]
:test-commands {
"datascript.test" [ "phantomjs" :runner "target/datascript.js" ]
"datascript.test.js" [ "phantomjs" "test/js/runner.js" ]
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/datascript/query_v3.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns datascript.query-v3
(:require
[clojure.set :as set]
;;[cemerick.cljs.test :as t]
[datascript :as d]
[datascript.core :as dc]
[datascript.shim :as shim]
Expand Down
74 changes: 33 additions & 41 deletions test/datascript/test.cljc
Original file line number Diff line number Diff line change
@@ -1,50 +1,42 @@
(ns datascript.test
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
datascript.test.core
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
datascript.test.core

datascript.test.btset
datascript.test.components
datascript.test.entity
datascript.test.explode
datascript.test.filter
datascript.test.index
datascript.test.listen
datascript.test.lookup-refs
datascript.test.lru
datascript.test.parser
datascript.test.parser-find
datascript.test.parser-rules
datascript.test.parser-query
datascript.test.parser-where
datascript.test.pull-api
datascript.test.pull-parser
datascript.test.query
datascript.test.query-aggregates
datascript.test.query-find-specs
datascript.test.query-fns
datascript.test.query-pull
datascript.test.query-rules
datascript.test.query-v3
datascript.test.serialization
datascript.test.transact
datascript.test.validation
datascript.test.upsert
))

(defn wrap-res [res]
#?(:cljs (clj->js res)
:clj (when (pos? (+ (:fail res) (:error res)))
(System/exit 1))))
datascript.test.btset
datascript.test.components
datascript.test.entity
datascript.test.explode
datascript.test.filter
datascript.test.index
datascript.test.listen
datascript.test.lookup-refs
datascript.test.lru
datascript.test.parser
datascript.test.parser-find
datascript.test.parser-rules
datascript.test.parser-query
datascript.test.parser-where
datascript.test.pull-api
datascript.test.pull-parser
datascript.test.query
datascript.test.query-aggregates
datascript.test.query-find-specs
datascript.test.query-fns
datascript.test.query-pull
datascript.test.query-rules
datascript.test.query-v3
datascript.test.serialization
datascript.test.transact
datascript.test.validation
datascript.test.upsert))

(defn ^:export test-most []
(wrap-res
(t/run-all-tests #"datascript\.test\.(?!btset).*")))
(datascript.test.core/wrap-res #(t/run-all-tests #"datascript\.test\.(?!btset).*")))

(defn ^:export test-btset []
(wrap-res
(t/test-ns 'datascript.test.btset)))
(datascript.test.core/wrap-res #(t/test-ns 'datascript.test.btset)))

(defn ^:export test-all []
(wrap-res
(t/run-all-tests)))
(datascript.test.core/wrap-res #(t/run-all-tests)))
12 changes: 4 additions & 8 deletions test/datascript/test/btset.cljc
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
(ns datascript.test.btset
#?@(:cljs
[(:require-macros [cemerick.cljs.test :refer [is deftest testing]])
(:require [cemerick.cljs.test :as t]
[datascript.btset :as btset :refer [btset btset-by slice]]
[datascript.perf :as perf])]
:clj
[(:require [clojure.test :as t :refer [is deftest testing]]
[datascript.btset :as btset :refer [btset btset-by slice]])]))
(:require
[datascript.btset :as btset :refer [btset btset-by slice]]
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])))

#?(:cljs (enable-console-print!))

Expand Down
11 changes: 6 additions & 5 deletions test/datascript/test/components.cljc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns datascript.test.components
(:require
[#?(:cljs cljs.reader :clj clojure.edn) :as edn]
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc]))
[#?(:cljs cljs.reader :clj clojure.edn) :as edn]
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc]))

#?(:cljs
(def Throwable js/Error))
Expand Down
56 changes: 33 additions & 23 deletions test/datascript/test/core.cljc
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
(ns datascript.test.core
(:require
[#?(:cljs cljs.reader :clj clojure.edn) :as edn]
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [deftest is are testing with-test-out]]
[datascript :as d]
[datascript.impl.entity :as de]
[datascript.core :as dc #?@(:cljs [:refer-macros [defrecord-updatable]]
:clj [:refer [defrecord-updatable]])]))
[#?(:cljs cljs.reader :clj clojure.edn) :as edn]
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.impl.entity :as de]
[datascript.core :as dc #?@(:cljs [:refer-macros [defrecord-updatable]]
:clj [:refer [defrecord-updatable]])]))

#?(:cljs
(enable-console-print!))

;; Added special case for printing ex-data of ExceptionInfo
#?(:cljs
(defmethod t/report :error [{:keys [test-env] :as m}]
(with-test-out test-env
(t/inc-report-counter test-env :error)
(println "\nERROR in" (t/testing-vars-str m))
(when (seq (::test-contexts @test-env))
(println (t/testing-contexts-str test-env)))
(when-let [message (:message m)] (println message))
(println "expected:" (pr-str (:expected m)))
(print " actual: ")
(let [actual (:actual m)]
(cond
(instance? ExceptionInfo actual)
(println (.-stack actual) "\n" (ex-data actual))
(instance? js/Error actual)
(println (.-stack actual))
:else
(prn actual))))))
(defmethod t/report [::t/default :error] [m]
(t/inc-report-counter! :error)
(println "\nERROR in" (t/testing-vars-str m))
(when (seq (:testing-contexts (t/get-current-env)))
(println (t/testing-contexts-str)))
(when-let [message (:message m)] (println message))
(println "expected:" (pr-str (:expected m)))
(print " actual: ")
(let [actual (:actual m)]
(cond
(instance? ExceptionInfo actual)
(println (.-stack actual) "\n" (pr-str (ex-data actual)))
(instance? js/Error actual)
(println (.-stack actual))
:else
(prn actual)))))

#?(:cljs (def test-summary (atom nil)))
#?(:cljs (defmethod t/report [::t/default :end-run-tests] [m]
(reset! test-summary (dissoc m :type))))

(defn wrap-res [f]
#?(:cljs (do (f) (clj->js @test-summary))
:clj (let [res (f)]
(when (pos? (+ (:fail res) (:error res)))
(System/exit 1)))))

;; utils

Expand Down
14 changes: 8 additions & 6 deletions test/datascript/test/entity.cljc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(ns datascript.test.entity
(:require
[#?(:cljs cljs.reader :clj clojure.edn) :as edn]
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [deftest is are testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc])
#?(:clj (:import [clojure.lang ExceptionInfo])))
[#?(:cljs cljs.reader :clj clojure.edn) :as edn]
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc])
#?(:clj
(:import [clojure.lang ExceptionInfo])))



Expand Down
11 changes: 6 additions & 5 deletions test/datascript/test/explode.cljc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns datascript.test.explode
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.shim :as shim]
[datascript.core :as dc]
[datascript.test.core :as tdc]))
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.shim :as shim]
[datascript.core :as dc]
[datascript.test.core :as tdc]))

#?(:cljs
(def Throwable js/Error))
Expand Down
9 changes: 5 additions & 4 deletions test/datascript/test/filter.cljc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(ns datascript.test.filter
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc]))
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc]))

(deftest test-filter-db
(let [db (-> (d/empty-db {:aka { :db/cardinality :db.cardinality/many }})
Expand Down
9 changes: 5 additions & 4 deletions test/datascript/test/index.cljc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(ns datascript.test.index
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc]))
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc]))

(deftest test-datoms
(let [dvec #(vector (:e %) (:a %) (:v %))
Expand Down
9 changes: 5 additions & 4 deletions test/datascript/test/listen.cljc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(ns datascript.test.listen
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc]))
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc]))

(deftest test-listen!
(let [conn (d/create-conn)
Expand Down
12 changes: 7 additions & 5 deletions test/datascript/test/lookup_refs.cljc
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
(ns datascript.test.lookup-refs
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc])
#?(:clj (:import [clojure.lang ExceptionInfo])))
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.test.core :as tdc])
#?(:clj
(:import [clojure.lang ExceptionInfo])))



Expand Down
3 changes: 2 additions & 1 deletion test/datascript/test/lru.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns datascript.test.lru
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript.lru :as lru]))

(deftest test-lru
Expand Down
14 changes: 8 additions & 6 deletions test/datascript/test/parser.cljc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(ns datascript.test.parser
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.parser :as dp]
[datascript.test.core :as tdc])
#?(:clj (:import [clojure.lang ExceptionInfo])))
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.parser :as dp]
[datascript.test.core :as tdc])
#?(:clj
(:import [clojure.lang ExceptionInfo])))



Expand Down
11 changes: 6 additions & 5 deletions test/datascript/test/parser_find.cljc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns datascript.test.parser-find
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.parser :as dp]
[datascript.test.core :as tdc]))
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.parser :as dp]
[datascript.test.core :as tdc]))

#?(:cljs
(def Throwable js/Error))
Expand Down
14 changes: 8 additions & 6 deletions test/datascript/test/parser_query.cljc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(ns datascript.test.parser-query
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.parser :as dp]
[datascript.test.core :as tdc])
#?(:clj (:import [clojure.lang ExceptionInfo])))
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.parser :as dp]
[datascript.test.core :as tdc])
#?(:clj
(:import [clojure.lang ExceptionInfo])))



Expand Down
14 changes: 8 additions & 6 deletions test/datascript/test/parser_rules.cljc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(ns datascript.test.parser-rules
(:require
[#?(:cljs cemerick.cljs.test :clj clojure.test) :as t #?(:cljs :refer-macros :clj :refer) [is are deftest testing]]
[datascript :as d]
[datascript.core :as dc]
[datascript.parser :as dp]
[datascript.test.core :as tdc])
#?(:clj (:import [clojure.lang ExceptionInfo])))
#?(:cljs [cljs.test :as t :refer-macros [is are deftest testing]]
:clj [clojure.test :as t :refer [is are deftest testing]])
[datascript :as d]
[datascript.core :as dc]
[datascript.parser :as dp]
[datascript.test.core :as tdc])
#?(:clj
(:import [clojure.lang ExceptionInfo])))



Expand Down
Loading

0 comments on commit de84aef

Please sign in to comment.