diff --git a/build.clj b/build.clj index 6b172b6..f59599b 100644 --- a/build.clj +++ b/build.clj @@ -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. diff --git a/build/honey/gen_doc_tests.clj b/build/honey/gen_doc_tests.clj new file mode 100644 index 0000000..7aed688 --- /dev/null +++ b/build/honey/gen_doc_tests.clj @@ -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")))) diff --git a/deps.edn b/deps.edn index f9678ab..e76ee32 100644 --- a/deps.edn +++ b/deps.edn @@ -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"]}