mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2025-02-23 09:45:50 -06:00
revamp tester
This commit is contained in:
parent
5020199fd1
commit
ac3e5663d0
3 changed files with 47 additions and 19 deletions
|
@ -8,11 +8,10 @@ let hwylCliWriteTime = getFileInfo(hwylCliSrc).lastWriteTime
|
||||||
if not dirExists(binDir):
|
if not dirExists(binDir):
|
||||||
createDir(binDir)
|
createDir(binDir)
|
||||||
|
|
||||||
proc runTestCli(module: string, args: string, code: int = 0): string =
|
proc runTestCli(module: string, args: string, code: int = 0): (string, int) =
|
||||||
let cmd = binDir / module & " " & args
|
let cmd = binDir / module & " " & args
|
||||||
let (output, exitCode) = execCmdEx(cmd)
|
let (output, code) = execCmdEx(cmd)
|
||||||
check code == exitCode
|
result = (output.strip(), code)
|
||||||
result = output.strip()
|
|
||||||
|
|
||||||
proc preCompileWorkingModule(module: string) =
|
proc preCompileWorkingModule(module: string) =
|
||||||
let exe = binDir / module
|
let exe = binDir / module
|
||||||
|
@ -24,6 +23,16 @@ proc preCompileWorkingModule(module: string) =
|
||||||
echo "cmd: ", cmd
|
echo "cmd: ", cmd
|
||||||
quit "failed to precompile test module"
|
quit "failed to precompile test module"
|
||||||
|
|
||||||
proc checkRunWithArgs*(module: string, args = "", output = "", code = 0) =
|
template okWithArgs*(module: string, args = "", output = "") =
|
||||||
preCompileWorkingModule(module)
|
preCompileWorkingModule(module)
|
||||||
check output == runTestCli(module, args, code)
|
test module:
|
||||||
|
let (actualOutput, code) = runTestCli(module, args)
|
||||||
|
check code == 0
|
||||||
|
check output == actualOutput
|
||||||
|
|
||||||
|
template failWithArgs*(module: string, args = "", output = "") =
|
||||||
|
preCompileWorkingModule(module)
|
||||||
|
test module:
|
||||||
|
let (actualOutput, code) = runTestCli(module, args)
|
||||||
|
check code == 1
|
||||||
|
check output == actualOutput
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
import std/[unittest]
|
|
||||||
import ./lib
|
|
||||||
|
|
||||||
suite "hwylcli":
|
|
||||||
test "positionals":
|
|
||||||
checkRunWithArgs("posFirst", "a b c d e","""first=@["a", "b", "c"], second=d, third=e""")
|
|
||||||
checkRunWithArgs("posFirst", "a b", "error missing positional args, got: 2, expected at least: 3", code = 1)
|
|
||||||
checkRunWithArgs("posLast", "a b", """first=a, second=b, third=@[]""")
|
|
||||||
checkRunWithArgs("posLastExact", "a b c d e", """first=a, second=b, third=@["c", "d", "e"]""")
|
|
||||||
checkRunWithArgs("posNoMulti", "5 b c", """first=5, second=b, third=c""")
|
|
||||||
checkRunWithArgs("posNoMulti", "5 b c d", """error missing positional args, got: 4, expected: 3""", code = 1)
|
|
||||||
checkRunWithArgs("enumFlag","--color red", "")
|
|
||||||
checkRunWithArgs("enumFlag","--color black", "")
|
|
32
tests/cli/tester.nim
Normal file
32
tests/cli/tester.nim
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import std/[unittest]
|
||||||
|
import ./lib
|
||||||
|
|
||||||
|
suite "hwylcli":
|
||||||
|
test "positionals":
|
||||||
|
okWithArgs(
|
||||||
|
"posFirst",
|
||||||
|
"a b c d e",
|
||||||
|
"""
|
||||||
|
first=@["a", "b", "c"], second=d, third=e
|
||||||
|
args=@[]"""
|
||||||
|
)
|
||||||
|
failWithArgs(
|
||||||
|
"posFirst",
|
||||||
|
"a b",
|
||||||
|
"error missing positional args, got: 2, expected at least: 3",
|
||||||
|
)
|
||||||
|
okWithArgs("posLast", "a b", """first=a, second=b, third=@[]""")
|
||||||
|
okWithArgs("posLastExact", "a b c d e", """first=a, second=b, third=@["c", "d", "e"]""")
|
||||||
|
okWithArgs("posNoMulti", "5 b c", """first=5, second=b, third=c""")
|
||||||
|
failWithArgs("posNoMulti", "5 b c d", """error missing positional args, got: 4, expected: 3""")
|
||||||
|
test "special flag types":
|
||||||
|
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")
|
||||||
|
|
||||||
|
test "help":
|
||||||
|
okWithArgs("posFirst", "--help",
|
||||||
|
"""usage:
|
||||||
|
positionals first... second third [flags]
|
||||||
|
|
||||||
|
flags:
|
||||||
|
-h --help show this help""")
|
Loading…
Add table
Reference in a new issue