Skip to content

Commit

Permalink
Tests can now be generated from a header-less doc (#26)
Browse files Browse the repository at this point in the history
Fixed the summary report not accounting for the fact a doc might have no
headers (aka section titles) in it.

While this is an unlikely scenario for real docs, it is a likely one for
someone wanting to give test-doc-blocks a whirl with a very minimal doc.

Closes #25
  • Loading branch information
lread authored May 5, 2024
1 parent 57ac054 commit bca7536
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ A release with known breaking changes is marked with:

== Unreleased

* Tests can now be generated from a header-less doc
https://github.com/lread/test-doc-blocks/issues/25[#25]
(thanks for the feedback https://github.com/genmeblog[@genmeblog]!)

== v1.1.19 - 2024-05-02 [[v1.1.19]]

* Drop `alpha` status, we don't have many users, but folks have been using this lib for years
Expand Down
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Test-doc-block versioning scheme is: `major`.`minor`.`release`-`test-qualifier`
image:seancorfield.png[seancorfield,width=273,link="https://github.com/seancorfield"]
image:MIJOTHY.png[MIJOTHY,width=273,link="https://github.com/MIJOTHY"]
image:borkdude.png[borkdude,width=273,link="https://github.com/borkdude"]
image:genmeblog.png[genmeblog,width=273,link="https://github.com/genmeblog"]
image:holyjak.png[holyjak,width=273,link="https://github.com/holyjak"]
image:PEZ.png[PEZ,width=273,link="https://github.com/PEZ"]
image:SevereOverfl0w.png[SevereOverfl0w,width=273,link="https://github.com/SevereOverfl0w"]
Expand Down
3 changes: 2 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
;; but on Windows it can be very time consuming to learn how to escape them
;; sooo... I'm putting :docs here
:test-opts {:exec-args {:docs ["doc/01-user-guide.adoc"
"doc/example.{adoc,md,cljc}"]}}
"doc/example.{adoc,md,cljc}"
"test-resources/doc/*.{adoc,md}"]}}

;; and :target, even passing a "\"string\"" is hard on windows
:regen-opts {:exec-args {:target-root "test-resources/expected"}}
Expand Down
3 changes: 2 additions & 1 deletion doc/contributors.edn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
{:github-id "seancorfield" :contributions [:inspiration :feedback :testing]}
{:github-id "uochan" :contributions [:feedback]}
{:github-id "holyjak" :contributions [:docs]}
{:github-id "MIJOTHY" :contributions [:feedback :docs]}]
{:github-id "MIJOTHY" :contributions [:feedback :docs]}
{:github-id "genmeblog" :contributions [:feedback]}]
:maintainers
[{:github-id "lread"
:contributions [:code]}]}
Binary file added doc/generated/contributors/genmeblog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/lread/test_doc_blocks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
(doseq [[fname headers] fnames]
(println (indent fname indent-cnt))
(doseq [[header lines] (->> headers (group-by :header) (into []) (sort-by #(-> % second first :line-no)))]
(println (indent header (+ 2 indent-cnt)))
(when header
(println (indent header (+ 2 indent-cnt))))
(doseq [line lines]
(println (-> (format "%03d: %s" (:line-no line) (:test-doc-blocks/test-ns line))
(indent (+ 4 indent-cnt)))))))))
Expand Down
5 changes: 5 additions & 0 deletions test-resources/doc/minimal.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[source,clojure]
----
(+ 1 2)
;; => 3
----
4 changes: 4 additions & 0 deletions test-resources/doc/minimal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```clojure
(+ 1 2)
;; => 3
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns minimal-adoc-test
(:require clojure.test
clojure.string
#?(:cljs [lread.test-doc-blocks.runtime :include-macros])
#?(:clj lread.test-doc-blocks.runtime)))

(clojure.test/deftest block-0001
(clojure.test/testing "test-resources/doc/minimal.adoc - line 2"
(clojure.test/is (= '3 (+ 1 2)))))

(defn test-ns-hook [] (block-0001))
11 changes: 11 additions & 0 deletions test-resources/expected/test-doc-blocks/test/minimal_md_test.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns minimal-md-test
(:require clojure.test
clojure.string
#?(:cljs [lread.test-doc-blocks.runtime :include-macros])
#?(:clj lread.test-doc-blocks.runtime)))

(clojure.test/deftest block-0001
(clojure.test/testing "test-resources/doc/minimal.md - line 1"
(clojure.test/is (= '3 (+ 1 2)))))

(defn test-ns-hook [] (block-0001))
4 changes: 3 additions & 1 deletion test/lread/test_doc_blocks_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
(deftest verify-generation-against-known-good-run

(sut/gen-tests {:docs ["doc/01-user-guide.adoc"
"doc/example.{adoc,md,cljc}"]
"doc/example.{adoc,md,cljc}"
"test-resources/doc/minimal.adoc"
"test-resources/doc/minimal.md"]
:target-root "target/actual"})

(let [expected-dir "test-resources/expected/test-doc-blocks/test/"
Expand Down

0 comments on commit bca7536

Please sign in to comment.