Skip to content

Commit 6a23913

Browse files
Test and officially describe support for test scopes and Scala-Java snippets
1 parent 4b296c9 commit 6a23913

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ coursier launch com.kubuszok:scala-cli-md-spec_3:0.1.0 -M com.kubuszok.scalaclim
4545
## Rules of the game
4646

4747
1. each markdown is its own suite
48-
2. by default only Scala snipets with `//> using` are considered
48+
2. by default only Scala (and Java) snipets with `//> using` are considered
4949
* other snippets are considered pseudocode and are ignored
5050

5151
```scala
@@ -142,6 +142,12 @@ coursier launch com.kubuszok:scala-cli-md-spec_3:0.1.0 -M com.kubuszok.scalaclim
142142
app, there should be either exactly one `.sc` file or only `.scala` files with exactly one explicitly defined
143143
main.
144144

145+
* if at least one file in multifile snippet has a name ending with `.test.scala` then `scala-cli test [dirname]`
146+
will be used unstead (useful for e.g. defining macros in compile scope and showing them in test scope since
147+
Scala CLI is NOT multi modular)
148+
149+
* Java snippets should not only use `java` in markdown, but also define `// file: filename.java - part of ...`
150+
145151
5. if `--test-only` flag is used, only suites containing at least 1 matching snippet and, within them, only
146152
the matching snippets will be run and displayed (but all markdowns still need to be read to find snippets
147153
and match them against the pattern!)

testSnippets.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ object Snippet {
210210

211211

212212
val start = raw"(\s*)```(scala|java)(.*)".r
213-
val end = raw"\s*```\*"
213+
val end = raw"(\s*)```\s*".r
214214
val sectionName = "#+(.+)".r
215215

216216
def loop(remainingContent: List[(String, Int)], location: Location, mode: Mode, result: Vector[Snippet]): List[Snippet] =
217217
(remainingContent, mode) match {
218218
// ``` terminates snippet reading
219-
case ((end(), _) :: lines, Reading(indent, content)) =>
219+
case ((end(_), _) :: lines, Reading(indent, content)) =>
220220
loop(
221221
lines,
222222
location,
@@ -269,7 +269,9 @@ trait Runner:
269269
val snippetDir = File(s"${tmpDir.getPath()}/${snippet.dirName}")
270270
snippetDir.mkdirs()
271271
snippet.content.fileToContentMap.foreach { case (fileName, Snippet.Content.Single(content)) =>
272-
Files.writeString(File(s"${snippetDir.getPath()}/$fileName").toPath(), content)
272+
val file = File(s"${snippetDir.getPath()}/$fileName")
273+
file.getParentFile().mkdirs() // in case file was named `packagename/file.scala` or similar
274+
Files.writeString(file.toPath(), content)
273275
}
274276
snippetDir
275277
}

0 commit comments

Comments
 (0)