diff --git a/src/mount/core.clj b/src/mount/core.clj index 3435fdb..4c2aba9 100644 --- a/src/mount/core.clj +++ b/src/mount/core.clj @@ -133,7 +133,7 @@ suspend (assoc :suspend `(fn [] ~suspend)) resume (assoc :resume `(fn [] ~resume)))] `(do - (defonce ~state (DerefableState. ~state-name)) + (def ~state (DerefableState. ~state-name)) (update-meta! [~state-name] (assoc ~s-meta :inst (atom (NotStartedState. ~state-name)) :var (var ~state))) (var ~state))))) diff --git a/test/check/deref/fun_with_values_test.clj b/test/check/deref/fun_with_values_test.clj new file mode 100644 index 0000000..a71b336 --- /dev/null +++ b/test/check/deref/fun_with_values_test.clj @@ -0,0 +1,58 @@ +(ns check.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 'check.deref.fun-with-values-test) + (mount/start #'check.deref.fun-with-values-test/scalar + #'check.deref.fun-with-values-test/fun + #'check.deref.fun-with-values-test/with-fun + #'check.deref.fun-with-values-test/with-partial + #'check.deref.fun-with-values-test/f-in-f + #'check.deref.fun-with-values-test/f-args + #'check.deref.fun-with-values-test/f-no-args-value + #'check.deref.fun-with-values-test/f-no-args + #'check.deref.fun-with-values-test/private-f + #'check.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))) diff --git a/test/check/deref/private_fun_test.clj b/test/check/deref/private_fun_test.clj new file mode 100644 index 0000000..4996ff9 --- /dev/null +++ b/test/check/deref/private_fun_test.clj @@ -0,0 +1,16 @@ +(ns check.deref.private-fun-test + (:require [mount.core :as mount :refer [defstate]] + [check.deref.fun-with-values-test :refer [private-f]] + [clojure.test :refer :all])) + +(defn with-fun-and-values [f] + (mount/in-cljc-mode) + (mount/start #'check.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))) diff --git a/test/check/fun_with_values_test.clj b/test/check/fun_with_values_test.clj index 6b30eae..f1f4772 100644 --- a/test/check/fun_with_values_test.clj +++ b/test/check/fun_with_values_test.clj @@ -53,17 +53,3 @@ (is (= (f-args 41 1) 42)) (is (= (private-f 1) 42)) (is (= f-value 42))) - -(deftest deref-fun-with-values - (mount/in-cljc-mode) - (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)) - (mount/in-clj-mode))