Skip to content

Commit a100ad3

Browse files
committed
Add zprint ClojureScript tests to lib tests suite
Was previously only running zprint's Clojure tests. Now also: - echoing (ish) shelled commands - documenting which platforms are covered for each lib
1 parent 75d57ca commit a100ad3

File tree

1 file changed

+84
-47
lines changed

1 file changed

+84
-47
lines changed

script/libs_tests.clj

Lines changed: 84 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,27 @@
2121
'[io.aviso.ansi :as ansi]
2222
'[release.version :as version])
2323

24+
(defn shcmd-no-exit
25+
"Thin wrapper on babashka.process/process that does not exit on error."
26+
([cmd] (shcmd-no-exit cmd {}))
27+
([cmd opts]
28+
(status/line :detail (str "Running: " (string/join " " cmd)))
29+
(shell/command-no-exit cmd opts)))
30+
31+
(defn shcmd
32+
"Thin wrapper on babashka.process/process that prints error message and exits on error."
33+
([cmd] (shcmd cmd {}))
34+
([cmd opts]
35+
(status/line :detail (str "Running: " (string/join " " cmd)))
36+
(shell/command cmd opts)))
37+
2438
(defn- install-local [version]
2539
(status/line :info (format "Installing rewrite-clj %s locally" version))
2640
(let [pom-bak-filename "pom.xml.canary.bak"]
2741
(try
2842
(fs/copy "pom.xml" pom-bak-filename {:replace-existing true :copy-attributes true})
29-
(shell/command ["clojure" "-X:jar" ":version" (pr-str version)])
30-
(shell/command ["clojure" "-X:deploy:local"])
43+
(shcmd ["clojure" "-X:jar" ":version" (pr-str version)])
44+
(shcmd ["clojure" "-X:deploy:local"])
3145
(finally
3246
(fs/move pom-bak-filename "pom.xml" {:replace-existing true}))))
3347
nil)
@@ -38,17 +52,17 @@
3852
(io/copy
3953
(:body (curl/get (format release-url-fmt version) {:as :stream}))
4054
(io/file target))
41-
(let [zip-root-dir (->> (shell/command ["unzip" "-qql" target] {:out :string})
55+
(let [zip-root-dir (->> (shcmd ["unzip" "-qql" target] {:out :string})
4256
:out
4357
string/split-lines
4458
first
4559
(re-matches #" *\d+ +[\d-]+ +[\d:]+ +(.*)")
4660
second)]
47-
(shell/command ["unzip" target "-d" target-root-dir])
61+
(shcmd ["unzip" target "-d" target-root-dir])
4862
(str (fs/file target-root-dir zip-root-dir)))))
4963

5064
(defn- deps-tree [{:keys [home-dir]} cmd]
51-
(let [{:keys [out err]} (shell/command cmd {:dir home-dir
65+
(let [{:keys [out err]} (shcmd cmd {:dir home-dir
5266
:out :string
5367
:err :string})]
5468
(-> (format "stderr->:\n%s\nstdout->:\n%s" err out)
@@ -65,7 +79,7 @@
6579
(deps-tree lib ["clojure" "-Stree"]))
6680

6781
(defn- patch-rewrite-cljc-sources [home-dir]
68-
(status/line :detail "Patching sources")
82+
(status/line :detail "=> Patching sources")
6983
(doall (map (fn [f]
7084
(let [f (fs/file f)
7185
content (slurp f)
@@ -77,8 +91,8 @@
7791
(fs/glob home-dir "**/*.{clj,cljc,cljs}"))))
7892

7993
(defn- patch-deps [{:keys [filename removals additions]}]
80-
(status/line :detail (format "Patching deps in: %s" filename))
81-
(shell/command ["clojure" "-X:deps-patcher"
94+
(status/line :detail (format "=> Patching deps in: %s" filename))
95+
(shcmd ["clojure" "-X:deps-patcher"
8296
(if (string/ends-with? filename "deps.edn")
8397
"update-deps-deps"
8498
"update-project-deps")
@@ -127,7 +141,7 @@
127141
;; mranderson
128142
;;
129143
(defn- mranderson-patch [{:keys [home-dir rewrite-clj-version]}]
130-
(status/line :detail "Patching deps")
144+
(status/line :detail "=> Patching deps")
131145
(let [p (str (fs/file home-dir "project.clj"))]
132146
(-> p
133147
slurp
@@ -143,11 +157,11 @@
143157
;;
144158

145159
(defn- refactor-nrepl-prep [{:keys [home-dir]}]
146-
(status/line :detail "Inlining deps")
147-
(shell/command ["lein" "inline-deps"] {:dir home-dir}))
160+
(status/line :detail "=> Inlining deps")
161+
(shcmd ["lein" "inline-deps"] {:dir home-dir}))
148162

149163
(defn- refactor-nrepl-patch [{:keys [home-dir rewrite-clj-version]}]
150-
(status/line :detail "Patching deps")
164+
(status/line :detail "=> Patching deps")
151165
(let [p (str (fs/file home-dir "project.clj"))]
152166
(-> p
153167
slurp
@@ -178,8 +192,8 @@
178192
:additions {'rewrite-clj/rewrite-clj {:mvn/version rewrite-clj-version}}}))
179193

180194
(defn- update-leiningen-dependencies-skill-prep [{:keys [home-dir]}]
181-
(status/line :detail "Installing node deps")
182-
(shell/command ["npm" "ci"] {:dir home-dir}))
195+
(status/line :detail "=> Installing node deps")
196+
(shcmd ["npm" "ci"] {:dir home-dir}))
183197

184198
;;
185199
;; zprint
@@ -190,8 +204,8 @@
190204
:removals #{'rewrite-clj 'rewrite-cljs}
191205
:additions [['rewrite-clj rewrite-clj-version]]})
192206

193-
(status/line :detail "Hacking lift-ns to compensate for rewrite-clj v0->v1 change in sexpr on nsmap keys")
194-
(status/line :detail "- note the word 'hacking' - hacked for to get test passing nly")
207+
(status/line :detail "=> Hacking lift-ns to compensate for rewrite-clj v0->v1 change in sexpr on nsmap keys")
208+
(status/line :detail "- note the word 'hacking' - hacked for to get test passing only")
195209
(let [src-filename (str (fs/file home-dir "src/zprint/zutil.cljc"))
196210
orig-filename (str src-filename ".orig")
197211
content (slurp src-filename)
@@ -205,92 +219,110 @@
205219
replace-str
206220
(subs content (+ ndx (count find-str)))))
207221
(throw (ex-info "hacking zprint failed" {})))
208-
(status/line :detail (format "here's the diff for %s" src-filename))
209-
(shell/command-no-exit ["git" "--no-pager" "diff" "--no-index" orig-filename src-filename])))
222+
(status/line :detail (format "-> here's the diff for %s" src-filename))
223+
(shcmd-no-exit ["git" "--no-pager" "diff" "--no-index" orig-filename src-filename])))
210224

211225
(defn- zprint-prep [{:keys [target-root-dir home-dir]}]
212-
(status/line :detail "Installing not-yet-released expectations/cljc-test")
226+
(status/line :detail "=> Installing not-yet-released expectations/cljc-test")
213227
(let [clone-to-dir (str (fs/file target-root-dir "clojure-test"))]
214-
(shell/command ["git" "clone" "--branch" "enhancements"
228+
(shcmd ["git" "clone" "--branch" "enhancements"
215229
"https://github.com/kkinnear/clojure-test.git" clone-to-dir])
216-
(run! #(shell/command % {:dir clone-to-dir})
230+
(run! #(shcmd % {:dir clone-to-dir})
217231
[["git" "reset" "--hard" "a6c3be067ab06f677d3b1703ee4092d25db2bb60"]
218232
["clojure" "-M:jar"]
219233
["mvn" "install:install-file" "-Dfile=expectations.jar" "-DpomFile=pom.xml"]]))
220-
(status/line :detail "Building uberjar for uberjar tests")
221-
(shell/command ["lein" "uberjar"] {:dir home-dir}))
234+
235+
(status/line :detail "=> Building uberjar for uberjar tests")
236+
(shcmd ["lein" "uberjar"] {:dir home-dir})
237+
238+
(status/line :detail "=> Installing zprint locally for ClojureScript tests")
239+
(shcmd ["lein" "install"] {:dir home-dir}))
222240

223241
;;
224242
;; lib defs
225243
;;
226244

227245
(def libs [{:name "antq"
228246
:version "0.11.2"
247+
:platforms [:clj]
229248
:release-url-fmt "https://github.com/liquidz/antq/archive/%s.zip"
230249
:patch-fn antq-patch
231250
:show-deps-fn cli-deps-tree
232-
:test-cmd ["clojure" "-M:dev:test"]}
251+
:test-cmds [["clojure" "-M:dev:test"]]}
233252
{:name "carve"
234253
:version "0.0.2"
254+
:platforms [:clj]
235255
:release-url-fmt "https://github.com/borkdude/carve/archive/v%s.zip"
236256
:patch-fn carve-patch
237257
:show-deps-fn cli-deps-tree
238-
:test-cmd ["clojure" "-M:test"]}
258+
:test-cmds [["clojure" "-M:test"]]}
239259
{:name "cljfmt"
240260
:version "0.7.0"
261+
:platforms [:clj :cljs]
241262
:root "cljfmt"
242263
:release-url-fmt "https://github.com/weavejester/cljfmt/archive/%s.zip"
243264
:patch-fn cljfmt-patch
244265
:show-deps-fn lein-deps-tree
245-
:test-cmd ["lein" "test"]}
266+
:test-cmds [["lein" "test"]]}
246267
{:name "clojure-lsp"
268+
:platforms [:clj]
247269
:version "2021.03.01-19.18.54"
248270
:release-url-fmt "https://github.com/clojure-lsp/clojure-lsp/archive/%s.zip"
249271
:patch-fn clojure-lsp-patch
250272
:show-deps-fn lein-deps-tree
251-
:test-cmd ["lein" "test"]}
273+
:test-cmds [["lein" "test"]]}
252274
{:name "mranderson"
253275
:version "0.5.3"
276+
:platforms [:clj]
254277
:release-url-fmt "https://github.com/benedekfazekas/mranderson/archive/v%s.zip"
255278
:patch-fn mranderson-patch
256279
:show-deps-fn lein-deps-tree
257-
:test-cmd ["lein" "test"]}
280+
:test-cmds [["lein" "test"]]}
258281
{:name "rewrite-edn"
259282
:version "665f61cf273c79b44baacb0897d72c2157e27b09"
283+
:platforms [:clj]
260284
:release-url-fmt "https://github.com/borkdude/rewrite-edn/zipball/%s"
261285
:patch-fn rewrite-edn-patch
262286
:show-deps-fn cli-deps-tree
263-
:test-cmd ["clojure" "-M:test"]}
287+
:test-cmds [["clojure" "-M:test"]]}
264288
{:name "refactor-nrepl"
265289
:version "2.5.1"
290+
:platforms [:clj]
266291
:release-url-fmt "https://github.com/clojure-emacs/refactor-nrepl/archive/v%s.zip"
267292
:patch-fn refactor-nrepl-patch
268293
:show-deps-fn lein-deps-tree
269294
:prep-fn refactor-nrepl-prep
270-
:test-cmd ["lein" "with-profile" "+1.10,+plugin.mranderson/config" "test"]}
295+
:test-cmds [["lein" "with-profile" "+1.10,+plugin.mranderson/config" "test"]]}
271296
{:name "update-leiningen-dependencies-skill"
272297
:version "21c7ce794c83d6eed9c2a27e2fdd527b5da8ebb3"
298+
:platforms [:cljs]
273299
:release-url-fmt "https://github.com/atomist-skills/update-leiningen-dependencies-skill/zipball/%s"
274300
:patch-fn update-leiningen-dependencies-skill-patch
275301
:prep-fn update-leiningen-dependencies-skill-prep
276302
:show-deps-fn cli-deps-tree
277-
:test-cmd ["npm" "run" "test"]}
303+
:test-cmds [["npm" "run" "test"]]}
278304
{:name "zprint"
279305
:version "1.1.1"
306+
:platforms [:clj :cljs]
280307
:note "zprint src hacked to pass with rewrite-clj v1"
281-
:release-url-fmt "https://github.com/kkinnear/zprint/archive/%s.zip"
308+
:release-url-fmt "https://github.com/kkinnear/zprint/archive/%s.zip"
282309
:patch-fn zprint-patch
283-
:show-deps-fn lein-deps-tree
284310
:prep-fn zprint-prep
285-
:test-cmd ["lein" "with-profile" "expectations" "test"]}])
311+
:show-deps-fn (fn [lib]
312+
(status/line :detail "=> Deps for Clojure run:")
313+
(lein-deps-tree lib)
314+
(status/line :detail "=> Deps Clojurescript run:")
315+
(cli-deps-tree lib))
316+
:test-cmds [["lein" "with-profile" "expectations" "test"]
317+
["clj" "-M:cljs-runner"]]}])
286318

287319
(defn- header [text]
288320
(let [dashes (apply str (repeat 80 "-"))]
289321
(status/line :info (str dashes "\n"
290322
text "\n"
291323
dashes))))
292324

293-
(defn- test-lib [{:keys [name root patch-fn prep-fn show-deps-fn test-cmd] :as lib}]
325+
(defn- test-lib [{:keys [name root patch-fn prep-fn show-deps-fn test-cmds] :as lib}]
294326
(header name)
295327
(let [home-dir (do
296328
(status/line :info (format "%s: Fetching" name))
@@ -307,15 +339,17 @@
307339
(throw (ex-info (format "missing show-deps-fn for %s" name) {})))
308340
(status/line :info (format "%s: Deps report" name))
309341
(show-deps-fn lib)
310-
(when-not test-cmd
311-
(throw (ex-info (format "missing test-cmd for %s" name) {})))
342+
(when-not test-cmds
343+
(throw (ex-info (format "missing test-cmds for %s" name) {})))
312344
(status/line :info (format "%s: Running tests" name))
313-
(let [{:keys [exit]} (shell/command-no-exit test-cmd {:dir home-dir})]
314-
(status/line :detail "\n")
315-
(if (zero? exit)
316-
(status/line :detail (format "%s: TESTS PASSED" name))
317-
(status/line :warn (format "%s: TESTS FAILED" name)))
318-
(assoc lib :exit-code exit))))
345+
(let [exit-codes (into [] (map-indexed (fn [ndx cmd]
346+
(let [{:keys [exit]} (shcmd-no-exit cmd {:dir home-dir})]
347+
(if (zero? exit)
348+
(status/line :detail (format "=> %s: TESTS %d of %d PASSED\n" name (inc ndx) (count test-cmds)))
349+
(status/line :warn (format "=> %s: TESTS %d of %d FAILED" name (inc ndx) (count test-cmds))))
350+
exit))
351+
test-cmds))]
352+
(assoc lib :exit-codes exit-codes))))
319353

320354
(defn main [args]
321355
;; no args = test all libs
@@ -333,16 +367,19 @@
333367
target-root-dir "target/libs-test"
334368
_ (when (fs/exists? target-root-dir) (fs/delete-tree target-root-dir))
335369
rewrite-clj-version (str (version/calc) "-canary")]
336-
(status/line :detail (format "requested libs: %s" (into [] (map :name requested-libs))))
370+
(status/line :detail (format "Requested libs: %s" (into [] (map :name requested-libs))))
337371
(install-local rewrite-clj-version)
338372
(let [results (doall (map #(test-lib (assoc %
339373
:target-root-dir target-root-dir
340374
:rewrite-clj-version rewrite-clj-version))
341375
requested-libs))]
342376
(status/line :info "Summary")
343-
(println (doric/table [:name :version :note :exit-code] results))
344-
(System/exit (if (every? #(zero? (:exit-code %)) results) 0 1))))
377+
(println (doric/table [:name :version :platforms :note :exit-codes] results))
378+
(System/exit (if (->> results
379+
(map :exit-codes)
380+
flatten
381+
(every? zero?))
382+
0 1))))
345383
nil)
346384

347385
(main *command-line-args*)
348-

0 commit comments

Comments
 (0)