Skip to content

Commit

Permalink
Fix #185: throw on non-existing library (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Mar 28, 2024
1 parent 1d47d97 commit ea6ceba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 6 additions & 4 deletions neil
Original file line number Diff line number Diff line change
Expand Up @@ -1236,10 +1236,12 @@ chmod +x bin/kaocha
[v :mvn])
(when-let [v (latest-mvn-version lib)]
[v :mvn])))
_ (when-not version
(throw (ex-info (str "Couldn't find version for lib: " lib) {:babashka/exit 1})))
missing? (nil? version)
mvn? (= coord-type? :mvn)
git-sha? (= coord-type? :git/sha)
git-tag? (= coord-type? :git/tag)
mvn? (= :mvn coord-type?)
git-sha? (= :git/sha coord-type?)
git-tag? (= :git/tag coord-type?)
git-url (when (or git-sha? git-tag?)
(or (:git/url opts)
(str "https://github.com/" (git/clean-github-lib lib))))
Expand Down Expand Up @@ -1679,7 +1681,7 @@ test
curl-get-json)]
(cond
(not license-key) (throw (ex-info "No license key provided." {}))
(= message "Not Found")
(= "Not Found" message)
(throw (ex-info (format "License '%s' not found." license-key) {:license license-key}))
(not body)
(throw (ex-info (format "License '%s' has no body text." (or name license-key))
Expand Down
10 changes: 6 additions & 4 deletions src/babashka/neil.clj
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,12 @@ chmod +x bin/kaocha
[v :mvn])
(when-let [v (latest-mvn-version lib)]
[v :mvn])))
_ (when-not version
(throw (ex-info (str "Couldn't find version for lib: " lib) {:babashka/exit 1})))
missing? (nil? version)
mvn? (= coord-type? :mvn)
git-sha? (= coord-type? :git/sha)
git-tag? (= coord-type? :git/tag)
mvn? (= :mvn coord-type?)
git-sha? (= :git/sha coord-type?)
git-tag? (= :git/tag coord-type?)
git-url (when (or git-sha? git-tag?)
(or (:git/url opts)
(str "https://github.com/" (git/clean-github-lib lib))))
Expand Down Expand Up @@ -821,7 +823,7 @@ test
curl-get-json)]
(cond
(not license-key) (throw (ex-info "No license key provided." {}))
(= message "Not Found")
(= "Not Found" message)
(throw (ex-info (format "License '%s' not found." license-key) {:license license-key}))
(not body)
(throw (ex-info (format "License '%s' has no body text." (or name license-key))
Expand Down
9 changes: 5 additions & 4 deletions tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require
[babashka.deps :as deps]
[babashka.fs :as fs]
[babashka.process :refer [check process tokenize]]
[babashka.process :as process :refer [check process tokenize]]
[babashka.tasks :as tasks]
[clojure.edn :as edn]
[clojure.string :as str]
Expand All @@ -15,7 +15,7 @@

(defn neil [arg & args]
(let [tmp-file (test-file "deps.edn")]
(apply tasks/shell "./neil"
(apply process/shell "./neil"
(concat (tokenize arg) [:deps-file tmp-file] args))
(let [s (slurp tmp-file)]
{:raw s
Expand All @@ -25,7 +25,8 @@
(let [{:keys [edn]} (neil "add dep clj-kondo/clj-kondo")]
(is (-> edn :deps (get 'clj-kondo/clj-kondo))))
(let [{:keys [edn]} (neil "add dep clj-kondo")]
(is (-> edn :deps (get 'clj-kondo/clj-kondo)))))
(is (-> edn :deps (get 'clj-kondo/clj-kondo))))
(is (thrown? Exception (neil "add dep fake-dep"))))

(deftest add-dep-alias-test
(let [{:keys [edn]} (neil "add dep clj-kondo/clj-kondo" :alias :lint)]
Expand All @@ -43,7 +44,7 @@
existing-deps {'clj-kondo/clj-kondo {:tag "v2022.03.08" :sha "247e538"}}]
(spit tmp-file (str "{:deps " existing-deps "}"))
;; note this is not a qualified namespace - no version will be found, it should not be added
(tasks/shell "./neil add dep com.rpl.specter --deps-file" tmp-file)
(tasks/shell {:continue true} "./neil add dep com.rpl.specter --deps-file" tmp-file)
(let [edn (edn/read-string (slurp tmp-file))]
;; make sure existing deps were not deleted
(is (= (-> edn :deps) existing-deps)))))
Expand Down

0 comments on commit ea6ceba

Please sign in to comment.