@@ -13,7 +13,7 @@ import scala.util.matching.Regex
13
13
val SnippetBlock = """ *(`{2}`+)[^ ]+ title=([\w\d.\-/_]+) *""" .r
14
14
val CompileBlock = """ *(`{2}`+) *(\w+) +(compile|fail) *(?:title=([\w\d.\-/_]+))? *(power)? *""" .r
15
15
def compileBlockEnds (backticks : String ) = s """ * $backticks * """ .r
16
- val BashCommand = """ *```bash *(fail|run-fail)? *""" .r
16
+ val BashCommand = """ *```bash *(fail|run-fail)? *(clean)? * """ .r
17
17
val CheckBlock = """ *\<\!-- Expected(-regex)?: *""" .r
18
18
val CheckBlockEnd = """ *\--> *""" .r
19
19
val Clear = """ *<!--+ *clear *-+-> *""" .r
@@ -35,8 +35,12 @@ enum Commands:
35
35
case Check (patterns, regex, _) =>
36
36
val kind = if regex then " regexes" else " patterns"
37
37
s " last output matches $kind: ${patterns.map(p => s " ' $p' " ).mkString(" , " )}"
38
- case Run (cmd, shouldFail, _) =>
39
- val prefix = if shouldFail then " [failure expected] " else " "
38
+ case Run (cmd, shouldFail, shouldClean, _) =>
39
+ val prefix = shouldFail -> shouldClean match
40
+ case (true , true ) => " [failure expected, clean]"
41
+ case (true , false ) => " [failure expected]"
42
+ case (false , true ) => " [clean]"
43
+ case _ => " "
40
44
cmd.mkString(prefix, " " , " " )
41
45
case Write (name, _, _) =>
42
46
name
@@ -53,7 +57,7 @@ enum Commands:
53
57
shouldFail : Boolean ,
54
58
power : Boolean
55
59
)
56
- case Run (scriptLines : Seq [String ], shouldFail : Boolean , context : Context )
60
+ case Run (scriptLines : Seq [String ], shouldFail : Boolean , shouldClean : Boolean , context : Context )
57
61
case Check (patterns : Seq [String ], regex : Boolean , context : Context )
58
62
case Clear (context : Context )
59
63
@@ -100,8 +104,8 @@ def parse(content: Seq[String], currentCommands: Seq[Commands], context: Context
100
104
compileBlockEnds(backticks)
101
105
)
102
106
103
- case BashCommand (failGroup) :: tail =>
104
- parseMultiline(tail, Commands .Run (_, failGroup != null , context))
107
+ case BashCommand (failGroup, clean ) :: tail =>
108
+ parseMultiline(tail, Commands .Run (_, failGroup != null , clean != null , context))
105
109
106
110
case CheckBlock (regexOpt) :: tail =>
107
111
val isRegex = regexOpt == " -regex"
@@ -274,7 +278,15 @@ def checkFile(file: os.Path, options: Options): Unit =
274
278
res.exitCode
275
279
276
280
cmd match
277
- case Commands .Run (cmds, shouldFail, _) =>
281
+ case Commands .Run (cmds, shouldFail, shouldClean, _) =>
282
+ if shouldClean then
283
+ os.list(out)
284
+ .filterNot(_ == binDir)
285
+ .filterNot(_.last.endsWith(" .scala" ))
286
+ .filterNot(_.last.endsWith(" .sc" ))
287
+ .filterNot(_.last.endsWith(" .java" ))
288
+ .filterNot(_.last.endsWith(" .md" ))
289
+ .foreach(os.remove.all)
278
290
val script = out / " .scala-build" / " run.sh"
279
291
os.write.over(script, mkBashScript(cmds), createFolders = true )
280
292
os.perms.set(script, " rwxr-xr-x" )
0 commit comments