@@ -30,82 +30,87 @@ func cmdsToName(cmds: string): string =
3030func helpToName (help: string ): string =
3131 help.replace (" :" , " _" )
3232
33+ proc execCmdTest (fname, cmdName: string , cmds = " " , help = " " ) =
34+ let res = execCmdEx (fname & " " & cmds & " --help" & help)
35+ let output = res.output.normalizeHelp ()
36+ let snapshot = snapshotsPath / cmdName & cmds.cmdsToName () & help.helpToName () & " .txt"
37+ if res.exitCode != 0 :
38+ checkpoint " Run output: " & res.output
39+ fail ()
40+ elif not fileExists (snapshot):
41+ writeFile (snapshot, output)
42+ checkpoint " Snapshot created: " & snapshot
43+ fail ()
44+ else :
45+ let expected = readFile (snapshot).normalizeHelp ()
46+ checkpoint " Cmd output: " & $ output.toBytes ()
47+ checkpoint " Snapshot: " & $ expected.toBytes ()
48+ check output == expected
49+
50+ const cmdFlags = " --verbosity:0 --hints:off -d:confutilsNoColors"
51+
3352proc cmdTest (cmdName: string , cmds = " " , help = " " ) =
3453 let fname = helpPath / cmdName
35- var build = " nim c --verbosity:0 --hints:off -d:confutilsNoColors "
54+ var build = " nim c " & cmdFlags
3655 if NimMajor < 2 :
3756 build.add " -d:nimOldCaseObjects"
3857 let buildRes = execCmdEx (build & " " & fname & " .nim" )
3958 if buildRes.exitCode != 0 :
4059 checkpoint " Build output: " & buildRes.output
4160 fail ()
4261 else :
43- let res = execCmdEx (fname & " " & cmds & " --help" & help)
44- let output = res.output.normalizeHelp ()
45- let snapshot = snapshotsPath / cmdName & cmds.cmdsToName () & help.helpToName () & " .txt"
46- if res.exitCode != 0 :
47- checkpoint " Run output: " & res.output
48- fail ()
49- elif not fileExists (snapshot):
50- writeFile (snapshot, output)
51- checkpoint " Snapshot created: " & snapshot
52- fail ()
53- else :
54- let expected = readFile (snapshot).normalizeHelp ()
55- checkpoint " Cmd output: " & $ output.toBytes ()
56- checkpoint " Snapshot: " & $ expected.toBytes ()
57- check output == expected
58-
59- suite " test --help" :
60- test " test test_nested_cmd" :
62+ execCmdTest (fname, cmdName, cmds, help)
63+
64+ suite " help message" :
65+ test " test_nested_cmd" :
6166 cmdTest (" test_nested_cmd" , " " )
6267
63- test " test test_nested_cmd lvl1Cmd1" :
68+ test " test_nested_cmd lvl1Cmd1" :
6469 cmdTest (" test_nested_cmd" , " lvl1Cmd1" )
6570
66- test " test test_nested_cmd lvl1Cmd1 lvl2Cmd2" :
71+ test " test_nested_cmd lvl1Cmd1 lvl2Cmd2" :
6772 cmdTest (" test_nested_cmd" , " lvl1Cmd1 lvl2Cmd2" )
6873
69- test " test test_argument" :
74+ test " test_argument" :
7075 cmdTest (" test_argument" , " " )
7176
72- test " test test_argument_abbr" :
77+ test " test_argument_abbr" :
7378 cmdTest (" test_argument_abbr" , " " )
7479
75- test " test test_default_value_desc" :
80+ test " test_default_value_desc" :
7681 cmdTest (" test_default_value_desc" , " " )
7782
78- test " test test_separator" :
83+ test " test_separator" :
7984 cmdTest (" test_separator" , " " )
8085
81- test " test test_longdesc" :
86+ test " test_longdesc" :
8287 cmdTest (" test_longdesc" , " " )
8388
84- test " test test_longdesc lvl1Cmd1" :
89+ test " test_longdesc lvl1Cmd1" :
8590 cmdTest (" test_longdesc" , " lvl1Cmd1" )
8691
87- test " test test_case_opt" :
92+ test " test_case_opt" :
8893 cmdTest (" test_case_opt" , " " )
8994
90- test " test test_case_opt cmdBlockProcessing" :
95+ test " test_case_opt cmdBlockProcessing" :
9196 cmdTest (" test_case_opt" , " cmdBlockProcessing" )
9297
93- test " test test_builtins" :
98+ test " test_builtins" :
9499 cmdTest (" test_builtins" , " " )
95100
96- test " test test_builtins lvl1Cmd1" :
101+ test " test_builtins lvl1Cmd1" :
97102 cmdTest (" test_builtins" , " lvl1Cmd1" )
98103
99- test " test test_debug --help" :
104+ test " test_debug --help" :
100105 cmdTest (" test_debug" , " " )
101106
102- test " test test_debug --help:debug" :
107+ test " test_debug --help:debug" :
103108 cmdTest (" test_debug" , " " , " :debug" )
104109
105- test " test test_debug lvl1Cmd1 --help:debug" :
110+ test " test_debug lvl1Cmd1 --help:debug" :
106111 cmdTest (" test_debug" , " lvl1Cmd1" , " :debug" )
107112
108- test " test test_dispatch" :
113+ test " test_dispatch" :
109114 cmdTest (" test_dispatch" , " " )
110115
111116 test " test test_default_cmd_desc" :
@@ -119,3 +124,9 @@ suite "test --help":
119124
120125 test " test test_multi_case_values" :
121126 cmdTest (" test_multi_case_values" )
127+
128+ test " nims test_cli_example" :
129+ execCmdTest (" nim " & cmdFlags & " " & helpPath / " test_cli_example.nims" , " test_cli_example_nims" )
130+
131+ test " nims test_cli_example" :
132+ execCmdTest (" nim e " & cmdFlags & " " & helpPath / " test_cli_example.nim" , " test_cli_example" )
0 commit comments