diff --git a/src/mount/core.clj b/src/mount/core.clj index c4e9297..d2cf278 100644 --- a/src/mount/core.clj +++ b/src/mount/core.clj @@ -33,13 +33,13 @@ (let [[state params] (macro/name-with-attributes state body) {:keys [start stop suspend resume] :as lifecycle} (apply hash-map params)] (validate lifecycle) - (let [s-meta (-> {:mount-state mount-state - :order (make-state-seq state) - :start `(fn [] (~@start)) - :started? false} - (cond-> stop (assoc :stop `(fn [] (~@stop)))) - (cond-> suspend (assoc :suspend `(fn [] (~@suspend)))) - (cond-> resume (assoc :resume `(fn [] (~@resume)))))] + (let [s-meta (cond-> {:mount-state mount-state + :order (make-state-seq state) + :start `(fn [] (~@start)) + :started? false} + stop (assoc :stop `(fn [] (~@stop))) + suspend (assoc :suspend `(fn [] (~@suspend))) + resume (assoc :resume `(fn [] (~@resume))))] `(defonce ~(with-meta state (merge (meta state) s-meta)) (NotStartedState. ~(str state)))))) diff --git a/test/check/stop_except_test.clj b/test/check/stop_except_test.clj new file mode 100644 index 0000000..b314c31 --- /dev/null +++ b/test/check/stop_except_test.clj @@ -0,0 +1,31 @@ +(ns check.stop-except-test + (:require [mount.core :as mount :refer [defstate]] + [app.config :refer [app-config]] + [app.nyse :refer [conn]] + [app :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.config/app-config)] + (is (map? app-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? app-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.config/app-config) + _ (mount/stop)] + (is (instance? mount.core.NotStartedState app-config)) + (is (instance? mount.core.NotStartedState conn)) + (is (instance? mount.core.NotStartedState nrepl)))))