@@ -35,18 +35,22 @@ def parse(content: Seq[String], currentCommands: Seq[Commands], context: Context
35
35
case Nil => currentCommands
36
36
case ScalaCodeBlock (name) :: tail =>
37
37
val (codeLines, rest, newContext) = untilEndOfSnippet(tail)(using context)
38
-
38
+
39
39
parse(rest, currentCommands :+ Commands .Snippet (name, codeLines, context), newContext)
40
40
case ScalaCliBlock (failGroup) :: tail =>
41
41
val (codeLines, rest, newContext) = untilEndOfSnippet(tail)
42
42
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
+ )
44
48
parse(rest, currentCommands :+ runCmd, newContext)
45
49
case CheckBlock (regexOpt) :: tail =>
46
50
val isRegex = regexOpt == " -regex"
47
51
val (patterns, rest, newContext) = untilEndOfSnippet(tail, CheckBlockEnd )
48
52
parse(rest, currentCommands :+ Commands .Check (patterns, isRegex, context), newContext)
49
- case _ :: tail =>
53
+ case _ :: tail =>
50
54
parse(tail, currentCommands, context.copy(line = context.line + 1 ))
51
55
52
56
case class TestCase (path : os.Path , failure : Option [Throwable ])
@@ -76,7 +80,7 @@ def checkFile(file: os.Path, dest: Option[os.Path]) =
76
80
val out = os.temp.dir(prefix = destName)
77
81
78
82
var lastOutput : String = null
79
- val allSources = Set .newBuilder[os.Path ]
83
+ val allSources = Set .newBuilder[os.Path ]
80
84
81
85
try
82
86
println(s " Using $out as output to process $file" )
@@ -87,13 +91,13 @@ def checkFile(file: os.Path, dest: Option[os.Path]) =
87
91
case Commands .Run (cmds, shouldFail, _) =>
88
92
cmds.foreach { cmd =>
89
93
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 )
91
95
println(res.out.text())
92
96
if shouldFail then
93
97
assert(res.exitCode != 0 )
94
98
else
95
99
assert(res.exitCode == 0 )
96
-
100
+
97
101
val outputChunks = res.chunks.map {
98
102
case Left (c) =>
99
103
c
@@ -103,17 +107,18 @@ def checkFile(file: os.Path, dest: Option[os.Path]) =
103
107
lastOutput = res.out.text()
104
108
}
105
109
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
113
118
allSources += file
114
119
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)
117
122
os.write(file, code.mkString(prefix, " \n " , " " ))
118
123
case Commands .Check (patterns, regex, line) =>
119
124
assert(lastOutput != null , msg(" No output stored from previous commands" ))
0 commit comments