From c71313a7d34160e71cc6042fc76ee97ec7daf7ac Mon Sep 17 00:00:00 2001 From: Krzysztof Romanowski Date: Mon, 11 Oct 2021 12:23:27 +0200 Subject: [PATCH] Fix non-working checks --- docs_checker/check.scala | 35 ++++++++++++++---------- website/docs/cookbooks/scala-jvm.md | 8 +++--- website/docs/cookbooks/scala-versions.md | 14 +++++----- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/docs_checker/check.scala b/docs_checker/check.scala index 8a83d070bd..4815be2cc0 100644 --- a/docs_checker/check.scala +++ b/docs_checker/check.scala @@ -35,18 +35,22 @@ def parse(content: Seq[String], currentCommands: Seq[Commands], context: Context case Nil => currentCommands case ScalaCodeBlock(name) :: tail => val (codeLines, rest, newContext) = untilEndOfSnippet(tail)(using context) - + parse(rest, currentCommands :+ Commands.Snippet(name, codeLines, context), newContext) case ScalaCliBlock(failGroup) :: tail => val (codeLines, rest, newContext) = untilEndOfSnippet(tail) assert(codeLines.size != 0) - val runCmd = Commands.Run(codeLines.filterNot(_.trim.startsWith("#")).map(_.split(" ").toList), failGroup != null, newContext) + val runCmd = Commands.Run( + codeLines.filterNot(_.trim.startsWith("#")).map(_.split(" ").toList), + failGroup != null, + newContext + ) parse(rest, currentCommands :+ runCmd, newContext) case CheckBlock(regexOpt) :: tail => val isRegex = regexOpt == "-regex" val (patterns, rest, newContext) = untilEndOfSnippet(tail, CheckBlockEnd) parse(rest, currentCommands :+ Commands.Check(patterns, isRegex, context), newContext) - case _ :: tail => + case _ :: tail => parse(tail, currentCommands, context.copy(line = context.line + 1)) case class TestCase(path: os.Path, failure: Option[Throwable]) @@ -76,7 +80,7 @@ def checkFile(file: os.Path, dest: Option[os.Path]) = val out = os.temp.dir(prefix = destName) var lastOutput: String = null - val allSources = Set.newBuilder[os.Path] + val allSources = Set.newBuilder[os.Path] try println(s"Using $out as output to process $file") @@ -87,13 +91,13 @@ def checkFile(file: os.Path, dest: Option[os.Path]) = case Commands.Run(cmds, shouldFail, _) => cmds.foreach { cmd => println(s"### Running: ${cmd.mkString(" ")}:") - val res = os.proc(cmd).call(cwd = out,mergeErrIntoOut=true, check = false) + val res = os.proc(cmd).call(cwd = out, mergeErrIntoOut = true, check = false) println(res.out.text()) if shouldFail then assert(res.exitCode != 0) else assert(res.exitCode == 0) - + val outputChunks = res.chunks.map { case Left(c) => c @@ -103,17 +107,18 @@ def checkFile(file: os.Path, dest: Option[os.Path]) = lastOutput = res.out.text() } case Commands.Snippet(name, code, c) => - val (prefixLines, codeLines) = code match - case shbang :: tail if shbang.startsWith("#!") => - List(shbang + "\n") -> tail - case other => - Nil -> other - - val file = out / name + val (prefixLines, codeLines) = + code match + case shbang :: tail if shbang.startsWith("#!") => + List(shbang + "\n") -> tail + case other => + Nil -> other + + val file = out / name allSources += file println(s"### Writting $name with:\n${codeLines.mkString("\n")}\n---") - - val prefix = prefixLines.mkString("", "",s"$fakeLineMarker\n" * c.line) + + val prefix = prefixLines.mkString("", "", s"$fakeLineMarker\n" * c.line) os.write(file, code.mkString(prefix, "\n", "")) case Commands.Check(patterns, regex, line) => assert(lastOutput != null, msg("No output stored from previous commands")) diff --git a/website/docs/cookbooks/scala-jvm.md b/website/docs/cookbooks/scala-jvm.md index 7edb7459ac..fd784c5bb5 100644 --- a/website/docs/cookbooks/scala-jvm.md +++ b/website/docs/cookbooks/scala-jvm.md @@ -23,16 +23,16 @@ object Main extends App { Pass `--jvm` to the `scala-cli` command to run your application with the specified java version. -```bash +```bash ignore scala-cli --jvm adopt:11 Main.scala ``` - To test your application with Java 8, change the value of `--jvm` parameter. -```bash fail +```bash ignore fail scala-cli --jvm 8 Main.scala # In this case, it raises an error because the `Files.createTempFile` method is not available in java 8 # @@ -42,7 +42,7 @@ scala-cli --jvm 8 Main.scala # at method main in modules/runner/src/main/scala/scala/cli/runner/Runner.scala:22 inside runner_3.jar ``` - \ No newline at end of file diff --git a/website/docs/cookbooks/scala-versions.md b/website/docs/cookbooks/scala-versions.md index e133081996..0276610272 100644 --- a/website/docs/cookbooks/scala-versions.md +++ b/website/docs/cookbooks/scala-versions.md @@ -37,7 +37,7 @@ object ScalaVersion extends App { val scalaVersion = checkScala3(manifests) val javaVersion = System.getProperty("java.version") - println(s"Scala: $scalaVersion Java: $javaVersion") + println(s"Scala: $scalaVersion") } ``` @@ -48,7 +48,7 @@ scala-cli ScalaVersion.scala ``` @@ -60,7 +60,7 @@ Scala version can be also provided from command line using `--scala` (with `-S` scala-cli -S 2.13.5 ScalaVersion.scala ``` In most cases we do not care for a precise Scala version and 'any Scala 2' or `2.13` is good enough for us. @@ -71,7 +71,7 @@ Scala cli accepts version prefixes so: scala-cli -S 2 ScalaVersion.scala ``` will result in picking up a latest stable release for Scala 2 (`2.13.6` as of when this doc is written) and @@ -80,7 +80,7 @@ will result in picking up a latest stable release for Scala 2 (`2.13.6` as of wh scala-cli -S 2.12 ScalaVersion.scala ``` will use latest stable release of `2.12` `2.12.15`. @@ -108,7 +108,7 @@ scala-cli ScalaVersion.scala version.scala ``` We will results in using `2.12.5`. @@ -124,7 +124,7 @@ scala-cli -S 2.13.5 ScalaVersion.scala version.scala Will result in using `2.13.5` ## When should I provide a full version of scala?