Skip to content

Commit 9f09a64

Browse files
JarrodCTaylorpuredanger
authored andcommitted
install-latest works when providing git :coord without :sha
1 parent 4d43641 commit 9f09a64

5 files changed

Lines changed: 103 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Clojure Tests
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Setup Java
13+
uses: actions/setup-java@v4
14+
with:
15+
distribution: 'temurin'
16+
java-version: '17'
17+
18+
- name: Install rlwrap
19+
run: sudo apt-get install -y rlwrap
20+
21+
- name: Install Clojure Tools
22+
uses: DeLaGuardo/setup-clojure@13.0
23+
with:
24+
cli: latest
25+
26+
- name: Run tests
27+
run: clj -X:test

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ io.github.clojure/tools.tools {:git/tag "v0.3.3" :git/sha "2f4d299"}
2929
* [How to contribute](https://clojure.org/community/contributing)
3030
* [Bug Tracker](https://clojure.atlassian.net/browse/TDEPS)
3131

32+
# Tests
33+
34+
Run test
35+
36+
``` sh
37+
clj -X:test
38+
```
39+
3240
# Copyright and License
3341

3442
Copyright © Rich Hickey, Alex Miller, and contributors

deps.edn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@
2020
:exec-args {:source-paths ["src"]
2121
:namespaces [clojure.tools.tools.api]
2222
:output-path "docs"}}
23+
:test {:extra-paths ["test"]
24+
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
25+
:main-opts ["-m" "cognitect.test-runner"]
26+
:exec-fn cognitect.test-runner.api/test}
2327
}
2428
}

src/clojure/tools/tools/api.clj

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,19 @@
7474
(defn- install-1
7575
[lib coord as master-edn]
7676
(let [current (tool/resolve-tool as)
77-
coord (or coord (->> (ext/find-all-versions lib (:coord current) master-edn)
78-
(filter release-version?)
79-
last
80-
(merge (:coord current))))]
81-
(if coord
82-
(if (and current (= lib (:lib current)) (zero? (ext/compare-versions lib (:coord current) coord master-edn)))
83-
(println (str as ":") "Skipping, newest installed" (ext/coord-summary lib coord))
77+
coord (or coord (:coord current))
78+
latest-coord (->> (ext/find-all-versions lib coord master-edn)
79+
(filter release-version?)
80+
last
81+
(merge coord))]
82+
(if latest-coord
83+
(if (and current (= lib (:lib current)) (zero? (ext/compare-versions lib (:coord current) latest-coord master-edn)))
84+
(println (str as ":") "Skipping, newest installed" (ext/coord-summary lib latest-coord))
8485
(do
85-
(tool/install-tool lib coord as)
86-
(println (str as ":") "Installed" (ext/coord-summary lib coord)
86+
(tool/install-tool lib latest-coord as)
87+
(println (str as ":") "Installed" (ext/coord-summary lib latest-coord)
8788
(binding [*print-namespace-maps* false]
88-
(pr-str coord)))))
89+
(pr-str latest-coord)))))
8990
(println (str as ":") "Did not find versions for" lib))))
9091

9192
(defn install-latest
@@ -111,7 +112,7 @@
111112
Options:
112113
:tool tool-name - currently installed tool
113114
:lib lib-name - mvn lib or git lib with inferrable url
114-
:coord - coord map if needed (note: git coords may omit sha)
115+
:coord - coord map if needed (note: git coords only use :git/url)
115116
:as - tool name
116117
117118
Example:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(ns clojure.tools.tools.api-test
2+
(:require
3+
[clojure.string :as str]
4+
[clojure.test :refer :all]
5+
[clojure.tools.tools.api :as sut]))
6+
7+
(def tool-install-name "temporary-ci-test-tool")
8+
9+
(deftest install-update-list-and-remove
10+
(testing "Install specific version that is not the latest"
11+
(let [expected-response (str tool-install-name ": Installed com.github.seancorfield/deps-new v0.4.9")
12+
actual-response (with-out-str (sut/install {'com.github.seancorfield/deps-new {:git/url "https://github.com/seancorfield/deps-new"
13+
:git/tag "v0.4.9"} :as tool-install-name}))]
14+
(is (str/includes? actual-response expected-response))))
15+
16+
(testing "list installed tools"
17+
(let [expected-response (re-pattern (str tool-install-name "\\s*com\\.github\\.seancorfield/deps-new\\s*:git\\s*v0\\.4\\.9"))
18+
actual-response (with-out-str (sut/list nil))]
19+
(is (re-find expected-response actual-response))))
20+
21+
(testing "update installed tool to latest version"
22+
;; Would be more desirable if we had a test tool to install and could check the specific version that wouldn't change
23+
(let [expected-response (re-pattern (str tool-install-name ": Installed com\\.github\\.seancorfield/deps-new"))
24+
actual-response (with-out-str (sut/install-latest {:tool tool-install-name}))]
25+
(is (re-find expected-response actual-response))))
26+
27+
(testing "list installed tools reflects updated version"
28+
(let [old-tool (re-pattern (str tool-install-name "\\s*com\\.github\\.seancorfield/deps-new\\s*:git\\s*v0\\.4\\.9"))
29+
expected-response (re-pattern (str tool-install-name "\\s*com\\.github\\.seancorfield/deps-new"))
30+
actual-response (with-out-str (sut/list nil))]
31+
(is (not (re-find old-tool actual-response)) "The old tool was not successfully updated")
32+
(is (re-find expected-response actual-response))))
33+
34+
(testing "remove installed tool"
35+
(let [removal-response (with-out-str (sut/remove {:tool tool-install-name}))
36+
list-response (with-out-str (sut/list nil))]
37+
(is (str/includes? removal-response "Tool removed"))
38+
(is (not (str/includes? list-response tool-install-name)) "The tool was not successfully removed"))))
39+
40+
(deftest install-latest-git-procurer-with-provided-coord
41+
(testing "Installed latest version of tool, for git procurer providing coord"
42+
(let [expected-response (re-pattern (str tool-install-name ": Installed com\\.github\\.seancorfield/deps-new"))
43+
actual-response (with-out-str (sut/install-latest {:lib 'com.github.seancorfield/deps-new
44+
:coord {:git/url "https://github.com/seancorfield/deps-new"}
45+
:as tool-install-name}))]
46+
(is (re-find expected-response actual-response))))
47+
48+
(testing "remove installed tool"
49+
(let [removal-response (with-out-str (sut/remove {:tool tool-install-name}))
50+
list-response (with-out-str (sut/list nil))]
51+
(is (str/includes? removal-response "Tool removed"))
52+
(is (not (str/includes? list-response tool-install-name)) "The tool was not successfully removed"))))

0 commit comments

Comments
 (0)