Skip to content

Commit b7d408b

Browse files
committed
test libs: adjustments for zprint
Current zprint canary test includes installing zprint to local maven repository. Not cleaning this up can cause issues for future runs. Lein will try to resolve deps for the installed zprint which might include a rewrite-clj canary dep which might not exist which will cause lein to fail. Cleanup also good idea because zprint test version is not different form official zprint release version.
1 parent 59f3c9f commit b7d408b

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

script/test_libs.clj

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,21 @@
244244
(defn- zprint-patch [lib]
245245
;; zprint has a project.clj and a deps.edn, patch 'em both
246246
(deps-edn-v1-patch lib)
247-
(project-clj-v1-patch lib))
247+
(project-clj-v1-patch lib)
248+
(show-patch-diff lib))
248249

249250
(defn- zprint-prep [{:keys [home-dir]}]
250251
(status/line :detail "=> Building uberjar for uberjar tests")
251252
(shcmd {:dir home-dir} "lein uberjar")
252-
253-
;; not sure if this is still necessary, but probably does not hurt(?)
253+
;; not sure if this is still necessary...
254254
(status/line :detail "=> Installing zprint locally for ClojureScript tests")
255255
(shcmd {:dir home-dir} "lein install"))
256256

257+
(defn- zprint-cleanup [_lib]
258+
(status/line :detail "=> Deleting jar installed to local maven repo for tests")
259+
;; currently an over-clobber but official zprint libs will re-install as needed
260+
(fs/delete-tree (fs/file (fs/home) ".m2/repository/zprint")))
261+
257262
;;
258263
;; lib defs
259264
;;
@@ -427,15 +432,16 @@
427432
(cli-deps-tree lib))
428433
:test-cmds ["lein with-profile expectations test"
429434
;; disable zprint cljs tests for now, see https://github.com/planck-repl/planck/issues/1088
430-
#_"clojure -M:cljs-runner"]}])
435+
#_"clojure -M:cljs-runner"]
436+
:cleanup-fn zprint-cleanup}])
431437

432438
(defn- header [text]
433439
(let [dashes (apply str (repeat 80 "-"))]
434440
(status/line :head (str dashes "\n"
435441
text "\n"
436442
dashes))))
437443

438-
(defn- test-lib [{:keys [name root patch-fn prep-fn show-deps-fn test-cmds] :as lib}]
444+
(defn- test-lib [{:keys [name root patch-fn prep-fn show-deps-fn test-cmds cleanup-fn] :as lib}]
439445
(header name)
440446
(let [home-dir (do
441447
(status/line :head "%s: Fetching" name)
@@ -450,26 +456,31 @@
450456
(when patch-fn
451457
(status/line :head "%s: Patching" name)
452458
(patch-fn lib))
453-
(when prep-fn
454-
(status/line :head "%s: Preparing" name)
455-
(prep-fn lib))
456-
(when (not show-deps-fn)
457-
(throw (ex-info (format "missing show-deps-fn for %s" name) {})))
458-
(status/line :head "%s: Effect of our patches" name)
459-
(show-patch-diff lib)
460-
(status/line :head "%s: Deps report" name)
461-
(show-deps-fn lib)
462-
(when-not test-cmds
463-
(throw (ex-info (format "missing test-cmds for %s" name) {})))
464-
(status/line :head "%s: Running tests" name)
465-
(let [exit-codes (into [] (map-indexed (fn [ndx cmd]
466-
(let [{:keys [exit]} (shcmd {:dir home-dir :continue true} cmd)]
467-
(if (zero? exit)
468-
(status/line :detail "=> %s: TESTS %d of %d PASSED\n" name (inc ndx) (count test-cmds))
469-
(status/line :warn "=> %s: TESTS %d of %d FAILED" name (inc ndx) (count test-cmds)))
470-
exit))
471-
test-cmds))]
472-
(assoc lib :exit-codes exit-codes))))
459+
(try
460+
(when prep-fn
461+
(status/line :head "%s: Preparing" name)
462+
(prep-fn lib))
463+
(when (not show-deps-fn)
464+
(throw (ex-info (format "missing show-deps-fn for %s" name) {})))
465+
(status/line :head "%s: Effect of our patches" name)
466+
(show-patch-diff lib)
467+
(status/line :head "%s: Deps report" name)
468+
(show-deps-fn lib)
469+
(when-not test-cmds
470+
(throw (ex-info (format "missing test-cmds for %s" name) {})))
471+
(status/line :head "%s: Running tests" name)
472+
(let [exit-codes (into [] (map-indexed (fn [ndx cmd]
473+
(let [{:keys [exit]} (shcmd {:dir home-dir :continue true} cmd)]
474+
(if (zero? exit)
475+
(status/line :detail "=> %s: TESTS %d of %d PASSED\n" name (inc ndx) (count test-cmds))
476+
(status/line :warn "=> %s: TESTS %d of %d FAILED" name (inc ndx) (count test-cmds)))
477+
exit))
478+
test-cmds))]
479+
(assoc lib :exit-codes exit-codes))
480+
(finally
481+
(when cleanup-fn
482+
(status/line :head "%s: Cleanup" name)
483+
(cleanup-fn lib))))))
473484

474485
(defn- prep-target [target-root-dir]
475486
(status/line :head "Prep target")

0 commit comments

Comments
 (0)