add tests for hwylcli

This commit is contained in:
Daylin Morgan 2024-09-30 17:23:52 -05:00
parent e447fc2b92
commit 337083afe1
Signed by: daylin
GPG key ID: 950D13E9719334AD
4 changed files with 15 additions and 23 deletions

View file

@ -2,6 +2,7 @@ import std/[os, strformat, strutils]
task test, "run tests": task test, "run tests":
selfExec "r tests/tbbansi.nim" selfExec "r tests/tbbansi.nim"
selfExec "r tests/tcli.nim"
task develop, "install cligen for development": task develop, "install cligen for development":
exec "nimble install -l 'cligen@1.7.5'" exec "nimble install -l 'cligen@1.7.5'"

View file

@ -72,6 +72,7 @@ proc bbImpl(cli: HwylCli): string =
result.add indent(cli.usage, 2 ) result.add indent(cli.usage, 2 )
result.add "\n" result.add "\n"
if cli.flags.len > 0: if cli.flags.len > 0:
result.add "\n"
result.add "[" & cli.styles.hdr & "]" result.add "[" & cli.styles.hdr & "]"
result.add "flags[/]:\n" result.add "flags[/]:\n"
for f in cli.flags: for f in cli.flags:

View file

@ -1,28 +1,17 @@
import std/[ import std/[
compilesettings,
os,
osproc,
strutils,
times,
unittest unittest
] ]
const pathToSrc = querySetting(SingleValueSetting.projectPath)
proc cliRun(cmd: string): string = import hwylterm, hwylterm/cli
let (output, _) = execCmdEx(pathToSrc / "bbansi.out " & cmd)
return output.strip()
suite "cli": suite "cli":
setup: test "cli":
let let expected = """[b]test-program[/] [[args...]
cli = pathToSrc / "bbansi.out"
srcDir = pathToSrc / ".." / "src" [b cyan]flags[/]:
cmd = "nim c -o:" & cli & " " & (srcDir / "bbansi.nim") [yellow]-h[/] [magenta]--help [/] []show this help[/]
if not cli.fileExists or getFileInfo(cli).lastWriteTime < getFileInfo(srcDir).lastWriteTime: [yellow]-V[/] [magenta]--version[/] []print version[/]
echo " -> compiling test binary" """
require execCmdEx(cmd).exitCode == 0 let cli = newHwylCli("[b]test-program[/] [[args...]",flags = [("h","help","show this help",),("V","version","print version")])
test "simple": check $cli == $bb(expected)
check "\e[31mRed\e[0m" == cliRun "[red]Red[/]"
check "\e[1;31mRed\e[0m\e[1m Not Red but Bold\e[0m" ==
cliRun "'[red]Red[/] Not Red but Bold' " & "--style:bold"

View file

@ -2,7 +2,8 @@
- [x] add cligen adapters to add colors with bbansi - [x] add cligen adapters to add colors with bbansi
- [ ] add integration test check cligen - [ ] add integration test check cligen
- [ ] add generic help generator to accompany parseopt - [x] add generic help generator to accompany parseopt
## improvements ## improvements
- [ ] consider reducing illwill surface to only relevant IO (input) features - [ ] consider reducing illwill surface to only relevant IO (input) features