From 92644a3bd0a10fadc7fef351a5dee0ac50b31175 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sun, 5 May 2024 10:02:37 -0700 Subject: [PATCH] Add `upgrade-maven-jar-test` --- bbin | 12 ++++----- src/babashka/bbin/scripts/maven_jar.clj | 12 ++++----- test/babashka/bbin/scripts/maven_jar_test.clj | 26 ++++++++++++++++--- test/babashka/bbin/test_util.clj | 4 +++ 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/bbin b/bbin index e1f9fd3..492ee87 100755 --- a/bbin +++ b/bbin @@ -1282,9 +1282,7 @@ WARNING: (We won't make any changes without asking you first.) (let [vparse (requiring-resolve 'version-clj.core/parse)] (some (fn [version] (let [{:keys [qualifiers]} (vparse version)] - (when-not - ;; assume all qualifiers indicate non-stable version - (some #{"rc" "alpha" "beta" "snapshot" "milestone"} qualifiers) + (when-not (some #{"rc" "alpha" "beta" "snapshot" "milestone"} qualifiers) version))) versions))) @@ -1355,9 +1353,11 @@ WARNING: (We won't make any changes without asking you first.) (upgrade [_] (let [latest-version (or (latest-stable-clojars-version lib) - (latest-stable-mvn-version lib))] - (p/install (map->MavenJar {:cli-opts {:script/lib (str lib) - :mvn/version latest-version} + (latest-stable-mvn-version lib)) + cli-opts' (merge (select-keys cli-opts [:edn]) + {:script/lib (str lib) + :mvn/version latest-version})] + (p/install (map->MavenJar {:cli-opts cli-opts' :lib lib})))) (uninstall [_] diff --git a/src/babashka/bbin/scripts/maven_jar.clj b/src/babashka/bbin/scripts/maven_jar.clj index d30f300..4a58572 100644 --- a/src/babashka/bbin/scripts/maven_jar.clj +++ b/src/babashka/bbin/scripts/maven_jar.clj @@ -48,9 +48,7 @@ (let [vparse (requiring-resolve 'version-clj.core/parse)] (some (fn [version] (let [{:keys [qualifiers]} (vparse version)] - (when-not - ;; assume all qualifiers indicate non-stable version - (some #{"rc" "alpha" "beta" "snapshot" "milestone"} qualifiers) + (when-not (some #{"rc" "alpha" "beta" "snapshot" "milestone"} qualifiers) version))) versions))) @@ -121,9 +119,11 @@ (upgrade [_] (let [latest-version (or (latest-stable-clojars-version lib) - (latest-stable-mvn-version lib))] - (p/install (map->MavenJar {:cli-opts {:script/lib (str lib) - :mvn/version latest-version} + (latest-stable-mvn-version lib)) + cli-opts' (merge (select-keys cli-opts [:edn]) + {:script/lib (str lib) + :mvn/version latest-version})] + (p/install (map->MavenJar {:cli-opts cli-opts' :lib lib})))) (uninstall [_] diff --git a/test/babashka/bbin/scripts/maven_jar_test.clj b/test/babashka/bbin/scripts/maven_jar_test.clj index 55681c0..28646e6 100644 --- a/test/babashka/bbin/scripts/maven_jar_test.clj +++ b/test/babashka/bbin/scripts/maven_jar_test.clj @@ -11,6 +11,9 @@ {:lib 'org.babashka/http-server :coords {:mvn/version "0.1.11"}}) +(def help-text + "Serves static assets using web server.") + (deftest install-from-mvn-version-test (testing "install */* --mvn/version *" (tu/reset-test-dir) @@ -21,7 +24,22 @@ (is (= maven-lib out)) (is (fs/exists? (fs/file (dirs/bin-dir nil) (name (:lib maven-lib))))) (is (str/starts-with? (tu/run-bin-script (:lib maven-lib) "--help") - "Serves static assets using web server.")) - (is (= '{http-server {:lib org.babashka/http-server - :coords {:mvn/version "0.1.11"}}} - (tu/run-ls)))))) + help-text)) + (is (= `{~'http-server ~maven-lib} (tu/run-ls)))))) + +(def upgraded-lib + (assoc-in maven-lib [:coords :mvn/version] "0.1.12")) + +(deftest upgrade-maven-jar-test + (testing "upgrade (maven jar)" + (tu/reset-test-dir) + (dirs/ensure-bbin-dirs {}) + (let [out (tu/run-install {:script/lib (str (:lib maven-lib)) + :mvn/version (-> maven-lib :coords :mvn/version)}) + out2 (tu/run-upgrade {:script/lib "http-server"})] + (is (= maven-lib out)) + (is (= upgraded-lib out2)) + (is (fs/exists? (fs/file (dirs/bin-dir nil) (name (:lib upgraded-lib))))) + (is (str/starts-with? (tu/run-bin-script (:lib upgraded-lib) "--help") + help-text)) + (is (= `{~'http-server ~upgraded-lib} (tu/run-ls)))))) diff --git a/test/babashka/bbin/test_util.clj b/test/babashka/bbin/test_util.clj index 0d96092..7745192 100644 --- a/test/babashka/bbin/test_util.clj +++ b/test/babashka/bbin/test_util.clj @@ -58,6 +58,10 @@ (some-> (with-out-str (scripts/install (assoc cli-opts :edn true))) edn/read-string)) +(defn run-upgrade [cli-opts] + (some-> (with-out-str (scripts/upgrade (assoc cli-opts :edn true))) + edn/read-string)) + (defn run-ls [] (some-> (with-out-str (scripts/ls {:edn true})) edn/read-string))