Skip to content
Browse files

ensure that descriptor-less middleware is added to the end/top of the…

… stack
  • Loading branch information...
1 parent 7356557 commit 3b60ef728b503b42e660ecabbd7ce41adad4e611 @cemerick cemerick committed Aug 20, 2012
View
4 src/main/clojure/clojure/tools/nrepl/middleware.clj
@@ -113,7 +113,8 @@
(remove (comp zero? second)))
lower (ffirst (filter (comp neg? second) comparisons))
upper (ffirst (reverse (filter (comp pos? second) comparisons)))
- [before after] (split-at (or lower (and upper (inc upper)) (count stack)) stack)]
+ ; default conj'ing at the end, a good default for descriptor-less middlewares
+ [before after] (split-at (or (and upper (inc upper)) lower (count stack)) stack)]
(into [] (concat before [x] after))))
;; TODO throw exception when the stack doesn't satisfy the requirements of the descriptors involved
@@ -122,6 +123,7 @@
(->> middlewares
extend-deps
(sort-by (comp count (partial apply concat) (juxt :expects :requires)))
+ reverse
(reduce #(conj-sorted % comparator %2) [])
(map :implemented-by)))
View
10 src/test/clojure/clojure/tools/nrepl/middleware_test.clj
@@ -46,8 +46,9 @@
{:expects #{"eval"} :requires #{n #'clojure.tools.nrepl.middleware.pr-values/pr-values}}}
{:dummy :middleware}
q ^{::middleware/descriptor
- {:expects #{} :requires #{"describe"}}} {:dummy :middleware3}
+ {:expects #{} :requires #{"describe" "eval"}}} {:dummy :middleware3}
stack (indexed-stack (concat default-middlewares [m q n]))]
+ ;(->> stack clojure.set/map-invert (into (sorted-map)) vals println)
(are [before after] (< (stack before) (stack after))
'interruptible-eval m
m 'pr-values
@@ -60,6 +61,13 @@
'wrap-describe 'pr-values
'interruptible-eval 'pr-values)))
+(deftest append-dependency-free-middleware
+ (let [m ^{::middleware/descriptor
+ {:expects #{} :requires #{}}} {:dummy :middleware}
+ n {:dummy "This not-middleware is supposed to be sans-descriptor, don't panic!"}
+ stack (indexed-stack (concat default-middlewares [m n]))]
+ (is (<= (stack n) (stack m) (count stack)))))
+
(deftest no-descriptor-warning
(is (.contains
(with-out-str

0 comments on commit 3b60ef7

Please sign in to comment.
Something went wrong with that request. Please try again.