Skip to content

Commit b7ef095

Browse files
authored
docs: review inline options (#24)
Highlights: - Move `:apply` after all other opts, as it applies to all other opts. - Describe long and short forms of `:skip`
1 parent b41bcbf commit b7ef095

14 files changed

+208
-76
lines changed

doc/example.adoc

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,31 +102,35 @@ It is sometimes just nice to know that your code snippet will run without except
102102
== Inline Options
103103
You can, to some limited extent, communicate your intent to test-doc-blocks.
104104

105-
Test-doc-blocks will look for AsciiDoc comments that begin with `:test-doc-blocks`.
105+
Test-doc-blocks will look for AsciiDoc `:test-doc-blocks` comment lines.
106106

107107
It currently understands the following options:
108108

109-
* `:test-doc-blocks/apply` - controls to what code blocks options are applied
110109
* `:test-doc-blocks/skip` - skips the next code block
111110
* `:test-doc-blocks/reader-cond` - wraps your code block in a reader conditional
112111
* `:test-doc-blocks/test-ns` - specifies the output test namespace
113112
* `:test-doc-blocks/platform` - specifies Clojure file type to generate for test ns
114113
* `:test-doc-blocks/meta` - attach metadata to generated tests
114+
* `:test-doc-blocks/apply` - controls to what code blocks options are applied
115115

116-
=== Applying Options - :apply
117-
118-
By default, test-doc-blocks will create tests for all Clojure code blocks it finds in the files you specified.
116+
=== Skipping Code Blocks - :skip
119117

120-
You can change this by including the `:test-doc-blocks/apply` option:
118+
By default, test-doc-blocks will create tests for all Clojure code blocks it finds.
121119

122-
* `:next` - default - applies new options to next Clojure code block only
123-
* `:all-next` - applies new options to all subsequent code blocks in the document until specifically overridden with new opts
120+
Tell test-doc-blocks to skip the next Clojure code block via `//#:test-doc-blocks {:skip true}`:
124121

125-
=== Skipping Code Blocks - :skip
122+
[source,asciidoc]
123+
....
124+
//#:test-doc-blocks {:skip true}
125+
[source,clojure]
126+
----
127+
;; no tests will be generated for this code Clojure code block
126128
127-
By default, test-doc-blocks will create tests for all Clojure code blocks it finds.
129+
(something we don't want to test...
130+
----
131+
....
128132

129-
Tell test-doc-blocks to skip the next Clojure code block via the following AsciiDoc comment:
133+
Because `:skip` is a boolean, you can use the shorter `//:test-doc-blocks/skip`:
130134

131135
[source,asciidoc]
132136
....
@@ -135,7 +139,7 @@ Tell test-doc-blocks to skip the next Clojure code block via the following Ascii
135139
----
136140
;; no tests will be generated for this code Clojure code block
137141
138-
(something we don't want to test)
142+
(something we don't want to test...
139143
----
140144
....
141145

@@ -188,7 +192,8 @@ Test-doc-blocks does no special checking, but `:reader-cond` only makes sense fo
188192
=== Specifying Test Namespace - :test-ns
189193

190194
By default, test-doc-blocks will generate tests to namespaces based on document filenames.
191-
This file is named `example.adoc`. Test-doc-blocks, up to this point, has been generating tests to the `example-adoc-test` namespace.
195+
This file you are reading now is named `example.adoc`.
196+
Test-doc-blocks, up to this point, has been generating tests to the `example-adoc-test` namespace.
192197

193198
If this does not work for you, you can override this default via an AsciiDoc comment:
194199

@@ -238,7 +243,7 @@ When specifying the platform, remember that:
238243
* For Clojure `my-ns-file.clj` will be picked over `my-ns-file.cljc`
239244
* For ClojureScript `my-ns-file.cljs` will be picked over `my-ns-file.cljc`
240245

241-
So if you are generating mixed platforms, you might want to specify the test-ns as well.
246+
So if you are generating mixed platforms, you might want to specify the test-ns as well:
242247

243248
[source,asciidoc]
244249
....
@@ -301,6 +306,62 @@ user=> (into [] {:a 1})
301306
----
302307
....
303308

309+
=== Applying Options - :apply
310+
311+
Use the `:test-doc-blocks/apply` option to control which code blocks your specified option(s) apply to:
312+
313+
* `:next` - default - applies new options to next Clojure code block only
314+
* `:all-next` - applies new options to all subsequent code blocks in the document until specifically overridden with new opts
315+
316+
For example, maybe you want test-doc-blocks to skip code blocks by default:
317+
318+
[source,asciidoc]
319+
....
320+
//#:test-doc-blocks{:skip true :apply :all-next}
321+
....
322+
323+
All subsequent code blocks would be skipped.
324+
325+
[source,asciidoc]
326+
....
327+
[source,clojure]
328+
----
329+
;; I am a code block that is skipped by test-doc-blocks
330+
(maybe some code that won't compile ...
331+
----
332+
....
333+
334+
Then you could choose to not skip a code block like so:
335+
[source,asciidoc]
336+
....
337+
//#:test-doc-blocks{:skip false}
338+
[source,clojure]
339+
----
340+
;; A test will be generated for this code block
341+
(apply str (interpose " " ["don't" "skip" "me!"]))
342+
;; => "don't skip me!"
343+
----
344+
....
345+
346+
To have test-doc-blocks stop skipping code blocks by default:
347+
348+
[source,asciidoc]
349+
....
350+
//#:test-doc-blocks{:skip false :apply :all-next}
351+
....
352+
353+
And now test-doc-blocks will generate tests for subsequent code blocks.
354+
355+
[source,asciidoc]
356+
....
357+
[source,clojure]
358+
----
359+
;; A test will be generated for this code block
360+
(apply str (interpose " " ["test" "me" "by" "default"]))
361+
;; => "test me by default"
362+
----
363+
....
364+
304365
// Notice the use of CommonMark syntax for section title here, we test that we recognize this syntax
305366
## Section Titles
306367
Test-doc-blocks will try to give each test block some context by including its filename, section title and starting line number.
@@ -324,7 +385,7 @@ And this level 2 type
324385
---------------------
325386
----
326387
327-
This code block should include "Section Titles" as part of the context for its generated test.
388+
This code block should include "Section Titles" (the actual title of this section) as part of the context for its generated test.
328389
329390
[source,markdown]
330391
....

doc/example.md

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,38 +91,40 @@ It is sometimes just nice to know that your code snippet will run without except
9191
## Inline Options
9292
You can, to some limited extent, communicate your intent to test-doc-blocks.
9393

94-
Test-doc-blocks will look for CommonMark comments that begin with `:test-doc-blocks`.
94+
Test-doc-blocks will look for CommonMark `:test-doc-blocks` comment lines.
9595

9696
It currently understands the following options:
9797

98-
- `:test-doc-blocks/apply` - controls to what code blocks options are applied
9998
- `:test-doc-blocks/skip` - skips the next code block
10099
- `:test-doc-blocks/reader-cond` - wraps your code block in a reader conditional
101100
- `:test-doc-blocks/test-ns` - specifies the output test namespace
102101
- `:test-doc-blocks/platform` - specifies Clojure file type to generate for test ns
103102
- `:test-doc-blocks/meta` - attach metadata to generated tests
103+
- `:test-doc-blocks/apply` - controls to what code blocks options are applied
104104

105-
### Applying Options - :apply
106-
107-
By default, new options are applied to the next Clojure code block only.
105+
### Skipping Code Blocks - :skip
108106

109-
You can change this by including the `:test-doc-blocks/apply` option:
107+
By default, test-doc-blocks will create tests for all Clojure code blocks it finds in the files you specified.
110108

111-
- `:next` - default - applies new options to next Clojure code block only
112-
- `:all-next` - applies new options to all subsequent code blocks in the document until specifically overridden with new opts
109+
Tell test-doc-blocks to skip the next Clojure code block via `<!-- #:test-doc-blocks {:skip true} -->`:
113110

114-
### Skipping Code Blocks - :skip
111+
~~~markdown
112+
<!-- #:test-doc-blocks {:skip true} -->
113+
```Clojure
114+
;; no tests will be generated for this Clojure code block
115115

116-
By default, test-doc-blocks will create tests for all Clojure code blocks it finds in the files you specified.
116+
(something we don't want to test ...
117+
```
118+
~~~
117119

118-
Tell test-doc-blocks to skip the next Clojure code block via the following CommonMark comment:
120+
Because `:skip` is a boolean, you can use the shorter `<!-- :test-doc-blocks/skip -->`:
119121

120122
~~~markdown
121123
<!-- :test-doc-blocks/skip -->
122124
```Clojure
123125
;; no tests will be generated for this Clojure code block
124126

125-
(something we don't want to test)
127+
(something we don't want to test ...
126128
```
127129
~~~
128130

@@ -169,7 +171,7 @@ Test-doc-blocks does no special checking, but `:reader-cond` only makes sense fo
169171
### Specifying Test Namespace - :test-ns
170172

171173
By default, test-doc-blocks will generate tests to namespaces based on document filenames.
172-
This file is named `example.md`. Test-doc-blocks, up to this point has been generating tests to the `example-md-test` namespace.
174+
This file your are reading now is named `example.md`. Test-doc-blocks, up to this point has been generating tests to the `example-md-test` namespace.
173175

174176
If this does not work for you, you can override this default via a CommonMark comment:
175177

@@ -217,7 +219,7 @@ When specifying the platform, remember that:
217219
- For Clojure `my-ns-file.clj` will be picked over `my-ns-file.cljc`
218220
- For ClojureScript `my-ns-file.cljs` will be picked over `my-ns-file.cljc`
219221

220-
So if you are generating mixed platforms, you might want to specify the test-ns as well.
222+
So if you are generating mixed platforms, you might want to specify the test-ns as well:
221223

222224
~~~markdown
223225
<!-- #:test-doc-blocks{:platform :cljs :test-ns example-md-cljs-test} -->
@@ -274,11 +276,60 @@ user=> (into [] {:a 1})
274276
```
275277
~~~
276278

279+
### Applying Options - :apply
280+
281+
Use the `:test-doc-blocks/apply` option to control which code blocks your specified option(s) apply to:
282+
283+
- `:next` - default - applies new options to next Clojure code block only
284+
- `:all-next` - applies new options to all subsequent code blocks in the document until specifically overridden with new opts
285+
286+
For example, maybe you want test-doc-blocks to skip code blocks by default:
287+
288+
~~~markdown
289+
<!-- #:test-doc-blocks{:skip true :apply :all-next} -->
290+
~~~
291+
292+
All subsequent code blocks would be skipped.
293+
294+
~~~markdown
295+
```clojure
296+
;; I am a code block that is skipped by test-doc-blocks
297+
(maybe some code that won't compile ...
298+
```
299+
~~~
300+
301+
Then you could choose to not skip a code block like so:
302+
303+
~~~markdown
304+
<!-- #:test-doc-blocks{:skip false} -->
305+
```clojure
306+
;; A test will be generated for this code block
307+
(apply str (interpose " " ["don't" "skip" "me!"]))
308+
;; => "don't skip me!"
309+
```
310+
~~~
311+
312+
To have test-doc-blocks stop skipping code blocks by default:
313+
314+
~~~markdown
315+
<!-- #:test-doc-blocks{:skip false :apply :all-next} -->
316+
~~~
317+
318+
And now test-doc-blocks will generate tests for subsequent code blocks.
319+
320+
~~~markdown
321+
```clojure
322+
;; A test will be generated for this code block
323+
(apply str (interpose " " ["test" "me" "by" "default"]))
324+
;; => "test me by default"
325+
```
326+
~~~
327+
277328
# Section Titles
278329

279330
Test-doc-blocks will try to give each test block some context by including its filename, section title and starting line number.
280331

281-
This code block should include "Section Titles" as part of the context for its generated test.
332+
This code block should include "Section Titles" (the actual title of this section) as part of the context for its generated test.
282333

283334
~~~markdown
284335
```Clojure

test-resources/expected/test-doc-blocks/test/example_adoc_cljs_test.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(:import goog.events.EventType))
77

88
(clojure.test/deftest block-0001
9-
(clojure.test/testing "doc/example.adoc - line 247 - Specifying The Platform - :platform"
9+
(clojure.test/testing "doc/example.adoc - line 252 - Specifying The Platform - :platform"
1010
;; this code block will generate a test under example-adoc-cljs-test ns to a .cljs file
1111

1212
nil

test-resources/expected/test-doc-blocks/test/example_adoc_inline_ns_test.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(:import #?@(:clj [java.util.List java.util.Queue java.util.Set] :cljs [goog.math.Long goog.math.Vec2 goog.math.Vec3])))
1111

1212
(clojure.test/deftest block-0001
13-
(clojure.test/testing "doc/example.adoc - line 411 - Inline requires and imports"
13+
(clojure.test/testing "doc/example.adoc - line 472 - Inline requires and imports"
1414
;; Stick the basics for requires, shorthand notation isn't supported
1515

1616
;; Some examples:

test-resources/expected/test-doc-blocks/test/example_adoc_inline_refer_clojure_test.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[clojure.edn :refer [read-string]]))
88

99
(clojure.test/deftest block-0001
10-
(clojure.test/testing "doc/example.adoc - line 442 - Inline refer-clojure"
10+
(clojure.test/testing "doc/example.adoc - line 503 - Inline refer-clojure"
1111
;; a contrived example that uses uses clojure.edn/read-string in place
1212
;; of clojure.core/read-string and excludes clojure.core/for
1313
nil

test-resources/expected/test-doc-blocks/test/example_adoc_new_ns/ns1_test.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[clojure.string :as string]))
77

88
(clojure.test/deftest block-0001
9-
(clojure.test/testing "doc/example.adoc - line 215 - Specifying Test Namespace - :test-ns"
9+
(clojure.test/testing "doc/example.adoc - line 220 - Specifying Test Namespace - :test-ns"
1010
;; this code block will generate tests under example-adoc-new-ns.ns1-test
1111

1212
nil

test-resources/expected/test-doc-blocks/test/example_adoc_new_ns_test.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#?(:clj lread.test-doc-blocks.runtime)))
66

77
(clojure.test/deftest block-0001
8-
(clojure.test/testing "doc/example.adoc - line 199 - Specifying Test Namespace - :test-ns"
8+
(clojure.test/testing "doc/example.adoc - line 204 - Specifying Test Namespace - :test-ns"
99
;; this code block will generate tests under example-adoc-new-ns-test
1010

1111
(clojure.test/is (= '8 (* 2 4)))))

0 commit comments

Comments
 (0)