From ea6ceba1fb4ad6bb2a53239c9baff40fc1a0fb06 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 28 Mar 2024 16:49:38 +0100 Subject: [PATCH] Fix #185: throw on non-existing library (#212) --- neil | 10 ++++++---- src/babashka/neil.clj | 10 ++++++---- tests.clj | 9 +++++---- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/neil b/neil index 27a522b..df0521f 100755 --- a/neil +++ b/neil @@ -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)))) @@ -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)) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 2595d63..4585137 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -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)))) @@ -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)) diff --git a/tests.clj b/tests.clj index f83be44..49c231a 100644 --- a/tests.clj +++ b/tests.clj @@ -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] @@ -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 @@ -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)] @@ -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)))))