1 # Copyright © 2015, 2021-2024 Nick Bowler
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 AT_BANNER([Binary packing functions])
18 TEST_TAP_SIMPLE([signed unpacking], [packtests], [], [pack])
19 TEST_TAP_SIMPLE([unsigned unpacking], [packtestu], [], [pack])
20 TEST_TAP_SIMPLE([64-bit signed unpacking], [packtests64], [], [pack])
21 TEST_TAP_SIMPLE([64-bit unsigned unpacking], [packtestu64], [], [pack])
23 AT_BANNER([Help formatting functions])
25 AT_SETUP([help_print_desc])
28 AT_SKIP_IF([test ! -x "$builddir/t/helpdesc"])
31 [[this is the first line
32 this is the second line
33 this is the third line
37 sed -e '5,$s/^/ /' -e '6,$s/^/ /' \
39 -e '13s/^ *//' -e '14,$s/^/ /' \
40 test.txt test.txt test.txt test.txt >expout
42 AT_CHECK(["$builddir/t/helpdesc" 0 0 10 5 30 20 40 40 <test.txt],
45 AT_CHECK([AS_ECHO_N(["no trailing newline"]) |
46 "$builddir/t/helpdesc" 0 0], [0],
52 AT_SETUP([help_print_desc (empty description)])
55 AT_SKIP_IF([test ! -x "$builddir/t/helpdesc"])
57 AT_CHECK(["$builddir/t/helpdesc" 0 0 0 20 </dev/null], [0], [
60 AT_CHECK(["$builddir/t/helpdesc" 1 20 </dev/null], [0], [
65 AT_SETUP([help_print_optstring])
75 --hello-this-is-a-very-long-option
77 --hello-this-is-a-very-long-option 35
82 # Some very old printf implementations return 0 on success instead of the
83 # number of bytes written. The help_print_optstring function is not fully
84 # functional in this case. It should fallback to printing a newline and
85 # returning 0 so the overall --help output should be mostly acceptable.
87 # We verify that this indeed works properly by adjusting the expected
88 # output accordingly, but ...
89 AS_IF(["$builddir/t/printfchk" >/dev/null], [ancient_printf=false],
90 [[sed -n -e 's/ [0-9]*$//' -e '/^ *-/p' -e 's/^ *-.*/ 0/p' expout >expout.tmp
91 mv -f expout.tmp expout
94 AT_CHECK([m4_join([ ],
95 ["$builddir/t/helpopt"],
100 [--quux '@<:@ARG@:>@'],
101 [--quux -q '@<:@ARG@:>@'],
102 [--hello-this-is-a-very-long-option 20],
103 [--hello-this-is-a-very-long-option 50],
105 [--flagged -f \&])], [0], [expout])
107 # ... we ultimately skip the test so there's an indication (other than an
108 # outright failure) that the function is not working completely.
109 AT_SKIP_IF([$ancient_printf])
113 AT_SETUP([help_print_optstring (getopt_long_only)])
123 -hello-this-is-a-very-long-option
125 -hello-this-is-a-very-long-option 34
130 # Some very old printf implementations return 0 on success instead of the
131 # number of bytes written. The help_print_optstring function is not fully
132 # functional in this case. It should fallback to printing a newline and
133 # returning 0 so the overall --help output should be mostly acceptable.
135 # We verify that this indeed works properly by adjusting the expected
136 # output accordingly, but ...
137 AS_IF(["$builddir/t/printfchk" >/dev/null], [ancient_printf=false],
138 [[sed -n -e 's/ [0-9]*$//' -e '/^ *-/p' -e 's/^ *-.*/ 0/p' expout >expout.tmp
139 mv -f expout.tmp expout
142 AT_CHECK([m4_join([ ],
143 ["$builddir/t/helpopt2"],
148 [--quux '@<:@ARG@:>@'],
149 [--quux -q '@<:@ARG@:>@'],
150 [--hello-this-is-a-very-long-option 20],
151 [--hello-this-is-a-very-long-option 50],
153 [--flagged -f \&])], [0], [expout])
155 # ... we ultimately skip the test so there's an indication (other than an
156 # outright failure) that the function is not working completely.
157 AT_SKIP_IF([$ancient_printf])
161 AT_SETUP([help_print_optstring (NLS fullwidth/halfwidth)])
162 AT_KEYWORDS([help nls])
164 AT_SKIP_IF([test ! -x "$builddir/t/helpopt3"])
165 TEST_UTF8_LOCALE([locale_utf8])
167 # Avoid some deficient shell parsers barfing on UTF-8 sequences by
168 # generating them this way using octal escapes.
170 zenkaku = "--\345\205\250\350\247\222";
171 hankaku = "--\357\276\212\357\276\235\357\275\266\357\275\270"
173 print zenkaku, hankaku >"args"
175 print " " zenkaku "\t" "7"
176 print " " hankaku "\t" "7"
177 }' >expout </dev/null
179 AT_CHECK([LC_ALL=$locale_utf8 xargs "$builddir/t/helpopt3" <args],
184 AT_BANNER([Miscellaneous functions])
186 TEST_TAP_SIMPLE([copyright_symbol], [copysym], [], [])
187 TEST_TAP_SIMPLE([do_getline], [getline], [], [getline])
189 TEST_TAP_SIMPLE([gnu_getopt], [gnugetopt gnu],
190 [unset POSIXLY_CORRECT], [getopt_long getopt_long_only])
191 TEST_TAP_SIMPLE([gnu_getopt (POSIXLY_CORRECT)], [gnugetopt posix],
192 [export POSIXLY_CORRECT=1], [getopt_long getopt_long_only])