mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2025-02-22 17:25:51 -06:00
add inferiting flag test
This commit is contained in:
parent
a7593561ee
commit
6a93485202
3 changed files with 47 additions and 2 deletions
32
tests/cli/clis/inheritFlags.nim
Normal file
32
tests/cli/clis/inheritFlags.nim
Normal 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=}"
|
|
@ -43,14 +43,16 @@ proc preCompileTestModules*() =
|
|||
|
||||
template okWithArgs*(module: string, args = "", output = "") =
|
||||
preCompileWorkingModule(module)
|
||||
let normalizedOutput = output.strip().strip(leading = false, chars = {'\n'}).dedent()
|
||||
test (module & "|" & args):
|
||||
let (actualOutput, code) = runTestCli(module, args)
|
||||
check code == 0
|
||||
check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput
|
||||
check normalizedOutput == actualOutput
|
||||
|
||||
template failWithArgs*(module: string, args = "", output = "") =
|
||||
preCompileWorkingModule(module)
|
||||
let normalizedOutput = output.strip().strip(leading = false, chars = {'\n'}).dedent()
|
||||
test (module & "|" & args):
|
||||
let (actualOutput, code) = runTestCli(module, args)
|
||||
check code == 1
|
||||
check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput
|
||||
check normalizedOutput == actualOutput
|
||||
|
|
|
@ -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":
|
||||
okWithArgs(
|
||||
"inferShort", "-i input -o output","""input=input, output=output, count=0, nancy=false, ignore=false"""
|
||||
|
|
Loading…
Add table
Reference in a new issue