From 73d58a23598ccd1c4c9c3335599c4e0a9b2ebeb9 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sun, 26 Jan 2025 14:17:36 -0600 Subject: [PATCH] make test suite format more forgiving --- tests/cli/lib.nim | 7 +-- tests/cli/tester.nim | 109 ++++++++++++++++++++++++++----------------- 2 files changed, 69 insertions(+), 47 deletions(-) diff --git a/tests/cli/lib.nim b/tests/cli/lib.nim index c4eb4b0..957d29f 100644 --- a/tests/cli/lib.nim +++ b/tests/cli/lib.nim @@ -41,19 +41,16 @@ proc preCompileTestModules*() = eraseLine stdout - #let (_, moduleName, _) = srcModule.splitFile -# preCompileWorkingModule(moduleName) - template okWithArgs*(module: string, args = "", output = "") = preCompileWorkingModule(module) test (module & "|" & args): let (actualOutput, code) = runTestCli(module, args) check code == 0 - check output == actualOutput + check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput template failWithArgs*(module: string, args = "", output = "") = preCompileWorkingModule(module) test (module & "|" & args): let (actualOutput, code) = runTestCli(module, args) check code == 1 - check output == actualOutput + check output.strip().strip(leading=false, chars = {'\n'}).dedent() == actualOutput diff --git a/tests/cli/tester.nim b/tests/cli/tester.nim index 060fa7c..d6aebe4 100644 --- a/tests/cli/tester.nim +++ b/tests/cli/tester.nim @@ -5,61 +5,72 @@ if commandLineParams().len == 0: preCompileTestModules() suite "hwylcli": - - okWithArgs( - "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""" - ) + okWithArgs("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( - "posFirst", - "a b", - "error missing positional args, got: 2, expected at least: 3", + "posFirst", "a b", "error missing positional args, got: 2, expected at least: 3" ) okWithArgs("posLast", "a b", """first=a, second=b, third=@[]""") 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") - failWithArgs("enumFlag","--color black", "error failed to parse value for color as enum: black expected one of: red,blue,green") + 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", + ) - okWithArgs("subcommands", "a b c","""input=b outputs=@["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", "a b c", """input=b outputs=@["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("posFirst", "--help", -"""usage: + okWithArgs( + "posFirst", "--help", + """ +usage: positionals first... second third [flags] flags: - -h --help show this help""") + -h --help show this help +""", + ) - - okWithArgs("flagSettings", "--help", -"""usage: + okWithArgs( + "flagSettings", "--help", + """ +usage: flag-settings [flags] flags: --input flag with default hidden --count a count var with default (0) - -h --help show this help""") + -h --help show this help +""", + ) - okWithArgs("cliCfgSettingHideDefault", "--help", -"""usage: + okWithArgs( + "cliCfgSettingHideDefault", "--help", +""" +usage: setting-hide-default [flags] flags: --input flag with default hidden --count a count var with default - -h --help show this help""") + -h --help show this help +""", + ) - okWithArgs("customHelp", "--help", -"""usage: + okWithArgs( + "customHelp", "--help", +""" +usage: custom-help [flags] flags: @@ -68,18 +79,32 @@ flags: --output output (output.txt) -h --help - show this help""") - okWithArgs("subHooks", "a", """preSub from root! + show this help +""", + ) + okWithArgs( + "subHooks", "a", +""" +preSub from root! inside sub 'a' -postSub from root!""") - okWithArgs("subHooks", "b a", """preSub from root! +postSub from root! +""", + ) + okWithArgs( + "subHooks", "b a", + """ +preSub from root! inside sub 'b a' postSub from root! -inside sub 'b'""") - okWithArgs("subHooks", "c a","""preSub from 'c'! +inside sub 'b' +""", + ) + okWithArgs( + "subHooks", "c a", +""" +preSub from 'c'! inside sub 'c a' postSub from root! -inside sub c""") - - - +inside sub c +""", + )