From 9f09a6414b7edcf92c6d925333c5057dd89d24c6 Mon Sep 17 00:00:00 2001 From: JarrodCTaylor Date: Wed, 20 Nov 2024 12:39:06 -0600 Subject: [PATCH] install-latest works when providing git :coord without :sha --- .github/workflows/ci.yml | 27 ++++++++++++++ README.md | 8 +++++ deps.edn | 4 +++ src/clojure/tools/tools/api.clj | 23 ++++++------ test/clojure/tools/tools/api_test.clj | 52 +++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 test/clojure/tools/tools/api_test.clj diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bb0b948 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: Clojure Tests + +on: + push: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Install rlwrap + run: sudo apt-get install -y rlwrap + + - name: Install Clojure Tools + uses: DeLaGuardo/setup-clojure@13.0 + with: + cli: latest + + - name: Run tests + run: clj -X:test \ No newline at end of file diff --git a/README.md b/README.md index d208c76..2bb5f24 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,14 @@ io.github.clojure/tools.tools {:git/tag "v0.3.3" :git/sha "2f4d299"} * [How to contribute](https://clojure.org/community/contributing) * [Bug Tracker](https://clojure.atlassian.net/browse/TDEPS) +# Tests + +Run test + +``` sh +clj -X:test +``` + # Copyright and License Copyright © Rich Hickey, Alex Miller, and contributors diff --git a/deps.edn b/deps.edn index cc89463..7ff40fc 100644 --- a/deps.edn +++ b/deps.edn @@ -20,5 +20,9 @@ :exec-args {:source-paths ["src"] :namespaces [clojure.tools.tools.api] :output-path "docs"}} + :test {:extra-paths ["test"] + :extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}} + :main-opts ["-m" "cognitect.test-runner"] + :exec-fn cognitect.test-runner.api/test} } } diff --git a/src/clojure/tools/tools/api.clj b/src/clojure/tools/tools/api.clj index 34147c8..1bf4294 100644 --- a/src/clojure/tools/tools/api.clj +++ b/src/clojure/tools/tools/api.clj @@ -74,18 +74,19 @@ (defn- install-1 [lib coord as master-edn] (let [current (tool/resolve-tool as) - coord (or coord (->> (ext/find-all-versions lib (:coord current) master-edn) - (filter release-version?) - last - (merge (:coord current))))] - (if coord - (if (and current (= lib (:lib current)) (zero? (ext/compare-versions lib (:coord current) coord master-edn))) - (println (str as ":") "Skipping, newest installed" (ext/coord-summary lib coord)) + coord (or coord (:coord current)) + latest-coord (->> (ext/find-all-versions lib coord master-edn) + (filter release-version?) + last + (merge coord))] + (if latest-coord + (if (and current (= lib (:lib current)) (zero? (ext/compare-versions lib (:coord current) latest-coord master-edn))) + (println (str as ":") "Skipping, newest installed" (ext/coord-summary lib latest-coord)) (do - (tool/install-tool lib coord as) - (println (str as ":") "Installed" (ext/coord-summary lib coord) + (tool/install-tool lib latest-coord as) + (println (str as ":") "Installed" (ext/coord-summary lib latest-coord) (binding [*print-namespace-maps* false] - (pr-str coord))))) + (pr-str latest-coord))))) (println (str as ":") "Did not find versions for" lib)))) (defn install-latest @@ -111,7 +112,7 @@ Options: :tool tool-name - currently installed tool :lib lib-name - mvn lib or git lib with inferrable url - :coord - coord map if needed (note: git coords may omit sha) + :coord - coord map if needed (note: git coords only use :git/url) :as - tool name Example: diff --git a/test/clojure/tools/tools/api_test.clj b/test/clojure/tools/tools/api_test.clj new file mode 100644 index 0000000..0990ffd --- /dev/null +++ b/test/clojure/tools/tools/api_test.clj @@ -0,0 +1,52 @@ +(ns clojure.tools.tools.api-test + (:require + [clojure.string :as str] + [clojure.test :refer :all] + [clojure.tools.tools.api :as sut])) + +(def tool-install-name "temporary-ci-test-tool") + +(deftest install-update-list-and-remove + (testing "Install specific version that is not the latest" + (let [expected-response (str tool-install-name ": Installed com.github.seancorfield/deps-new v0.4.9") + actual-response (with-out-str (sut/install {'com.github.seancorfield/deps-new {:git/url "https://github.com/seancorfield/deps-new" + :git/tag "v0.4.9"} :as tool-install-name}))] + (is (str/includes? actual-response expected-response)))) + + (testing "list installed tools" + (let [expected-response (re-pattern (str tool-install-name "\\s*com\\.github\\.seancorfield/deps-new\\s*:git\\s*v0\\.4\\.9")) + actual-response (with-out-str (sut/list nil))] + (is (re-find expected-response actual-response)))) + + (testing "update installed tool to latest version" + ;; Would be more desirable if we had a test tool to install and could check the specific version that wouldn't change + (let [expected-response (re-pattern (str tool-install-name ": Installed com\\.github\\.seancorfield/deps-new")) + actual-response (with-out-str (sut/install-latest {:tool tool-install-name}))] + (is (re-find expected-response actual-response)))) + + (testing "list installed tools reflects updated version" + (let [old-tool (re-pattern (str tool-install-name "\\s*com\\.github\\.seancorfield/deps-new\\s*:git\\s*v0\\.4\\.9")) + expected-response (re-pattern (str tool-install-name "\\s*com\\.github\\.seancorfield/deps-new")) + actual-response (with-out-str (sut/list nil))] + (is (not (re-find old-tool actual-response)) "The old tool was not successfully updated") + (is (re-find expected-response actual-response)))) + + (testing "remove installed tool" + (let [removal-response (with-out-str (sut/remove {:tool tool-install-name})) + list-response (with-out-str (sut/list nil))] + (is (str/includes? removal-response "Tool removed")) + (is (not (str/includes? list-response tool-install-name)) "The tool was not successfully removed")))) + +(deftest install-latest-git-procurer-with-provided-coord + (testing "Installed latest version of tool, for git procurer providing coord" + (let [expected-response (re-pattern (str tool-install-name ": Installed com\\.github\\.seancorfield/deps-new")) + actual-response (with-out-str (sut/install-latest {:lib 'com.github.seancorfield/deps-new + :coord {:git/url "https://github.com/seancorfield/deps-new"} + :as tool-install-name}))] + (is (re-find expected-response actual-response)))) + + (testing "remove installed tool" + (let [removal-response (with-out-str (sut/remove {:tool tool-install-name})) + list-response (with-out-str (sut/list nil))] + (is (str/includes? removal-response "Tool removed")) + (is (not (str/includes? list-response tool-install-name)) "The tool was not successfully removed")))) \ No newline at end of file