Skip to content

Commit

Permalink
Test and officially describe support for test scopes and Scala-Java s…
Browse files Browse the repository at this point in the history
…nippets
  • Loading branch information
MateuszKubuszok committed May 13, 2024
1 parent 4b296c9 commit 6a23913
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ coursier launch com.kubuszok:scala-cli-md-spec_3:0.1.0 -M com.kubuszok.scalaclim
## Rules of the game

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

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

* if at least one file in multifile snippet has a name ending with `.test.scala` then `scala-cli test [dirname]`
will be used unstead (useful for e.g. defining macros in compile scope and showing them in test scope since
Scala CLI is NOT multi modular)

* Java snippets should not only use `java` in markdown, but also define `// file: filename.java - part of ...`

5. if `--test-only` flag is used, only suites containing at least 1 matching snippet and, within them, only
the matching snippets will be run and displayed (but all markdowns still need to be read to find snippets
and match them against the pattern!)
Expand Down
8 changes: 5 additions & 3 deletions testSnippets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ object Snippet {


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

def loop(remainingContent: List[(String, Int)], location: Location, mode: Mode, result: Vector[Snippet]): List[Snippet] =
(remainingContent, mode) match {
// ``` terminates snippet reading
case ((end(), _) :: lines, Reading(indent, content)) =>
case ((end(_), _) :: lines, Reading(indent, content)) =>
loop(
lines,
location,
Expand Down Expand Up @@ -269,7 +269,9 @@ trait Runner:
val snippetDir = File(s"${tmpDir.getPath()}/${snippet.dirName}")
snippetDir.mkdirs()
snippet.content.fileToContentMap.foreach { case (fileName, Snippet.Content.Single(content)) =>
Files.writeString(File(s"${snippetDir.getPath()}/$fileName").toPath(), content)
val file = File(s"${snippetDir.getPath()}/$fileName")
file.getParentFile().mkdirs() // in case file was named `packagename/file.scala` or similar
Files.writeString(file.toPath(), content)
}
snippetDir
}
Expand Down

0 comments on commit 6a23913

Please sign in to comment.