@@ -5,19 +5,21 @@ and each markdown document into a test suite.
55
66## Usage
77
8+ ### Scala CLI
9+
810Create ` test-snippets.scala ` (use at least Java 11):
911
1012``` scala
1113//> using scala 3.3.3
1214//> using jvm temurin:1.11.0.23
13- //> using dep " com.kubuszok::scala-cli-md-spec:0.0.2 "
15+ //> using dep " com.kubuszok::scala-cli-md-spec:0.0.3 "
1416import com .kubuszok .scalaclimdspec .*
1517@ main def run (args : String * ): Unit = testSnippets(args.toArray) { cfg =>
1618 new Runner .Default (cfg) // or provide your own :)
1719}
1820```
1921
20- then run it with Scala CLI:
22+ then run it with [ Scala CLI] ( https://scala-cli.virtuslab.org/ ) :
2123
2224``` bash
2325# run all tests
@@ -29,24 +31,48 @@ scala-cli run test-snippets.scala -- --test-only="my-markdown.md#Section*" "$PWD
2931To see how one can customize the code to e.g. inject variables or use the newest library version
3032in an arbitrary markdown documentation generator see [ Chimney's example] ( https://github.com/scalalandio/chimney/blob/29cd5048bee3b66c2d4d3d81dc17e0c0d5a4a128/scripts/test-snippets.scala ) .
3133
34+ ### Coursier
35+
36+ If you are not providing any modification, you can run it straight from the [ Coursier] ( https://get-coursier.io ) :
37+
38+ ``` bash
39+ # run all tests
40+ coursier launch com.kubuszok:scala-cli-md-spec_3:0.0.3 -M com.kubuszok.scalaclimdspec.testSnippets -- " $PWD /docs"
41+ # run only tests from Section in my-markdown.md
42+ coursier launch com.kubuszok:scala-cli-md-spec_3:0.0.3 -M com.kubuszok.scalaclimdspec.testSnippets -- --test-only=" my-markdown.md#Section*" " $PWD /docs"
43+ ```
44+
3245## Rules of the game
3346
3447 1 . each markdown is its own suite
3548 2 . by default only Scala snipets with ` //> using ` are considered
36- 3 . snippets are tested for lack of errors
37- 4 . unless there is ` // expected error: ` followed by inline comments with the error show in Scala CLI in the error stream
49+ * other snippets are considered pseudocode and are ignored
50+ 3 . by default snippets are tested for the lack of errors
51+ * by the lack of errors we mean that Scala CLI returns ` 0 `
52+ * if there is ` // expected output: ` followed by inline comments, snippet will be expected to succeed and
53+ standard output is expected to contain the content provided in these comments
54+ * if there is ` // expected error: ` followed by inline comments, snippet will be expected to fails and
55+ standard error is expected to contain the content provided in these comments
56+ 4 . by default each snippet is standalone Scala snippet, it will be tested in a separate directory, containing
57+ a single ` snippet.sc ` file
58+ 5 . if ` --test-only ` flag is used, only suites containing at least 1 matching snippet and within them only
59+ the matching snippets will be run and displayed (but all markdowns still need to be read to find snippets
60+ and match them against the pattern!)
61+ * multiple pieces of code can be combined into one multi-file snippet with:
62+ ` // file: filename.scala - part of X example ` syntax that would group all ` X example ` snippets, use
63+ ` filename.scala ` for this particular snippet, and place it within the same directory as others
3864
3965## Why though
4066
4167Some people would ask: if you need to make sure code in your documentation compiles, why not use something like
4268[ mdoc] ( https://scalameta.org/mdoc/ ) ?
4369
44- Well, because MDoc doesn't work for my cases:
70+ Well, because mdoc doesn't work for my cases:
4571
4672 * it requires picking a specific documentation tool whether or not its look'n'feel is what authors desires
47- * it makes it difficult to have different ` scalacOptions ` , different scala versions and different libraries available
48- in each snippet - all setting are global, so one would have to work real hard to work around these limitations
49- * since it depends on settings provided when code was build (scalacOptions, libraries) code might not be exactly
73+ * it makes it difficult to have different ` scalacOptions ` , different Scala versions and different libraries available
74+ in each snippet - all setting are global, so one would have to work real hard to around these limitations
75+ * since it depends on settings provided when the code was build (` scalacOptions ` , libraries) code might not be exactly
5076 reproducibe by the users - if they just copy-paste the code from the docs, they might find the code not working
5177 since they were not aware of some flags, libraries or compiler plugins used by authors of the example
5278
0 commit comments