Merge pull request #76 from grammati/ipending

Do not start a DerefableState as a side-effect of printing
This commit is contained in:
Anatoly 2017-01-22 11:33:18 -05:00 committed by GitHub
commit 891869721c
3 changed files with 29 additions and 4 deletions

View file

@ -104,6 +104,9 @@
(swap! running dissoc state)
(update-meta! [state :status] #{:stopped})))
(defn running-states []
(set (keys @running)))
(deftype DerefableState [name]
#?(:clj clojure.lang.IDeref
:cljs IDeref)
@ -113,7 +116,13 @@
(let [{:keys [status inst] :as state} (@meta-state name)]
(when-not (:started status)
(up name state (atom #{})))
@inst)))
@inst))
#?(:clj clojure.lang.IPending
:cljs IPending)
(#?(:clj isRealized
:cljs -realized?)
[_]
(boolean ((running-states) name))))
(defn on-reload-meta [s-var]
(or (-> s-var meta :on-reload)
@ -181,9 +190,6 @@
(with-ns ns name))
v)))
(defn running-states []
(set (keys @running)))
(defn- unvar-state [s]
(->> s (drop 2) (apply str))) ;; magic 2 is removing "#'" in state name

View file

@ -13,6 +13,7 @@
mount.test.start-without
mount.test.start-with
mount.test.start-with-states
mount.test.printing
))
#?(:clj (alter-meta! *ns* assoc ::load false))
@ -31,6 +32,7 @@
'mount.test.start-without
'mount.test.start-with
'mount.test.start-with-states
'mount.test.printing
))
(defn run-tests []

View file

@ -0,0 +1,17 @@
(ns mount.test.printing
(: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]]])))
#?(:clj (alter-meta! *ns* assoc ::load false))
(defstate foo
:start (do (println "Starting!") 42))
(deftest test-printing-has-no-side-effects
;; Test that printing an unstarted DerefableState does not have the
;; side-effect of starting it
(println foo)
(is (not= 42 foo)))