starting cljs tests
This commit is contained in:
parent
8e34001122
commit
268162324f
18 changed files with 184 additions and 415 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -4,7 +4,7 @@
|
|||
pom.xml
|
||||
pom.xml.asc
|
||||
.repl*
|
||||
dev-resources/public/js/*
|
||||
dev/resources/public/js/*
|
||||
figwheel_server.log
|
||||
*.jar
|
||||
*.class
|
||||
|
|
|
|||
14
project.clj
14
project.clj
|
|
@ -9,7 +9,7 @@
|
|||
:dependencies [[org.clojure/clojure "1.7.0"]
|
||||
[org.clojure/clojurescript "1.7.170"]]
|
||||
|
||||
:profiles {:dev {:source-paths ["dev" "dev/clj" "test/clj"]
|
||||
:profiles {:dev {:source-paths ["dev" "dev/clj" "test"]
|
||||
:dependencies [[datascript "0.13.3"]
|
||||
[hiccups "0.3.0"]
|
||||
[com.andrewmcveigh/cljs-time "0.3.14"]
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
[com.datomic/datomic-free "0.9.5327" :exclusions [joda-time]]]
|
||||
|
||||
:plugins [[lein-cljsbuild "1.1.1"]
|
||||
[lein-doo "0.1.6"]
|
||||
[lein-figwheel "0.5.0-2"]]
|
||||
|
||||
:clean-targets ^{:protect false} [:target-path
|
||||
|
|
@ -28,7 +29,7 @@
|
|||
[:cljsbuild :builds :prod :compiler :output-to]]
|
||||
:cljsbuild {
|
||||
:builds {:dev
|
||||
{:source-paths ["dev/cljs" "test/cljs"]
|
||||
{:source-paths ["src" "dev/cljs"]
|
||||
:figwheel true
|
||||
|
||||
:compiler {:main app.example
|
||||
|
|
@ -38,6 +39,15 @@
|
|||
:optimizations :none
|
||||
:source-map true
|
||||
:source-map-timestamp true}}
|
||||
:test
|
||||
{:source-paths ["src" "dev/cljs" "test"]
|
||||
:compiler {:main mount.test
|
||||
;; :asset-path "js/compiled/out"
|
||||
:output-to "dev/resources/public/js/compiled/mount.js"
|
||||
:output-dir "dev/resources/public/js/compiled/test"
|
||||
:optimizations :none
|
||||
:source-map true
|
||||
:source-map-timestamp true}}
|
||||
:prod
|
||||
{:source-paths ["src" "test"]
|
||||
:compiler {:output-to "dev/resources/public/js/compiled/mount.js"
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
(ns mount.cleanup_dirty_states_test
|
||||
(:require [mount.core :as mount]
|
||||
[app.example]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(deftest cleanup-dirty-states
|
||||
(let [_ (mount/start)]
|
||||
(is (not (.isClosed (:server-socket app.example/nrepl))))
|
||||
(require 'app.example :reload)
|
||||
(mount/start) ;; should not result in "BindException Address already in use" since the clean up will stop the previous instance
|
||||
(is (not (.isClosed (:server-socket app.example/nrepl))))
|
||||
(mount/stop)
|
||||
(is (instance? mount.core.NotStartedState app.example/nrepl))))
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
(ns mount.deref.fun-with-values-test
|
||||
(:require [mount.core :as mount :refer [defstate]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defn f [n]
|
||||
(fn [m]
|
||||
(+ n m)))
|
||||
|
||||
(defn g [a b]
|
||||
(+ a b))
|
||||
|
||||
(defn- pf [n]
|
||||
(+ 41 n))
|
||||
|
||||
(defn fna []
|
||||
42)
|
||||
|
||||
(defstate scalar :start 42)
|
||||
(defstate fun :start #(inc 41))
|
||||
(defstate with-fun :start (inc 41))
|
||||
(defstate with-partial :start (partial g 41))
|
||||
(defstate f-in-f :start (f 41))
|
||||
(defstate f-no-args-value :start (fna))
|
||||
(defstate f-no-args :start fna)
|
||||
(defstate f-args :start g)
|
||||
(defstate f-value :start (g 41 1))
|
||||
(defstate private-f :start pf)
|
||||
|
||||
(defn with-fun-and-values [f]
|
||||
(mount/in-cljc-mode)
|
||||
(require :reload 'mount.deref.fun-with-values-test)
|
||||
(mount/start #'mount.deref.fun-with-values-test/scalar
|
||||
#'mount.deref.fun-with-values-test/fun
|
||||
#'mount.deref.fun-with-values-test/with-fun
|
||||
#'mount.deref.fun-with-values-test/with-partial
|
||||
#'mount.deref.fun-with-values-test/f-in-f
|
||||
#'mount.deref.fun-with-values-test/f-args
|
||||
#'mount.deref.fun-with-values-test/f-no-args-value
|
||||
#'mount.deref.fun-with-values-test/f-no-args
|
||||
#'mount.deref.fun-with-values-test/private-f
|
||||
#'mount.deref.fun-with-values-test/f-value)
|
||||
(f)
|
||||
(mount/stop)
|
||||
(mount/in-clj-mode))
|
||||
|
||||
(use-fixtures :each with-fun-and-values)
|
||||
|
||||
(deftest fun-with-values
|
||||
(is (= @scalar 42))
|
||||
(is (= (@fun) 42))
|
||||
(is (= @with-fun 42))
|
||||
(is (= (@with-partial 1) 42))
|
||||
(is (= (@f-in-f 1) 42))
|
||||
(is (= @f-no-args-value 42))
|
||||
(is (= (@f-no-args) 42))
|
||||
(is (= (@f-args 41 1) 42))
|
||||
(is (= (@private-f 1) 42))
|
||||
(is (= @f-value 42)))
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
(ns mount.deref.private-fun-test
|
||||
(:require [mount.core :as mount :refer [defstate]]
|
||||
[mount.deref.fun-with-values-test :refer [private-f]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defn with-fun-and-values [f]
|
||||
(mount/in-cljc-mode)
|
||||
(mount/start #'mount.deref.fun-with-values-test/private-f)
|
||||
(f)
|
||||
(mount/stop)
|
||||
(mount/in-clj-mode))
|
||||
|
||||
(use-fixtures :each with-fun-and-values)
|
||||
|
||||
(deftest fun-with-valuesj
|
||||
(is (= (@private-f 1) 42)))
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
(ns mount.fun-with-values-test
|
||||
(:require [mount.core :as mount :refer [defstate]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defn f [n]
|
||||
(fn [m]
|
||||
(+ n m)))
|
||||
|
||||
(defn g [a b]
|
||||
(+ a b))
|
||||
|
||||
(defn- pf [n]
|
||||
(+ 41 n))
|
||||
|
||||
(defn fna []
|
||||
42)
|
||||
|
||||
(defstate scalar :start 42)
|
||||
(defstate fun :start #(inc 41))
|
||||
(defstate with-fun :start (inc 41))
|
||||
(defstate with-partial :start (partial g 41))
|
||||
(defstate f-in-f :start (f 41))
|
||||
(defstate f-no-args-value :start (fna))
|
||||
(defstate f-no-args :start fna)
|
||||
(defstate f-args :start g)
|
||||
(defstate f-value :start (g 41 1))
|
||||
(defstate private-f :start pf)
|
||||
|
||||
(defn with-fun-and-values [f]
|
||||
(mount/start #'mount.fun-with-values-test/scalar
|
||||
#'mount.fun-with-values-test/fun
|
||||
#'mount.fun-with-values-test/with-fun
|
||||
#'mount.fun-with-values-test/with-partial
|
||||
#'mount.fun-with-values-test/f-in-f
|
||||
#'mount.fun-with-values-test/f-args
|
||||
#'mount.fun-with-values-test/f-no-args-value
|
||||
#'mount.fun-with-values-test/f-no-args
|
||||
#'mount.fun-with-values-test/private-f
|
||||
#'mount.fun-with-values-test/f-value)
|
||||
(f)
|
||||
(mount/stop))
|
||||
|
||||
(use-fixtures :each with-fun-and-values)
|
||||
|
||||
(deftest fun-with-values
|
||||
(is (= scalar 42))
|
||||
(is (= (fun) 42))
|
||||
(is (= with-fun 42))
|
||||
(is (= (with-partial 1) 42))
|
||||
(is (= (f-in-f 1) 42))
|
||||
(is (= f-no-args-value 42))
|
||||
(is (= (f-no-args) 42))
|
||||
(is (= (f-args 41 1) 42))
|
||||
(is (= (private-f 1) 42))
|
||||
(is (= f-value 42)))
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
(ns mount.parts-test
|
||||
(:require [mount.core :as mount :refer [defstate] :as m]
|
||||
[app.nyse :refer [conn]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defstate should-not-start :start #(constantly 42))
|
||||
|
||||
(defn with-parts [f]
|
||||
(m/start #'app.conf/config #'app.nyse/conn)
|
||||
(f)
|
||||
(m/stop))
|
||||
|
||||
(use-fixtures :each with-parts)
|
||||
|
||||
(deftest start-only-parts
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(is (instance? mount.core.NotStartedState should-not-start)))
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
(ns mount.private-fun-test
|
||||
(:require [mount.core :as mount :refer [defstate]]
|
||||
[mount.fun-with-values-test :refer [private-f]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defn with-fun-and-values [f]
|
||||
(mount/start #'mount.fun-with-values-test/private-f)
|
||||
(f)
|
||||
(mount/stop))
|
||||
|
||||
(use-fixtures :each with-fun-and-values)
|
||||
|
||||
(deftest fun-with-valuesj
|
||||
(is (= (private-f 1) 42)))
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
(ns mount.start-with-test
|
||||
(:require [mount.core :as mount :refer [defstate]]
|
||||
[app.conf :refer [config]]
|
||||
[app.nyse :refer [conn]]
|
||||
[app.example :refer [nrepl]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defstate test-conn :start 42
|
||||
:stop #(constantly 0))
|
||||
|
||||
(defstate test-nrepl :start [])
|
||||
|
||||
(deftest start-with
|
||||
|
||||
(testing "should start with substitutes"
|
||||
(let [_ (mount/start-with {#'app.nyse/conn #'mount.start-with-test/test-conn
|
||||
#'app.example/nrepl #'mount.start-with-test/test-nrepl})]
|
||||
(is (map? config))
|
||||
(is (vector? nrepl))
|
||||
(is (= conn 42))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should not start the substitute itself"
|
||||
(let [_ (mount/start-with {#'app.nyse/conn #'mount.start-with-test/test-conn})]
|
||||
(is (instance? mount.core.NotStartedState test-conn))
|
||||
(is (= conn 42))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should start normally after start-with"
|
||||
(let [_ (mount/start)]
|
||||
(is (map? config))
|
||||
(is (instance? clojure.tools.nrepl.server.Server nrepl))
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(is (= test-conn 42))
|
||||
(is (vector? test-nrepl))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should start-without normally after start-with"
|
||||
(let [_ (mount/start-without #'mount.start-with-test/test-conn
|
||||
#'mount.start-with-test/test-nrepl)]
|
||||
(is (map? config))
|
||||
(is (instance? clojure.tools.nrepl.server.Server nrepl))
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(is (instance? mount.core.NotStartedState test-conn))
|
||||
(is (instance? mount.core.NotStartedState test-nrepl))
|
||||
(mount/stop))))
|
||||
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
(ns mount.start-without-test
|
||||
(:require [mount.core :as m]
|
||||
[app.conf :refer [config]]
|
||||
[app.nyse :refer [conn]]
|
||||
[app.example :refer [nrepl]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defn without [f]
|
||||
(m/start-without #'app.nyse/conn #'app.example/nrepl)
|
||||
(f)
|
||||
(m/stop))
|
||||
|
||||
(use-fixtures :each without)
|
||||
|
||||
(deftest start-without-states
|
||||
(is (map? config))
|
||||
(is (instance? mount.core.NotStartedState nrepl))
|
||||
(is (instance? mount.core.NotStartedState conn)))
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
(ns mount.stop-except-test
|
||||
(:require [mount.core :as mount :refer [defstate]]
|
||||
[app.conf :refer [config]]
|
||||
[app.nyse :refer [conn]]
|
||||
[app.example :refer [nrepl]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(deftest stop-except
|
||||
|
||||
(testing "should stop all except nrepl"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/stop-except #'app.nyse/conn #'app.conf/config)]
|
||||
(is (map? config))
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(is (instance? mount.core.NotStartedState nrepl))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should start normally after stop-except"
|
||||
(let [_ (mount/start)]
|
||||
(is (map? config))
|
||||
(is (instance? clojure.tools.nrepl.server.Server nrepl))
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should stop all normally after stop-except"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/stop-except #'app.nyse/conn #'app.conf/config)
|
||||
_ (mount/stop)]
|
||||
(is (instance? mount.core.NotStartedState config))
|
||||
(is (instance? mount.core.NotStartedState conn))
|
||||
(is (instance? mount.core.NotStartedState nrepl)))))
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
(ns mount.suspend-resume-test
|
||||
(:require [mount.core :as mount :refer [defstate]]
|
||||
[app.conf :refer [config]]
|
||||
[app.nyse :refer [conn]]
|
||||
[app.example :refer [nrepl]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defn koncat [k s]
|
||||
(-> (name k)
|
||||
(str "-" (name s))
|
||||
keyword))
|
||||
|
||||
(defn start [s] (koncat s :started))
|
||||
(defn stop [s] (koncat s :stopped))
|
||||
(defn suspend [s] (koncat s :suspended))
|
||||
(defn resume [s] (koncat s :resumed))
|
||||
|
||||
(defstate web-server :start (start :w)
|
||||
:stop (stop :w)
|
||||
:suspend (suspend :w)
|
||||
:resume (resume :w))
|
||||
|
||||
(defstate q-listener :start (start :q)
|
||||
:stop (stop :q)
|
||||
:suspend (suspend :q)
|
||||
:resume (resume :q))
|
||||
|
||||
(defstate randomizer :start (rand-int 42))
|
||||
|
||||
(deftest suspendable-lifecycle
|
||||
|
||||
(testing "should suspend _only suspendable_ states that are currently started"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/suspend)]
|
||||
(is (map? config))
|
||||
(is (instance? clojure.tools.nrepl.server.Server nrepl))
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(is (= web-server :w-suspended))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should resume _only suspendable_ states that are currently suspended"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/stop #'app.example/nrepl)
|
||||
_ (mount/suspend)
|
||||
_ (mount/resume)]
|
||||
(is (map? config))
|
||||
(is (instance? mount.core.NotStartedState nrepl))
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(is (= web-server :w-resumed))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should start all the states, except the ones that are currently suspended, should resume them instead"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/suspend)
|
||||
_ (mount/start)]
|
||||
(is (map? config))
|
||||
(is (instance? clojure.tools.nrepl.server.Server nrepl))
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(is (= web-server :w-resumed))
|
||||
(mount/stop)))
|
||||
|
||||
(testing "should stop all: started and suspended"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/suspend)
|
||||
_ (mount/stop)]
|
||||
(is (instance? mount.core.NotStartedState config))
|
||||
(is (instance? mount.core.NotStartedState nrepl))
|
||||
(is (instance? mount.core.NotStartedState conn))
|
||||
(is (instance? mount.core.NotStartedState web-server)))))
|
||||
|
||||
|
||||
(deftest suspendable-start-with
|
||||
|
||||
(testing "when replacing a non suspendable state with a suspendable one,
|
||||
the later should be able to suspend/resume,
|
||||
the original should not be suspendable after resume and preserve its lifecycle fns after rollback/stop"
|
||||
(let [_ (mount/start-with {#'app.example/nrepl #'mount.suspend-resume-test/web-server})
|
||||
_ (mount/suspend)]
|
||||
(is (= nrepl :w-suspended))
|
||||
(is (instance? mount.core.NotStartedState web-server))
|
||||
(mount/stop)
|
||||
(mount/start)
|
||||
(mount/suspend)
|
||||
(is (instance? clojure.tools.nrepl.server.Server nrepl))
|
||||
(is (= web-server :w-suspended))
|
||||
(mount/stop)))
|
||||
|
||||
;; this is a messy use case, but can still happen especially at REPL time
|
||||
;; it also messy, because usually :stop function refers the _original_ state by name (i.e. #(disconnect conn))
|
||||
;; (unchanged/not substituted in its lexical scope), and original state won't be started
|
||||
(testing "when replacing a suspendable state with a non suspendable one,
|
||||
the later should not be suspendable,
|
||||
the original should still be suspendable and preserve its lifecycle fns after the rollback/stop"
|
||||
(let [_ (mount/start-with {#'mount.suspend-resume-test/web-server #'mount.suspend-resume-test/randomizer})
|
||||
_ (mount/suspend)]
|
||||
(is (integer? web-server))
|
||||
(is (instance? mount.core.NotStartedState randomizer))
|
||||
(mount/stop)
|
||||
(mount/start)
|
||||
(mount/suspend)
|
||||
(is (integer? randomizer))
|
||||
(is (= web-server :w-suspended))
|
||||
(mount/stop)))
|
||||
|
||||
;; this is a messy use case, but can still happen especially at REPL time
|
||||
(testing "when replacing a suspended state with a non suspendable started one,
|
||||
the later should not be suspendable,
|
||||
the original should still be suspended and preserve its lifecycle fns after the rollback/stop"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/suspend)
|
||||
_ (mount/start-with {#'mount.suspend-resume-test/web-server #'app.nyse/conn}) ;; TODO: good to WARN on started states during "start-with"
|
||||
_ (mount/suspend)]
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(is (= web-server :w-suspended)) ;; since the "conn" does not have a resume method, so web-server was not started
|
||||
(mount/stop)
|
||||
(mount/start)
|
||||
(mount/suspend)
|
||||
(is (instance? datomic.peer.LocalConnection conn))
|
||||
(is (= web-server :w-suspended))
|
||||
(mount/stop)))
|
||||
|
||||
;; this is a messy use case, but can still happen especially at REPL time
|
||||
(testing "when replacing a suspended state with a suspendable one,
|
||||
the later should be suspendable,
|
||||
the original should still be suspended and preserve its lifecycle fns after the rollback/stop"
|
||||
(let [_ (mount/start)
|
||||
_ (mount/suspend)
|
||||
_ (mount/start-with {#'mount.suspend-resume-test/web-server
|
||||
#'mount.suspend-resume-test/q-listener})] ;; TODO: good to WARN on started states during "start-with"
|
||||
(is (= q-listener :q-suspended))
|
||||
(is (= web-server :q-resumed))
|
||||
(mount/suspend)
|
||||
(is (= q-listener :q-suspended))
|
||||
(is (= web-server :q-suspended))
|
||||
(mount/stop)
|
||||
(is (instance? mount.core.NotStartedState web-server))
|
||||
(is (instance? mount.core.NotStartedState q-listener))
|
||||
(mount/start)
|
||||
(mount/suspend)
|
||||
(is (= q-listener :q-suspended))
|
||||
(is (= web-server :w-suspended))
|
||||
(mount/stop))))
|
||||
|
|
@ -1 +0,0 @@
|
|||
обещали подвезти
|
||||
18
test/mount/test.cljc
Normal file
18
test/mount/test.cljc
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(ns mount.test
|
||||
(:require
|
||||
#?@(:cljs [[cljs.test :as t]
|
||||
[doo.runner :refer-macros [doo-tests]]]
|
||||
:clj [clojure.test :as t])
|
||||
[mount.core :as mount]
|
||||
|
||||
mount.test.fun-with-values
|
||||
mount.test.private-fun))
|
||||
|
||||
(mount/in-cljc-mode)
|
||||
|
||||
(doo.runner/doo-tests 'mount.test.fun-with-values
|
||||
'mount.test.private-fun)
|
||||
;; (doo.runner/do-all-tests)
|
||||
|
||||
(defn run-tests []
|
||||
(t/run-all-tests #"mount.test.*"))
|
||||
59
test/mount/test/fun_with_values.cljc
Normal file
59
test/mount/test/fun_with_values.cljc
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
(ns mount.test.fun-with-values
|
||||
(:require
|
||||
#?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]]
|
||||
[mount.core :as mount :refer-macros [defstate]]]
|
||||
:clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]]
|
||||
[mount.core :as mount :refer [defstate]]])))
|
||||
|
||||
(defn f [n]
|
||||
(fn [m]
|
||||
(+ n m)))
|
||||
|
||||
(defn g [a b]
|
||||
(+ a b))
|
||||
|
||||
(defn- pf [n]
|
||||
(+ 41 n))
|
||||
|
||||
(defn fna []
|
||||
42)
|
||||
|
||||
(defstate scalar :start 42)
|
||||
(defstate fun :start #(inc 41))
|
||||
(defstate with-fun :start (inc 41))
|
||||
(defstate with-partial :start (partial g 41))
|
||||
(defstate f-in-f :start (f 41))
|
||||
(defstate f-no-args-value :start (fna))
|
||||
(defstate f-no-args :start fna)
|
||||
(defstate f-args :start g)
|
||||
(defstate f-value :start (g 41 1))
|
||||
(defstate private-f :start pf)
|
||||
|
||||
(defn start-states []
|
||||
(mount/start #'mount.test.fun-with-values/scalar
|
||||
#'mount.test.fun-with-values/fun
|
||||
#'mount.test.fun-with-values/with-fun
|
||||
#'mount.test.fun-with-values/with-partial
|
||||
#'mount.test.fun-with-values/f-in-f
|
||||
#'mount.test.fun-with-values/f-args
|
||||
#'mount.test.fun-with-values/f-no-args-value
|
||||
#'mount.test.fun-with-values/f-no-args
|
||||
#'mount.test.fun-with-values/private-f
|
||||
#'mount.test.fun-with-values/f-value))
|
||||
|
||||
(use-fixtures :once
|
||||
#?(:cljs {:before start-states
|
||||
:after mount/stop}
|
||||
:clj #((start-states) (%) (mount/stop))))
|
||||
|
||||
(deftest fun-with-values
|
||||
(is (= @scalar 42))
|
||||
(is (= (@fun) 42))
|
||||
(is (= @with-fun 42))
|
||||
(is (= (@with-partial 1) 42))
|
||||
(is (= (@f-in-f 1) 42))
|
||||
(is (= @f-no-args-value 42))
|
||||
(is (= (@f-no-args) 42))
|
||||
(is (= (@f-args 41 1) 42))
|
||||
(is (= (@private-f 1) 42))
|
||||
(is (= @f-value 42)))
|
||||
18
test/mount/test/private_fun.cljc
Normal file
18
test/mount/test/private_fun.cljc
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(ns mount.test.private-fun
|
||||
(:require
|
||||
#?@(:cljs [[cljs.test :as t :refer-macros [is are deftest testing use-fixtures]]
|
||||
[mount.core :as mount :refer-macros [defstate]]]
|
||||
:clj [[clojure.test :as t :refer [is are deftest testing use-fixtures]]
|
||||
[mount.core :as mount :refer [defstate]]])
|
||||
|
||||
[mount.test.fun-with-values :refer [private-f]]))
|
||||
|
||||
(use-fixtures :once
|
||||
#?(:cljs {:before #(mount/start #'mount.test.fun-with-values/private-f)
|
||||
:after mount/stop}
|
||||
:clj #((mount/start #'mount.test.fun-with-values/private-f)
|
||||
(%)
|
||||
(mount/stop))))
|
||||
|
||||
(deftest fun-with-values
|
||||
(is (= (@private-f 1) 42)))
|
||||
59
test/mount/test/var/fun_with_values.clj
Normal file
59
test/mount/test/var/fun_with_values.clj
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
(ns mount.test.var.fun-with-values
|
||||
(:require [clojure.test :as t :refer [is are deftest testing use-fixtures]]
|
||||
[mount.core :as mount :refer [defstate]]))
|
||||
|
||||
(defn f [n]
|
||||
(fn [m]
|
||||
(+ n m)))
|
||||
|
||||
(defn g [a b]
|
||||
(+ a b))
|
||||
|
||||
(defn- pf [n]
|
||||
(+ 41 n))
|
||||
|
||||
(defn fna []
|
||||
42)
|
||||
|
||||
(defstate scalar :start 42)
|
||||
(defstate fun :start #(inc 41))
|
||||
(defstate with-fun :start (inc 41))
|
||||
(defstate with-partial :start (partial g 41))
|
||||
(defstate f-in-f :start (f 41))
|
||||
(defstate f-no-args-value :start (fna))
|
||||
(defstate f-no-args :start fna)
|
||||
(defstate f-args :start g)
|
||||
(defstate f-value :start (g 41 1))
|
||||
(defstate private-f :start pf)
|
||||
|
||||
(defn start-states []
|
||||
(mount/in-clj-mode)
|
||||
(require :reload 'mount.test.var.fun-with-values)
|
||||
(mount/start #'mount.test.var.fun-with-values/scalar
|
||||
#'mount.test.var.fun-with-values/fun
|
||||
#'mount.test.var.fun-with-values/with-fun
|
||||
#'mount.test.var.fun-with-values/with-partial
|
||||
#'mount.test.var.fun-with-values/f-in-f
|
||||
#'mount.test.var.fun-with-values/f-args
|
||||
#'mount.test.var.fun-with-values/f-no-args-value
|
||||
#'mount.test.var.fun-with-values/f-no-args
|
||||
#'mount.test.var.fun-with-values/private-f
|
||||
#'mount.test.var.fun-with-values/f-value))
|
||||
|
||||
(defn stop-states []
|
||||
(mount/stop)
|
||||
(mount/in-cljc-mode))
|
||||
|
||||
(use-fixtures :once #((start-states) (%) (stop-states)))
|
||||
|
||||
(deftest fun-with-values
|
||||
(is (= scalar 42))
|
||||
(is (= (fun) 42))
|
||||
(is (= with-fun 42))
|
||||
(is (= (with-partial 1) 42))
|
||||
(is (= (f-in-f 1) 42))
|
||||
(is (= f-no-args-value 42))
|
||||
(is (= (f-no-args) 42))
|
||||
(is (= (f-args 41 1) 42))
|
||||
(is (= (private-f 1) 42))
|
||||
(is (= f-value 42)))
|
||||
17
test/mount/test/var/private_fun.clj
Normal file
17
test/mount/test/var/private_fun.clj
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(ns mount.test.var.private-fun
|
||||
(:require [clojure.test :refer [is are deftest testing use-fixtures]]
|
||||
[mount.core :as mount :refer [defstate]]
|
||||
[mount.test.var.fun-with-values :refer [private-f]]))
|
||||
|
||||
(defn in-clj-mode [f]
|
||||
(mount/in-clj-mode)
|
||||
(require :reload 'mount.test.var.fun-with-values 'mount.test.var.private-fun)
|
||||
(mount/start #'mount.test.var.fun-with-values/private-f)
|
||||
(f)
|
||||
(mount/stop)
|
||||
(mount/in-cljc-mode))
|
||||
|
||||
(use-fixtures :once in-clj-mode)
|
||||
|
||||
(deftest fun-with-values
|
||||
(is (= (private-f 1) 42)))
|
||||
Loading…
Reference in a new issue