add inferiting flag test

This commit is contained in:
Daylin Morgan 2025-01-29 15:35:05 -06:00
parent a7593561ee
commit 6a93485202
Signed by: daylin
GPG key ID: 950D13E9719334AD
3 changed files with 47 additions and 2 deletions

View file

@ -0,0 +1,32 @@
import std/strformat
import hwylterm, hwylterm/hwylcli
hwylCli:
name "base"
flags:
[global]
always "in all subcommands"
[misc]
misc1 "first misc flag"
misc2 "second misc flag"
subcommands:
[first]
... "command with it's own flag"
flags:
first "first first flag"
run:
echo fmt"{always=},{first=}"
[second]
... "command with 'misc' flags"
flags:
^[misc]
run:
echo fmt"{always=},{misc1=},{misc2=}"
[third]
... "command with only 'misc1' flag"
flags:
^misc1
run:
echo fmt"{always=},{misc1=}"

View file

@ -43,14 +43,16 @@ proc preCompileTestModules*() =
template okWithArgs*(module: string, args = "", output = "") = template okWithArgs*(module: string, args = "", output = "") =
preCompileWorkingModule(module) preCompileWorkingModule(module)
let normalizedOutput = output.strip().strip(leading = false, chars = {'\n'}).dedent()
test (module & "|" & args): test (module & "|" & args):
let (actualOutput, code) = runTestCli(module, args) let (actualOutput, code) = runTestCli(module, args)
check code == 0 check code == 0
check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput check normalizedOutput == actualOutput
template failWithArgs*(module: string, args = "", output = "") = template failWithArgs*(module: string, args = "", output = "") =
preCompileWorkingModule(module) preCompileWorkingModule(module)
let normalizedOutput = output.strip().strip(leading = false, chars = {'\n'}).dedent()
test (module & "|" & args): test (module & "|" & args):
let (actualOutput, code) = runTestCli(module, args) let (actualOutput, code) = runTestCli(module, args)
check code == 1 check code == 1
check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput check normalizedOutput == actualOutput

View file

@ -122,6 +122,17 @@ inside sub c
""", """,
) )
suite "parent-child":
okWithArgs(
"inheritFlags", "first --always", "always=true,first=false"
)
okWithArgs(
"inheritFlags", "second --always --misc2", "always=true,misc1=false,misc2=true"
)
okWithArgs(
"inheritFlags", "third --misc1", "always=false,misc1=true"
)
suite "settings": suite "settings":
okWithArgs( okWithArgs(
"inferShort", "-i input -o output","""input=input, output=output, count=0, nancy=false, ignore=false""" "inferShort", "-i input -o output","""input=input, output=output, count=0, nancy=false, ignore=false"""