Skip to content

Commit 355d278

Browse files
committed
TDEPS-238 & TDEPS-239
* Validate deps.edn with existing spec * Empty deps.edn is valid * Added tests
1 parent f7ae85d commit 355d278

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/main/clojure/clojure/tools/deps.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
(:require
1111
[clojure.java.io :as jio]
1212
[clojure.set :as set]
13+
[clojure.spec.alpha :as s]
1314
[clojure.string :as str]
1415
[clojure.tools.deps.util.concurrent :as concurrent]
1516
[clojure.tools.deps.util.dir :as dir]
1617
[clojure.tools.deps.util.io :as io]
1718
[clojure.tools.deps.util.session :as session]
1819
[clojure.tools.deps.extensions :as ext]
20+
[clojure.tools.deps.specs :as specs]
1921
[clojure.walk :as walk])
2022
(:import
2123
[clojure.lang EdnReader$ReaderException]
@@ -34,6 +36,9 @@
3436
(let [path (.getAbsolutePath f)]
3537
(ex-info (format fmt path) {:path path})))
3638

39+
(defn valid-deps? [m]
40+
(s/valid? ::specs/deps-map m))
41+
3742
(defn- slurp-edn-map
3843
"Read the file specified by the path-segments, slurp it, and read it as edn."
3944
[^File f]
@@ -43,9 +48,9 @@
4348
(if (str/starts-with? (.getMessage t) "EOF while reading")
4449
(throw (io-err "Error reading edn, delimiter unmatched (%s)" f))
4550
(throw (io-err (str "Error reading edn. " (.getMessage t) " (%s)") f)))))]
46-
(if (map? val)
51+
(if (valid-deps? val)
4752
val
48-
(throw (io-err "Expected edn map in: %s" f)))))
53+
(throw (io-err "%s is not valid." f)))))
4954

5055
;; all this canonicalization is deprecated and will eventually be removed
5156

src/main/clojure/clojure/tools/deps/specs.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
(s/def ::paths :aliased/paths)
8888
(s/def ::deps (s/map-of ::lib ::coord))
8989
(s/def ::aliases (s/map-of ::alias any?))
90-
(s/def ::deps-map (s/keys
91-
:opt-un [::paths ::deps ::aliases]
92-
:opt [:mvn/repos :mvn/local-repo :tools/usage :deps/prep-lib]))
90+
(s/def ::deps-map (s/nilable (s/keys
91+
:opt-un [::paths ::deps ::aliases]
92+
:opt [:mvn/repos :mvn/local-repo :tools/usage :deps/prep-lib])))
9393

9494
;; lib map
9595
;; a map of lib to resolved coordinate (a coord with a ::path) and dependent info

src/test/clojure/clojure/tools/deps/test_deps.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,18 @@
295295
(let [b (deps/create-basis {:user nil :project adeps})]
296296
(is (contains? (:classpath b) (.getAbsolutePath (jio/file bdir "src"))))))))
297297

298+
(deftest empty-nil-deps-is-valid
299+
(testing "file exists but is empty (nil)"
300+
(is (deps/valid-deps? nil))))
301+
302+
(deftest TDEPS-238
303+
(testing "deps are invalid with extra nested vector in :exclusions"
304+
(let [invalid {:deps
305+
{'org.clojure/core.memoize
306+
{:mvn/version "1.0.257"
307+
:exclusions [['org.clojure/data.priority-map]]}}}]
308+
(is (not (deps/valid-deps? invalid))))))
309+
298310
(comment
299311
(test-local-root-relative-to-project-deps)
300312
)

0 commit comments

Comments
 (0)