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:
lread 2021-08-30 21:08:28 -04:00
parent 458cc9fa52
commit ae29147a22
3 changed files with 42 additions and 34 deletions

View file

@ -10,10 +10,8 @@
clojure -A:deps -T:build help/doc"
(:require [babashka.fs :as fs]
[clojure.tools.build.api :as b]
[org.corfield.build :as bb]
[lread.test-doc-blocks :as tdb]))
(:require [clojure.tools.build.api :as b]
[org.corfield.build :as bb]))
(def lib 'com.github.seancorfield/honeysql)
(def version (format "2.0.%s" (b/git-count-revs nil)))
@ -21,33 +19,8 @@
(defn eastwood "Run Eastwood." [opts]
(-> opts (bb/run-task [:eastwood])))
(defn gen-doc-tests "Generate tests from doc code blocks" [opts]
(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 "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 gen-doc-tests "Generate tests from doc code blocks." [opts]
(-> opts (bb/run-task [:gen-doc-tests])))
(defn run-doc-tests
"Generate and run doc tests.

View 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"))))

View file

@ -3,9 +3,8 @@
:deps {org.clojure/clojure {:mvn/version "1.9.0"}}
:aliases
{;; for help: clojure -A:deps -T:build help/doc
:build {:deps {babashka/fs {:mvn/version "0.0.5"}
com.github.lread/test-doc-blocks {:mvn/version "1.0.146-alpha"}
io.github.seancorfield/build-clj {:git/tag "v0.1.0" :git/sha "fe2d586"}}
:build {:deps {io.github.seancorfield/build-clj
{:git/tag "v0.1.0" :git/sha "fe2d586"}}
:ns-default build}
;; versions to test against:
@ -24,6 +23,11 @@
:cljs {:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}}
: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-clj {:main-opts ["-m" "cognitect.test-runner"
"-d" "target/test-doc-blocks/test"]}