Skip to content

Commit

Permalink
Fix deps extractor not to throw Exception when the form has unexpecte…
Browse files Browse the repository at this point in the history
…d structure #89
  • Loading branch information
liquidz committed Jun 16, 2021
1 parent 184dbbb commit ef5c6e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/antq/dep/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@

(defn- ignore?
[opt]
(contains? opt :local/root))
(and (map? opt)
(contains? opt :local/root)))

(defmulti extract-type-and-version
(fn [opt]
(or (and (:mvn/version opt) :java)
(and (:git/url opt) :git-sha))))
(if (map? opt)
(or (and (:mvn/version opt) :java)
(and (:git/url opt) :git-sha))
::unknown)))

(defmethod extract-type-and-version :default
[_]
{})

(defmethod extract-type-and-version :java
[opt]
{:type :java
:version (:mvn/version opt)})
Expand All @@ -35,7 +42,8 @@
edn (edn/read-string deps-edn-content-str)]
(walk/postwalk (fn [form]
(when (and (sequential? form)
(#{:deps :extra-deps :replace-deps :override-deps} (first form)))
(#{:deps :extra-deps :replace-deps :override-deps} (first form))
(map? (second form)))
(->> form
(second)
(seq)
Expand Down
5 changes: 5 additions & 0 deletions test/antq/dep/clojure_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
:extra {:url "https://github.com/example/hello.git"}})}
(set deps)))))

(t/deftest extract-deps-unexpected-test
(t/is (empty? (sut/extract-deps file-path "[:deps \"foo\"]")))
(t/is (empty? (sut/extract-deps file-path "{:deps \"foo\"}")))
(t/is (empty? (sut/extract-deps file-path "{:deps {foo/core \"bar\"}}"))))

(t/deftest load-deps-test
(let [deps (sut/load-deps "test/resources/dep")]
(t/is (every? #(contains? #{:java :git-sha} (:type %)) deps))))

0 comments on commit ef5c6e6

Please sign in to comment.