Skip to content

Commit

Permalink
[script] add listCases subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Sep 5, 2024
1 parent 8ef0400 commit a25003f
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions script/emu/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ object Main:
end run

@main
def offline(
def check(
@arg(
name = "config",
short = 'c',
Expand Down Expand Up @@ -344,7 +344,48 @@ object Main:

val ret = os.proc(driverArgs).call(stdout = os.Inherit, stderr = os.Inherit, check = false)
if (ret.exitCode != 0) then Logger.fatal("offline checker run failed")
end offline
end check

@main
def listCases(
@arg(
name = "config",
short = 'c',
doc = "specify the config for test cases"
) config: String,
pattern: Leftover[String]
): Unit =
if pattern.value.length != 1 then
Logger.fatal("invalid pattern was given, plz run 't1-helper listCases -c <config> <regexp>'")

val regexp = pattern.value.head.r
Logger.info("Fetching current test cases")
val args = Seq(
"nix",
"--no-warn-dirty",
"eval",
s".#t1.${config}.ip.cases",
"--apply",
"""cases: with builtins;
| (map
| (drv: drv.pname)
| (filter
| (drv: drv ? type && drv.type == "derivation" && drv ? pname)
| (concatMap attrValues
| (filter
| (v: typeOf v == "set")
| (attrValues cases)))))""".stripMargin,
"--json"
)
val output = os.proc(args).call().out.trim()
println()
ujson
.read(output)
.arr
.map(v => v.str)
.filter(eachCase => regexp.findAllIn(eachCase).nonEmpty)
.foreach(p => println(s"* ${p}"))
end listCases

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
end Main

0 comments on commit a25003f

Please sign in to comment.