Skip to content

Commit 5ea1928

Browse files
committed
Add cljstyle to libs tests
Required 2 hacks - internal usage of StringNode needed to updated - had expectation on exception type (we moved to ExceptionInfo for cross platform throwing in clj/cljs) Also now git init-ing in lib home dir rather than in lib tests root dir. Some libs expect to have been cloned, and this satisfies that expectation. Cljstyle is one of those libs.
1 parent 61253ea commit 5ea1928

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

README.adoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Some projects using rewrite-clj v0 and/or rewrite-cljs
5656

5757
* https://github.com/mauricioszabo/atom-chlorine[atom-chlorine]
5858
* https://github.com/weavejester/cljfmt[cljfmt] ^t^
59-
* https://github.com/greglook/cljstyle[cljstyle]
59+
* https://github.com/greglook/cljstyle[cljstyle] ^t^ ^h^
6060
* https://github.com/Olical/depot[depot]
6161
* https://github.com/jonase/kibit[kibit]
6262
* https://github.com/xsc/lein-ancient[lein-ancient]
@@ -66,11 +66,12 @@ Some projects using rewrite-clj v0 and/or rewrite-cljs
6666
* https://github.com/clojure-emacs/refactor-nrepl[refactor-nrepl] ^t^
6767
* https://github.com/mauricioszabo/repl-tooling[repl-tooling]
6868
* https://github.com/atomist-skills/update-leiningen-dependencies-skill[update-leiningen-dependencies-skill]
69-
* https://github.com/kkinnear/zprint[zprint] ^t^
69+
* https://github.com/kkinnear/zprint[zprint] ^t^ ^h^
7070

7171
Have an update? Let us know!
7272

73-
^t^ [.small]#included in rewrite-clj v1 link:doc/02-developer-guide.adoc#libs-test[lib test suite]#
73+
^t^ [.small]#included in rewrite-clj v1 link:doc/02-developer-guide.adoc#libs-test[lib test suite]# +
74+
^h^ [.small]#required minor change to work with rewrite-clj v1#
7475

7576
== Versioning
7677

doc/02-developer-guide.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ Current libs we test against:
215215
* antq
216216
* carve
217217
* cljfmt
218+
* cljstyle
218219
* clojure-lsp
219220
* mranderson
220221
* rewrite-edn

script/libs_tests.clj

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@
160160
:additions {'rewrite-clj/rewrite-clj {:mvn/version rewrite-clj-version}}})
161161
(patch-rewrite-cljc-sources home-dir))
162162

163+
(defn- replace-in-file [fname match replacement]
164+
(let [orig-filename (str fname ".orig")
165+
content (slurp fname)]
166+
(fs/copy fname orig-filename)
167+
(status/line :detail (format "- hacking %s" fname))
168+
(let [new-content (string/replace content match replacement)]
169+
(if (= new-content content)
170+
(throw (ex-info (format "hacking file failed: %s" fname) {}))
171+
(spit fname new-content)))
172+
(status/line :detail (format "-> here's the diff for %s" fname))
173+
(shcmd-no-exit ["git" "--no-pager" "diff" "--no-index" orig-filename fname])))
174+
163175
;;
164176
;; antq
165177
;;
@@ -197,6 +209,27 @@
197209
:additions {'rewrite-clj/rewrite-clj {:mvn/version rewrite-clj-version}
198210
'cljfmt/cljfmt {:mvn/version "0.7.0" :exclusions ['rewrite-cljs/rewrite-cljs
199211
'rewrite-clj/rewrite-clj]}}}))
212+
213+
;;
214+
;; cljstyle
215+
;;
216+
217+
(defn- cljstyle-patch [{:keys [home-dir rewrite-clj-version]}]
218+
(patch-deps {:filename (str (fs/file home-dir "project.clj"))
219+
:removals #{'rewrite-clj}
220+
:additions [['rewrite-clj rewrite-clj-version]]})
221+
222+
(status/line :detail "=> cljstyle needs to hacks to work with rewrite-clj v1")
223+
(status/line :detail "=> hack 1 of 2: update ref to internal use of StringNode")
224+
(replace-in-file (str (fs/file home-dir "src/cljstyle/format/zloc.clj"))
225+
"rewrite_clj.node.string.StringNode"
226+
"rewrite_clj.node.stringz.StringNode")
227+
228+
(status/line :detail "=> hack 2 of 2: update test expectation of exception type")
229+
(replace-in-file (str (fs/file home-dir "test/cljstyle/task_test.clj"))
230+
"java.lang.Exception: Unexpected"
231+
"clojure.lang.ExceptionInfo: Unexpected"))
232+
200233
;;
201234
;; mranderson
202235
;;
@@ -303,6 +336,16 @@
303336
:patch-fn cljfmt-patch
304337
:show-deps-fn lein-deps-tree
305338
:test-cmds [["lein" "test"]]}
339+
{:name "cljstyle"
340+
:version "0.14.0"
341+
:platforms [:clj]
342+
:note "2 minor hacks to pass with rewrite-clj v1"
343+
:github-release {:repo "greglook/cljstyle"
344+
:via :tag}
345+
:patch-fn cljstyle-patch
346+
:show-deps-fn lein-deps-tree
347+
:test-cmds [["lein" "check"]
348+
["lein" "test"]]}
306349
{:name "clojure-lsp"
307350
:platforms [:clj]
308351
:version "2021.03.06-17.05.35"
@@ -350,7 +393,7 @@
350393
{:name "zprint"
351394
:version "1.1.1"
352395
:platforms [:clj :cljs]
353-
:note "zprint src hacked to pass with rewrite-clj v1"
396+
:note "1 minor hack to pass with rewrite-clj v1"
354397
:github-release {:repo "kkinnear/zprint"}
355398
:patch-fn zprint-patch
356399
:prep-fn zprint-prep
@@ -375,6 +418,9 @@
375418
(fetch-lib-release lib))
376419
home-dir (str (fs/file home-dir (or root "")))
377420
lib (assoc lib :home-dir home-dir)]
421+
(status/line :detail "git init-ing target, some libs expect that they were cloned")
422+
(shcmd ["git" "init"] {:dir home-dir})
423+
378424
(when patch-fn
379425
(status/line :info (format "%s: Patching" name))
380426
(patch-fn lib))
@@ -402,8 +448,7 @@
402448
(status/line :detail (format "(re)creating: %s" target-root-dir))
403449
(when (fs/exists? target-root-dir) (fs/delete-tree target-root-dir))
404450
(.mkdirs (fs/file target-root-dir))
405-
(status/line :detail "git init-ing target to avoid polluting our project git config/hooks with any changes libs under test might effect")
406-
(shcmd ["git" "init"] {:dir target-root-dir}))
451+
)
407452

408453
;;
409454
;; cmds

0 commit comments

Comments
 (0)