diff --git a/README.md b/README.md index b9dfccb..4634488 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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!) diff --git a/testSnippets.scala b/testSnippets.scala index 11eca17..7ffec18 100644 --- a/testSnippets.scala +++ b/testSnippets.scala @@ -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, @@ -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 }