[#733] print-deps tests

This commit is contained in:
Michiel Borkent 2021-08-02 23:34:38 +02:00
parent 5a0f056a42
commit be29d791a8
3 changed files with 23 additions and 8 deletions

View file

@ -5,7 +5,8 @@
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.pprint :as pp]
[clojure.string :as str]))
[clojure.string :as str]
[sci.core :as sci]))
(defn print-deps [deps-format]
(let [deps (-> (io/resource "META-INF/babashka/deps.edn")
@ -21,7 +22,8 @@
'org.postgresql/postgresql
'babashka/clojure-lanterna
'seancorfield/next.jdbc
'datascript/datascript)
'datascript/datascript
'org.hsqldb/hsqldb)
bb-edn-deps (:deps @common/bb-edn)
deps (merge deps bb-edn-deps)
paths (:paths @common/bb-edn)
@ -31,4 +33,6 @@
(case deps-format
("deps" nil) (binding [*print-namespace-maps* false]
(pp/pprint deps))
("classpath") (println (str/trim (with-out-str (deps/clojure ["-Spath" "-Sdeps" deps])))))))
("classpath") (let [cp (str/trim (sci/with-out-str
(deps/clojure ["-Spath" "-Sdeps" deps] {:out :string})))]
(println cp)))))

View file

@ -34,6 +34,22 @@
(is (= "src"
(bb "-cp" "src" "-e" "(babashka.classpath/get-classpath)"))))))
(deftest print-deps-test
(test-utils/with-config '{:deps {medley/medley {:mvn/version "1.3.0"}}}
(testing "deps output"
(let [edn (bb "print-deps")
deps (:deps edn)]
(is deps)
(is (map? (get deps 'selmer/selmer)))
(is (string? (:mvn/version (get deps 'selmer/selmer))))
(testing "user provided lib"
(is (map? (get deps 'medley/medley))))))
(testing "classpath output"
(let [classpath (test-utils/bb nil "print-deps" "--format" "classpath")]
(is (str/includes? classpath "selmer"))
(is (str/includes? classpath (System/getProperty "path.separator")))
(is (str/includes? classpath "medley"))))))
(deftest task-test
(test-utils/with-config '{:tasks {foo (+ 1 2 3)}}
(is (= 6 (bb "run" "--prn" "foo"))))

View file

@ -113,8 +113,3 @@ true
(str/replace ":env-key" ":extra-env")))
(is (fs/exists? libs-dir))
(is (fs/exists? libs-dir2)))))
(deftest print-deps-test
)