Browse files

TNS-19: always return set from `parse/deps-from-ns-decl`

clojure.set/union is wildly unpredictable given a mix of nils and
empty sets as input. Sometimes it returns nil, sometimes an empty set.

To ensure the result is always a set, we can use `mapcat` instead and
call `set` at the end.
  • Loading branch information...
1 parent c3a5a48 commit e9394727b6e6ca4491bb4e058edabd30e6524915 @stuartsierra stuartsierra committed Jun 13, 2014
@@ -60,30 +60,29 @@
(defn- deps-from-libspec [prefix form]
(cond (prefix-spec? form)
- (apply set/union
- (map (fn [f] (deps-from-libspec
- (symbol (str (when prefix (str prefix "."))
- (first form)))
- f))
- (rest form)))
+ (mapcat (fn [f] (deps-from-libspec
+ (symbol (str (when prefix (str prefix "."))
+ (first form)))
+ f))
+ (rest form))
(option-spec? form)
(deps-from-libspec prefix (first form))
(symbol? form)
- #{(symbol (str (when prefix (str prefix ".")) form))}
+ (list (symbol (str (when prefix (str prefix ".")) form)))
(keyword? form) ; Some people write (:require ... :reload-all)
- #{}
+ nil
(throw (IllegalArgumentException.
(pr-str "Unparsable namespace form:" form)))))
(defn- deps-from-ns-form [form]
(when (and (list? form)
(contains? #{:use :require} (first form)))
- (apply set/union (map #(deps-from-libspec nil %) (rest form)))))
+ (mapcat #(deps-from-libspec nil %) (rest form))))
(defn deps-from-ns-decl
"Given an (ns...) declaration form (unevaluated), returns a set of
symbols naming the dependencies of that namespace. Handles :use and
:require clauses but not :load."
- (apply set/union (map deps-from-ns-form decl)))
+ (set (mapcat deps-from-ns-form decl)))
@@ -49,3 +49,6 @@
(deftest t-prefix-list-as-vector
(is (= deps-from-prefix-list
(deps-from-ns-decl ns-decl-prefix-list-as-vector))))
+(deftest t-no-deps-returns-empty-set
+ (is (= #{} (deps-from-ns-decl '(ns

0 comments on commit e939472

Please sign in to comment.