Skip to content

Commit c2c2df5

Browse files
committed
Fix non-working checks
1 parent 7fec501 commit c2c2df5

File tree

6 files changed

+45
-40
lines changed

6 files changed

+45
-40
lines changed

docs_checker/check.scala

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,22 @@ def parse(content: Seq[String], currentCommands: Seq[Commands], context: Context
3535
case Nil => currentCommands
3636
case ScalaCodeBlock(name) :: tail =>
3737
val (codeLines, rest, newContext) = untilEndOfSnippet(tail)(using context)
38-
38+
3939
parse(rest, currentCommands :+ Commands.Snippet(name, codeLines, context), newContext)
4040
case ScalaCliBlock(failGroup) :: tail =>
4141
val (codeLines, rest, newContext) = untilEndOfSnippet(tail)
4242
assert(codeLines.size != 0)
43-
val runCmd = Commands.Run(codeLines.filterNot(_.trim.startsWith("#")).map(_.split(" ").toList), failGroup != null, newContext)
43+
val runCmd = Commands.Run(
44+
codeLines.filterNot(_.trim.startsWith("#")).map(_.split(" ").toList),
45+
failGroup != null,
46+
newContext
47+
)
4448
parse(rest, currentCommands :+ runCmd, newContext)
4549
case CheckBlock(regexOpt) :: tail =>
4650
val isRegex = regexOpt == "-regex"
4751
val (patterns, rest, newContext) = untilEndOfSnippet(tail, CheckBlockEnd)
4852
parse(rest, currentCommands :+ Commands.Check(patterns, isRegex, context), newContext)
49-
case _ :: tail =>
53+
case _ :: tail =>
5054
parse(tail, currentCommands, context.copy(line = context.line + 1))
5155

5256
case class TestCase(path: os.Path, failure: Option[Throwable])
@@ -76,7 +80,7 @@ def checkFile(file: os.Path, dest: Option[os.Path]) =
7680
val out = os.temp.dir(prefix = destName)
7781

7882
var lastOutput: String = null
79-
val allSources = Set.newBuilder[os.Path]
83+
val allSources = Set.newBuilder[os.Path]
8084

8185
try
8286
println(s"Using $out as output to process $file")
@@ -87,13 +91,13 @@ def checkFile(file: os.Path, dest: Option[os.Path]) =
8791
case Commands.Run(cmds, shouldFail, _) =>
8892
cmds.foreach { cmd =>
8993
println(s"### Running: ${cmd.mkString(" ")}:")
90-
val res = os.proc(cmd).call(cwd = out,mergeErrIntoOut=true, check = false)
94+
val res = os.proc(cmd).call(cwd = out, mergeErrIntoOut = true, check = false)
9195
println(res.out.text())
9296
if shouldFail then
9397
assert(res.exitCode != 0)
9498
else
9599
assert(res.exitCode == 0)
96-
100+
97101
val outputChunks = res.chunks.map {
98102
case Left(c) =>
99103
c
@@ -103,17 +107,18 @@ def checkFile(file: os.Path, dest: Option[os.Path]) =
103107
lastOutput = res.out.text()
104108
}
105109
case Commands.Snippet(name, code, c) =>
106-
val (prefixLines, codeLines) = code match
107-
case shbang :: tail if shbang.startsWith("#!") =>
108-
List(shbang + "\n") -> tail
109-
case other =>
110-
Nil -> other
111-
112-
val file = out / name
110+
val (prefixLines, codeLines) =
111+
code match
112+
case shbang :: tail if shbang.startsWith("#!") =>
113+
List(shbang + "\n") -> tail
114+
case other =>
115+
Nil -> other
116+
117+
val file = out / name
113118
allSources += file
114119
println(s"### Writting $name with:\n${codeLines.mkString("\n")}\n---")
115-
116-
val prefix = prefixLines.mkString("", "",s"$fakeLineMarker\n" * c.line)
120+
121+
val prefix = prefixLines.mkString("", "", s"$fakeLineMarker\n" * c.line)
117122
os.write(file, code.mkString(prefix, "\n", ""))
118123
case Commands.Check(patterns, regex, line) =>
119124
assert(lastOutput != null, msg("No output stored from previous commands"))

examples/scala-jvm/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ object Main extends App {
2323

2424
Pass `--jvm` to the `scala-cli` command to run your application with the specified java version.
2525

26-
```bash
27-
scala-cli Main.scala --jvm 11
26+
```bash ignore
27+
scala-cli --jvm adopt:11 Main.scala
2828
```
2929

30-
<!-- Expected:
30+
<!-- ignored Expected:
3131
Hello from ScalaCli
3232
-->
3333

3434
To test your application with Java 8, change the value of `--jvm` parameter.
35-
```bash fail
36-
scala-cli Main.scala --jvm 8
35+
```bash ignore fail
36+
scala-cli --jvm 8 Main.scala
3737
# In this case, it raises an error because the `Files.createTempFile` method is not available in java 8
3838
#
3939
# Exception in thread main: java.lang.Exception: java.lang.NoSuchMethodError: java.nio.file.Files.writeString(Ljava/nio/file/Path;Ljava/lang/CharSequence;[Ljava/nio/file/OpenOption;)Ljava/nio/file/Path;
@@ -42,7 +42,7 @@ scala-cli Main.scala --jvm 8
4242
# at method main in modules/runner/src/main/scala/scala/cli/runner/Runner.scala:22 inside runner_3.jar
4343
```
4444

45-
<!-- Expected:
45+
<!-- ignored Expected:
4646
java.lang.NoSuchMethodError
4747
java.nio.file.Files.writeString
4848
-->

examples/scala-versions/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object ScalaVersion extends App {
3737
val scalaVersion = checkScala3(manifests)
3838
val javaVersion = System.getProperty("java.version")
3939

40-
println(s"Scala: $scalaVersion Java: $javaVersion")
40+
println(s"Scala: $scalaVersion")
4141
}
4242
```
4343

@@ -48,7 +48,7 @@ scala-cli ScalaVersion.scala
4848
```
4949

5050
<!-- Expected-regex:
51-
Scala: 3\..* Java: 11\..+
51+
Scala: 3\..*
5252
-->
5353

5454

@@ -60,7 +60,7 @@ Scala version can be also provided from command line using `--scala` (with `-S`
6060
scala-cli -S 2.13.5 ScalaVersion.scala
6161
```
6262
<!-- Expected-regex:
63-
Scala: 2\.13\.5 Java: 11\..+
63+
Scala: 2\.13\.5
6464
-->
6565

6666
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:
7171
scala-cli -S 2 ScalaVersion.scala
7272
```
7373
<!-- Expected-regex:
74-
Scala: 2\..+ Java: 11\..+
74+
Scala: 2\..+
7575
-->
7676

7777
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
8080
scala-cli -S 2.12 ScalaVersion.scala
8181
```
8282
<!-- Expected-regex:
83-
Scala: 2\.12\.15 Java: 11\..+
83+
Scala: 2\.12\.15
8484
-->
8585

8686
will use latest stable release of `2.12` `2.12.15`.
@@ -108,7 +108,7 @@ scala-cli ScalaVersion.scala version.scala
108108
```
109109

110110
<!-- Expected-regex: TODO -
111-
Scala: 2\.12\.5 Java: 11\..+
111+
Scala: 2\.12\.5
112112
-->
113113

114114
We will results in using `2.12.5`.
@@ -124,7 +124,7 @@ scala-cli -S 2.13.5 ScalaVersion.scala version.scala
124124
Will result in using `2.13.5`
125125

126126
<!-- Expected-regex:
127-
Scala: 2\.13\.5 Java: 11\..+
127+
Scala: 2\.13\.5
128128
-->
129129

130130
## When should I provide a full version of scala?

examples/scala-versions/ScalaVersion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ object ScalaVersion extends App {
2727
val scalaVersion = checkScala3(manifests)
2828
val javaVersion = System.getProperty("java.version")
2929

30-
println(s"Scala: $scalaVersion Java: $javaVersion")
30+
println(s"Scala: $scalaVersion")
3131
}

website/docs/cookbooks/scala-jvm.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ object Main extends App {
2323

2424
Pass `--jvm` to the `scala-cli` command to run your application with the specified java version.
2525

26-
```bash
26+
```bash ignore
2727
scala-cli --jvm adopt:11 Main.scala
2828
```
2929

30-
<!-- Expected:
30+
<!-- ignored Expected:
3131
Hello from ScalaCli
3232
-->
3333

3434
To test your application with Java 8, change the value of `--jvm` parameter.
35-
```bash fail
35+
```bash ignore fail
3636
scala-cli --jvm 8 Main.scala
3737
# In this case, it raises an error because the `Files.createTempFile` method is not available in java 8
3838
#
@@ -42,7 +42,7 @@ scala-cli --jvm 8 Main.scala
4242
# at method main in modules/runner/src/main/scala/scala/cli/runner/Runner.scala:22 inside runner_3.jar
4343
```
4444

45-
<!-- Expected:
45+
<!-- ignored Expected:
4646
java.lang.NoSuchMethodError
4747
java.nio.file.Files.writeString
4848
-->

website/docs/cookbooks/scala-versions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object ScalaVersion extends App {
3737
val scalaVersion = checkScala3(manifests)
3838
val javaVersion = System.getProperty("java.version")
3939

40-
println(s"Scala: $scalaVersion Java: $javaVersion")
40+
println(s"Scala: $scalaVersion")
4141
}
4242
```
4343

@@ -48,7 +48,7 @@ scala-cli ScalaVersion.scala
4848
```
4949

5050
<!-- Expected-regex:
51-
Scala: 3\..* Java: 11\..+
51+
Scala: 3\..*
5252
-->
5353

5454

@@ -60,7 +60,7 @@ Scala version can be also provided from command line using `--scala` (with `-S`
6060
scala-cli -S 2.13.5 ScalaVersion.scala
6161
```
6262
<!-- Expected-regex:
63-
Scala: 2\.13\.5 Java: .+
63+
Scala: 2\.13\.5
6464
-->
6565

6666
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:
7171
scala-cli -S 2 ScalaVersion.scala
7272
```
7373
<!-- Expected-regex:
74-
Scala: 2\..+ Java: 11\..+
74+
Scala: 2\..+
7575
-->
7676

7777
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
8080
scala-cli -S 2.12 ScalaVersion.scala
8181
```
8282
<!-- Expected-regex:
83-
Scala: 2\.12\.15 Java: 11\..+
83+
Scala: 2\.12\.15
8484
-->
8585

8686
will use latest stable release of `2.12` `2.12.15`.
@@ -108,7 +108,7 @@ scala-cli ScalaVersion.scala version.scala
108108
```
109109

110110
<!-- Expected-regex: TODO -
111-
Scala: 2\.12\.5 Java: 11\..+
111+
Scala: 2\.12\.5
112112
-->
113113

114114
We will results in using `2.12.5`.
@@ -124,7 +124,7 @@ scala-cli -S 2.13.5 ScalaVersion.scala version.scala
124124
Will result in using `2.13.5`
125125

126126
<!-- Expected-regex:
127-
Scala: 2\.13\.5 Java: 11\..+
127+
Scala: 2\.13\.5
128128
-->
129129

130130
## When should I provide a full version of scala?

0 commit comments

Comments
 (0)