Skip to content

Commit

Permalink
install-latest works when providing git :coord without :sha
Browse files Browse the repository at this point in the history
  • Loading branch information
JarrodCTaylor authored and puredanger committed Nov 20, 2024
1 parent 4d43641 commit 9f09a64
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 11 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
23 changes: 12 additions & 11 deletions src/clojure/tools/tools/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
52 changes: 52 additions & 0 deletions test/clojure/tools/tools/api_test.clj
Original file line number Diff line number Diff line change
@@ -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"))))

0 comments on commit 9f09a64

Please sign in to comment.