From 20e230b5dd31a718478a8a1ddc9e608bf359af72 Mon Sep 17 00:00:00 2001 From: anatoly Date: Mon, 30 Nov 2015 17:23:03 -0500 Subject: [PATCH] [#20, #21]: removing trampoline to take functions as values --- src/mount/core.clj | 2 +- test/check/fun_with_values_test.clj | 39 +++++++++++++++++++++++++++++ test/check/start_with_test.clj | 3 ++- test/check/suspend_resume_test.clj | 20 ++++++++------- 4 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 test/check/fun_with_values_test.clj diff --git a/src/mount/core.clj b/src/mount/core.clj index 19125be..6ca57c4 100644 --- a/src/mount/core.clj +++ b/src/mount/core.clj @@ -66,7 +66,7 @@ (NotStartedState. ~(str state)))))) (defn- record! [{:keys [ns name]} f done] - (let [state (trampoline f)] + (let [state (f)] (swap! done conj (ns-resolve ns name)) state)) diff --git a/test/check/fun_with_values_test.clj b/test/check/fun_with_values_test.clj new file mode 100644 index 0000000..765793d --- /dev/null +++ b/test/check/fun_with_values_test.clj @@ -0,0 +1,39 @@ +(ns check.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)) + +(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-value :start (g 41 1)) + +(defn with-fun-and-values [f] + (mount/start #'check.fun-with-values-test/scalar + #'check.fun-with-values-test/fun + #'check.fun-with-values-test/with-fun + #'check.fun-with-values-test/with-partial + #'check.fun-with-values-test/f-in-f + #'check.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-value 42))) + +(run-tests) diff --git a/test/check/start_with_test.clj b/test/check/start_with_test.clj index 5256f70..8e362c0 100644 --- a/test/check/start_with_test.clj +++ b/test/check/start_with_test.clj @@ -8,7 +8,7 @@ (defstate test-conn :start 42 :stop #(constantly 0)) -(defstate test-nrepl :start vector) +(defstate test-nrepl :start []) (deftest start-with @@ -44,3 +44,4 @@ (is (instance? mount.core.NotStartedState test-conn)) (is (instance? mount.core.NotStartedState test-nrepl)) (mount/stop)))) + diff --git a/test/check/suspend_resume_test.clj b/test/check/suspend_resume_test.clj index 6e2b9a6..e5d022f 100644 --- a/test/check/suspend_resume_test.clj +++ b/test/check/suspend_resume_test.clj @@ -15,17 +15,17 @@ (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 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 q-listener :start (start :q) + :stop (stop :q) + :suspend (suspend :q) + :resume (resume :q)) -(defstate randomizer :start #(rand-int 42)) +(defstate randomizer :start (rand-int 42)) (deftest suspendable-lifecycle @@ -139,3 +139,5 @@ (is (= q-listener :q-suspended)) (is (= web-server :w-suspended)) (mount/stop)))) + +(run-tests)