@@ -5,8 +5,18 @@ load ../environment
55TEST_COMMAND_SCRIPT_PATH=" $TEST_GO_SCRIPTS_DIR /test-command"
66
77setup () {
8- . ' lib/internal/command_descriptions'
8+ test_filter
9+
10+ @go.create_test_go_script \
11+ " . '$_GO_CORE_DIR /lib/internal/command_descriptions'" \
12+ ' declare __go_cmd_desc=""' \
13+ ' "$@"' \
14+ ' declare result="$?"' \
15+ ' printf "%s\n" "$__go_cmd_desc"' \
16+ ' exit "$result"'
17+ }
918
19+ create_script_with_description () {
1020 local script=' #
1121# Command that does something in {{root}}
1222#
@@ -51,14 +61,14 @@ teardown() {
5161
5262@test " $SUITE : return error if there's an error reading" {
5363 skip_if_cannot_trigger_file_permission_failure
64+ printf ' \n' > " $TEST_COMMAND_SCRIPT_PATH "
5465 chmod ugo-r " $TEST_COMMAND_SCRIPT_PATH "
5566
56- run _@go.command_summary " $TEST_COMMAND_SCRIPT_PATH "
67+ run " $TEST_GO_SCRIPT " _@go.command_summary " $TEST_COMMAND_SCRIPT_PATH "
5768 assert_failure
5869 assert_output_matches " ERROR: problem reading $TEST_COMMAND_SCRIPT_PATH \$ "
5970
60- output=' '
61- run _@go.command_description " $TEST_COMMAND_SCRIPT_PATH "
71+ run " $TEST_GO_SCRIPT " _@go.command_description " $TEST_COMMAND_SCRIPT_PATH "
6272 assert_failure
6373 assert_output_matches " ERROR: problem reading $TEST_COMMAND_SCRIPT_PATH \$ "
6474}
@@ -67,39 +77,32 @@ teardown() {
6777 @go.create_test_command_script ' test-command' \
6878 ' echo "This script has no description"'
6979
70- local __go_cmd_desc=' '
71- _@go.command_summary " $TEST_COMMAND_SCRIPT_PATH "
72- assert_equal ' No description available' " $__go_cmd_desc " ' command summary'
80+ run " $TEST_GO_SCRIPT " _@go.command_summary " $TEST_COMMAND_SCRIPT_PATH "
81+ assert_success ' No description available'
7382
7483 __go_cmd_desc=' '
75- _@go.command_description " $TEST_COMMAND_SCRIPT_PATH "
76- assert_equal ' No description available' " $__go_cmd_desc " ' command description '
84+ run " $TEST_GO_SCRIPT " _@go.command_description " $TEST_COMMAND_SCRIPT_PATH "
85+ assert_success ' No description available'
7786}
7887
7988@test " $SUITE : parse summary from command script" {
80- _GO_ROOTDIR=' /foo/bar'
81- _@go.command_summary " $TEST_COMMAND_SCRIPT_PATH "
82- assert_equal ' Command that does something in /foo/bar' " $__go_cmd_desc " \
83- ' command summary'
89+ create_script_with_description
90+ run " $TEST_GO_SCRIPT " _@go.command_summary " $TEST_COMMAND_SCRIPT_PATH "
91+ assert_success " Command that does something in $TEST_GO_ROOTDIR "
8492}
8593
8694@test " $SUITE : one-line description from command script has no trailing space" {
8795 echo ' # Command that does something in {{root}}' > " $TEST_COMMAND_SCRIPT_PATH "
88- _GO_ROOTDIR=' /foo/bar'
89- COLUMNS=40
90-
91- _@go.command_description " $TEST_COMMAND_SCRIPT_PATH "
92- assert_equal ' Command that does something in /foo/bar' " $__go_cmd_desc " \
93- ' one-line command description'
96+ COLUMNS=40 run " $TEST_GO_SCRIPT " _@go.command_description \
97+ " $TEST_COMMAND_SCRIPT_PATH "
98+ assert_success " Command that does something in $TEST_GO_ROOTDIR "
9499}
95100
96101@test " $SUITE : parse description from command script" {
97- _GO_CMD=' test-go'
98- _GO_ROOTDIR=' /foo/bar'
99- COLUMNS=40
100- _@go.command_description " $TEST_COMMAND_SCRIPT_PATH "
102+ create_script_with_description
103+ COLUMNS=40 run test-go _@go.command_description " $TEST_COMMAND_SCRIPT_PATH "
101104
102- local expected=' Command that does something in /foo/bar
105+ local expected=' Command that does something in TEST_GO_ROOTDIR
103106
104107Usage: test-go test-command [args...]
105108
@@ -125,13 +128,12 @@ Indented lines that look like tables (there are two or more adjacent spaces afte
125128 xyzzy all work and no play makes
126129 mike a Dull Boy.
127130 plugh all werk and no play makes
128- mike a dull Boy
129- '
131+ mike a dull Boy'
130132
131133 # With this test, I learned that you _do_ have to quote strings even inside of
132134 # '[[' and ']]' in case the strings themselves contain '[' or ']', as with
133135 # '[args...]' above.
134- assert_equal " $expected " " $__go_cmd_desc " ' command description '
136+ assert_success " ${ expected/ TEST_GO_ROOTDIR / $TEST_GO_ROOTDIR } "
135137}
136138
137139@test " $SUITE : format subcommand description" {
@@ -144,15 +146,9 @@ Indented lines that look like tables (there are two or more adjacent spaces afte
144146echo The command script starts now.
145147'
146148
147- local _GO_CMD=' test-go'
148- local expected=(" Leaf command that does something in $_GO_ROOTDIR "
149- ' '
150- " Usage: $_GO_CMD root-command node-command leaf-command [args...]"
151- ' ' )
152- local __go_cmd_desc
153- _@go.command_description \
149+ run test-go _@go.command_description \
154150 " $TEST_GO_SCRIPTS_DIR /root-command.d/node-command.d/leaf-command"
155-
156- local IFS= $' \n '
157- assert_equal " ${expected[*]} " " $__go_cmd_desc "
151+ assert_success " Leaf command that does something in $TEST_GO_ROOTDIR " \
152+ ' ' \
153+ " Usage: test-go root-command node-command leaf-command [args...] "
158154}
0 commit comments