make test suite format more forgiving

This commit is contained in:
Daylin Morgan 2025-01-26 14:17:36 -06:00
parent 5f2fcdc4ed
commit 73d58a2359
Signed by: daylin
GPG key ID: 950D13E9719334AD
2 changed files with 69 additions and 47 deletions

View file

@ -41,19 +41,16 @@ proc preCompileTestModules*() =
eraseLine stdout eraseLine stdout
#let (_, moduleName, _) = srcModule.splitFile
# preCompileWorkingModule(moduleName)
template okWithArgs*(module: string, args = "", output = "") = template okWithArgs*(module: string, args = "", output = "") =
preCompileWorkingModule(module) preCompileWorkingModule(module)
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 == actualOutput check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput
template failWithArgs*(module: string, args = "", output = "") = template failWithArgs*(module: string, args = "", output = "") =
preCompileWorkingModule(module) preCompileWorkingModule(module)
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 == actualOutput check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput

View file

@ -5,61 +5,72 @@ if commandLineParams().len == 0:
preCompileTestModules() preCompileTestModules()
suite "hwylcli": suite "hwylcli":
okWithArgs("posBasic", "a b c d e", """args=@["a", "b", "c", "d", "e"]""")
okWithArgs( okWithArgs("posFirst", "a b c d e", """first=@["a", "b", "c"], second=d, third=e""")
"posBasic",
"a b c d e",
"""args=@["a", "b", "c", "d", "e"]"""
)
okWithArgs(
"posFirst",
"a b c d e",
"""first=@["a", "b", "c"], second=d, third=e"""
)
failWithArgs( failWithArgs(
"posFirst", "posFirst", "a b", "error missing positional args, got: 2, expected at least: 3"
"a b",
"error missing positional args, got: 2, expected at least: 3",
) )
okWithArgs("posLast", "a b", """first=a, second=b, third=@[]""") okWithArgs("posLast", "a b", """first=a, second=b, third=@[]""")
okWithArgs("posNoMulti", "5 b c", """first=5, second=b, third=c""") okWithArgs("posNoMulti", "5 b c", """first=5, second=b, third=c""")
failWithArgs("posNoMulti", "5 b c d", """error unexepected positional args, got: 4, expected: 3""") failWithArgs(
"posNoMulti", "5 b c d",
"""error unexepected positional args, got: 4, expected: 3""",
)
okWithArgs("enumFlag","--color red", "color=red") okWithArgs("enumFlag", "--color red", "color=red")
failWithArgs("enumFlag","--color black", "error failed to parse value for color as enum: black expected one of: red,blue,green") failWithArgs(
"enumFlag", "--color black",
"error failed to parse value for color as enum: black expected one of: red,blue,green",
)
okWithArgs("subcommands", "a b c","""input=b outputs=@["c"]""") okWithArgs("subcommands", "a b c", """input=b outputs=@["c"]""")
failWithArgs("subcommands", "b b c","""error got unexpected positionals args: b c""") failWithArgs("subcommands", "b b c", """error got unexpected positionals args: b c""")
okWithArgs("subcommands","b --input in --outputs out1 --outputs out2", """input=in outputs=@["out1", "out2"]""") okWithArgs(
"subcommands", "b --input in --outputs out1 --outputs out2",
"""input=in outputs=@["out1", "out2"]""",
)
okWithArgs("posFirst", "--help", okWithArgs(
"""usage: "posFirst", "--help",
"""
usage:
positionals first... second third [flags] positionals first... second third [flags]
flags: flags:
-h --help show this help""") -h --help show this help
""",
)
okWithArgs(
okWithArgs("flagSettings", "--help", "flagSettings", "--help",
"""usage: """
usage:
flag-settings [flags] flag-settings [flags]
flags: flags:
--input flag with default hidden --input flag with default hidden
--count a count var with default (0) --count a count var with default (0)
-h --help show this help""") -h --help show this help
""",
)
okWithArgs("cliCfgSettingHideDefault", "--help", okWithArgs(
"""usage: "cliCfgSettingHideDefault", "--help",
"""
usage:
setting-hide-default [flags] setting-hide-default [flags]
flags: flags:
--input flag with default hidden --input flag with default hidden
--count a count var with default --count a count var with default
-h --help show this help""") -h --help show this help
""",
)
okWithArgs("customHelp", "--help", okWithArgs(
"""usage: "customHelp", "--help",
"""
usage:
custom-help [flags] custom-help [flags]
flags: flags:
@ -68,18 +79,32 @@ flags:
--output --output
output (output.txt) output (output.txt)
-h --help -h --help
show this help""") show this help
okWithArgs("subHooks", "a", """preSub from root! """,
)
okWithArgs(
"subHooks", "a",
"""
preSub from root!
inside sub 'a' inside sub 'a'
postSub from root!""") postSub from root!
okWithArgs("subHooks", "b a", """preSub from root! """,
)
okWithArgs(
"subHooks", "b a",
"""
preSub from root!
inside sub 'b a' inside sub 'b a'
postSub from root! postSub from root!
inside sub 'b'""") inside sub 'b'
okWithArgs("subHooks", "c a","""preSub from 'c'! """,
)
okWithArgs(
"subHooks", "c a",
"""
preSub from 'c'!
inside sub 'c a' inside sub 'c a'
postSub from root! postSub from root!
inside sub c""") inside sub c
""",
)