Skip to content

Commit

Permalink
Add cljstyle to libs tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lread committed Mar 16, 2021
1 parent 61253ea commit 5ea1928
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Some projects using rewrite-clj v0 and/or rewrite-cljs

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

Have an update? Let us know!

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

== Versioning

Expand Down
1 change: 1 addition & 0 deletions doc/02-developer-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ Current libs we test against:
* antq
* carve
* cljfmt
* cljstyle
* clojure-lsp
* mranderson
* rewrite-edn
Expand Down
51 changes: 48 additions & 3 deletions script/libs_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@
:additions {'rewrite-clj/rewrite-clj {:mvn/version rewrite-clj-version}}})
(patch-rewrite-cljc-sources home-dir))

(defn- replace-in-file [fname match replacement]
(let [orig-filename (str fname ".orig")
content (slurp fname)]
(fs/copy fname orig-filename)
(status/line :detail (format "- hacking %s" fname))
(let [new-content (string/replace content match replacement)]
(if (= new-content content)
(throw (ex-info (format "hacking file failed: %s" fname) {}))
(spit fname new-content)))
(status/line :detail (format "-> here's the diff for %s" fname))
(shcmd-no-exit ["git" "--no-pager" "diff" "--no-index" orig-filename fname])))

;;
;; antq
;;
Expand Down Expand Up @@ -197,6 +209,27 @@
:additions {'rewrite-clj/rewrite-clj {:mvn/version rewrite-clj-version}
'cljfmt/cljfmt {:mvn/version "0.7.0" :exclusions ['rewrite-cljs/rewrite-cljs
'rewrite-clj/rewrite-clj]}}}))

;;
;; cljstyle
;;

(defn- cljstyle-patch [{:keys [home-dir rewrite-clj-version]}]
(patch-deps {:filename (str (fs/file home-dir "project.clj"))
:removals #{'rewrite-clj}
:additions [['rewrite-clj rewrite-clj-version]]})

(status/line :detail "=> cljstyle needs to hacks to work with rewrite-clj v1")
(status/line :detail "=> hack 1 of 2: update ref to internal use of StringNode")
(replace-in-file (str (fs/file home-dir "src/cljstyle/format/zloc.clj"))
"rewrite_clj.node.string.StringNode"
"rewrite_clj.node.stringz.StringNode")

(status/line :detail "=> hack 2 of 2: update test expectation of exception type")
(replace-in-file (str (fs/file home-dir "test/cljstyle/task_test.clj"))
"java.lang.Exception: Unexpected"
"clojure.lang.ExceptionInfo: Unexpected"))

;;
;; mranderson
;;
Expand Down Expand Up @@ -303,6 +336,16 @@
:patch-fn cljfmt-patch
:show-deps-fn lein-deps-tree
:test-cmds [["lein" "test"]]}
{:name "cljstyle"
:version "0.14.0"
:platforms [:clj]
:note "2 minor hacks to pass with rewrite-clj v1"
:github-release {:repo "greglook/cljstyle"
:via :tag}
:patch-fn cljstyle-patch
:show-deps-fn lein-deps-tree
:test-cmds [["lein" "check"]
["lein" "test"]]}
{:name "clojure-lsp"
:platforms [:clj]
:version "2021.03.06-17.05.35"
Expand Down Expand Up @@ -350,7 +393,7 @@
{:name "zprint"
:version "1.1.1"
:platforms [:clj :cljs]
:note "zprint src hacked to pass with rewrite-clj v1"
:note "1 minor hack to pass with rewrite-clj v1"
:github-release {:repo "kkinnear/zprint"}
:patch-fn zprint-patch
:prep-fn zprint-prep
Expand All @@ -375,6 +418,9 @@
(fetch-lib-release lib))
home-dir (str (fs/file home-dir (or root "")))
lib (assoc lib :home-dir home-dir)]
(status/line :detail "git init-ing target, some libs expect that they were cloned")
(shcmd ["git" "init"] {:dir home-dir})

(when patch-fn
(status/line :info (format "%s: Patching" name))
(patch-fn lib))
Expand Down Expand Up @@ -402,8 +448,7 @@
(status/line :detail (format "(re)creating: %s" target-root-dir))
(when (fs/exists? target-root-dir) (fs/delete-tree target-root-dir))
(.mkdirs (fs/file target-root-dir))
(status/line :detail "git init-ing target to avoid polluting our project git config/hooks with any changes libs under test might effect")
(shcmd ["git" "init"] {:dir target-root-dir}))
)

;;
;; cmds
Expand Down

0 comments on commit 5ea1928

Please sign in to comment.