PR review feedback: move gen-doc-tests build code
Move the code that generates doc tests out from build.clj to its own source runnable via main. This isolates gen-doc-tests work to its own process during the build. I arbitrarily: - chose 'build' as the folder for build helper sources - namespaced our first build helper under 'honey.gen-doc-tests'
This commit is contained in:
parent
458cc9fa52
commit
ae29147a22
3 changed files with 42 additions and 34 deletions
35
build.clj
35
build.clj
|
|
@ -10,10 +10,8 @@
|
||||||
|
|
||||||
clojure -A:deps -T:build help/doc"
|
clojure -A:deps -T:build help/doc"
|
||||||
|
|
||||||
(:require [babashka.fs :as fs]
|
(:require [clojure.tools.build.api :as b]
|
||||||
[clojure.tools.build.api :as b]
|
[org.corfield.build :as bb]))
|
||||||
[org.corfield.build :as bb]
|
|
||||||
[lread.test-doc-blocks :as tdb]))
|
|
||||||
|
|
||||||
(def lib 'com.github.seancorfield/honeysql)
|
(def lib 'com.github.seancorfield/honeysql)
|
||||||
(def version (format "2.0.%s" (b/git-count-revs nil)))
|
(def version (format "2.0.%s" (b/git-count-revs nil)))
|
||||||
|
|
@ -21,33 +19,8 @@
|
||||||
(defn eastwood "Run Eastwood." [opts]
|
(defn eastwood "Run Eastwood." [opts]
|
||||||
(-> opts (bb/run-task [:eastwood])))
|
(-> opts (bb/run-task [:eastwood])))
|
||||||
|
|
||||||
(defn gen-doc-tests "Generate tests from doc code blocks" [opts]
|
(defn gen-doc-tests "Generate tests from doc code blocks." [opts]
|
||||||
(let [target "target/test-doc-blocks"
|
(-> opts (bb/run-task [:gen-doc-tests])))
|
||||||
success-marker (fs/file target "SUCCESS")
|
|
||||||
docs ["README.md"
|
|
||||||
"doc/clause-reference.md"
|
|
||||||
"doc/differences-from-1-x.md"
|
|
||||||
"doc/extending-honeysql.md"
|
|
||||||
"doc/general-reference.md"
|
|
||||||
"doc/getting-started.md"
|
|
||||||
"doc/postgresql.md"
|
|
||||||
"doc/special-syntax.md"]
|
|
||||||
regen-reason (if (not (fs/exists? success-marker))
|
|
||||||
"a previous successful gen result not found"
|
|
||||||
(let [newer-thans (fs/modified-since target
|
|
||||||
(concat docs
|
|
||||||
["build.clj" "deps.edn"]
|
|
||||||
(fs/glob "src" "**/*.*")))]
|
|
||||||
(when (seq newer-thans)
|
|
||||||
(str "found files newer than last gen: " (mapv str newer-thans)))))]
|
|
||||||
(if regen-reason
|
|
||||||
(do
|
|
||||||
(fs/delete-if-exists success-marker)
|
|
||||||
(println "gen-doc-tests: Regenerating:" regen-reason)
|
|
||||||
(tdb/gen-tests {:docs docs})
|
|
||||||
(spit success-marker "SUCCESS"))
|
|
||||||
(println "gen-doc-tests: Tests already successfully generated")))
|
|
||||||
opts)
|
|
||||||
|
|
||||||
(defn run-doc-tests
|
(defn run-doc-tests
|
||||||
"Generate and run doc tests.
|
"Generate and run doc tests.
|
||||||
|
|
|
||||||
31
build/honey/gen_doc_tests.clj
Normal file
31
build/honey/gen_doc_tests.clj
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
(ns honey.gen-doc-tests
|
||||||
|
(:require [babashka.fs :as fs]
|
||||||
|
[lread.test-doc-blocks :as tdb]))
|
||||||
|
|
||||||
|
(defn -main [& _args]
|
||||||
|
(let [target "target/test-doc-blocks"
|
||||||
|
success-marker (fs/file target "SUCCESS")
|
||||||
|
docs ["README.md"
|
||||||
|
"doc/clause-reference.md"
|
||||||
|
"doc/differences-from-1-x.md"
|
||||||
|
"doc/extending-honeysql.md"
|
||||||
|
"doc/general-reference.md"
|
||||||
|
"doc/getting-started.md"
|
||||||
|
"doc/postgresql.md"
|
||||||
|
"doc/special-syntax.md"]
|
||||||
|
regen-reason (if (not (fs/exists? success-marker))
|
||||||
|
"a previous successful gen result not found"
|
||||||
|
(let [newer-thans (fs/modified-since target
|
||||||
|
(concat docs
|
||||||
|
["build.clj" "deps.edn"]
|
||||||
|
(fs/glob "build" "**/*.*")
|
||||||
|
(fs/glob "src" "**/*.*")))]
|
||||||
|
(when (seq newer-thans)
|
||||||
|
(str "found files newer than last gen: " (mapv str newer-thans)))))]
|
||||||
|
(if regen-reason
|
||||||
|
(do
|
||||||
|
(fs/delete-if-exists success-marker)
|
||||||
|
(println "gen-doc-tests: Regenerating:" regen-reason)
|
||||||
|
(tdb/gen-tests {:docs docs})
|
||||||
|
(spit success-marker "SUCCESS"))
|
||||||
|
(println "gen-doc-tests: Tests already successfully generated"))))
|
||||||
10
deps.edn
10
deps.edn
|
|
@ -3,9 +3,8 @@
|
||||||
:deps {org.clojure/clojure {:mvn/version "1.9.0"}}
|
:deps {org.clojure/clojure {:mvn/version "1.9.0"}}
|
||||||
:aliases
|
:aliases
|
||||||
{;; for help: clojure -A:deps -T:build help/doc
|
{;; for help: clojure -A:deps -T:build help/doc
|
||||||
:build {:deps {babashka/fs {:mvn/version "0.0.5"}
|
:build {:deps {io.github.seancorfield/build-clj
|
||||||
com.github.lread/test-doc-blocks {:mvn/version "1.0.146-alpha"}
|
{:git/tag "v0.1.0" :git/sha "fe2d586"}}
|
||||||
io.github.seancorfield/build-clj {:git/tag "v0.1.0" :git/sha "fe2d586"}}
|
|
||||||
:ns-default build}
|
:ns-default build}
|
||||||
|
|
||||||
;; versions to test against:
|
;; versions to test against:
|
||||||
|
|
@ -24,6 +23,11 @@
|
||||||
:cljs {:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}}
|
:cljs {:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}}
|
||||||
:main-opts ["-m" "cljs-test-runner.main"]}
|
:main-opts ["-m" "cljs-test-runner.main"]}
|
||||||
|
|
||||||
|
:gen-doc-tests {:replace-paths ["build"]
|
||||||
|
:extra-deps {babashka/fs {:mvn/version "0.0.5"}
|
||||||
|
com.github.lread/test-doc-blocks {:mvn/version "1.0.146-alpha"}}
|
||||||
|
:main-opts ["-m" "honey.gen-doc-tests"]}
|
||||||
|
|
||||||
:test-doc {:replace-paths ["src" "target/test-doc-blocks/test"]}
|
:test-doc {:replace-paths ["src" "target/test-doc-blocks/test"]}
|
||||||
:test-doc-clj {:main-opts ["-m" "cognitect.test-runner"
|
:test-doc-clj {:main-opts ["-m" "cognitect.test-runner"
|
||||||
"-d" "target/test-doc-blocks/test"]}
|
"-d" "target/test-doc-blocks/test"]}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue