]> git.draconx.ca Git - dxcommon.git/blob - tests/functions.at
DX_C_ALIGNAS: Work around bash-5 parsing bug.
[dxcommon.git] / tests / functions.at
1 dnl Copyright © 2015, 2021-2024 Nick Bowler
2 dnl
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
6
7 AT_BANNER([Binary packing functions])
8
9 TEST_TAP_SIMPLE([signed unpacking], [packtests], [], [pack])
10 TEST_TAP_SIMPLE([unsigned unpacking], [packtestu], [], [pack])
11 TEST_TAP_SIMPLE([64-bit signed unpacking], [packtests64], [], [pack])
12 TEST_TAP_SIMPLE([64-bit unsigned unpacking], [packtestu64], [], [pack])
13
14 AT_BANNER([Help formatting functions])
15
16 AT_SETUP([help_print_desc])
17 AT_KEYWORDS([help])
18
19 AT_SKIP_IF([test ! -x "$builddir/t/helpdesc"])
20
21 AT_DATA([test.txt],
22 [[this is the first line
23 this is the second line
24 this is the third line
25 and so on
26 ]])
27
28 sed -e '5,$s/^/     /' -e '6,$s/^/     /' \
29   -e '10,$s/^/                    /' \
30   -e '13s/^ *//' -e '14,$s/^/          /' \
31   test.txt test.txt test.txt test.txt >expout
32
33 AT_CHECK(["$builddir/t/helpdesc" 0 0 10 5 30 20 40 40 <test.txt],
34   [0], [expout])
35
36 AT_CHECK([AS_ECHO_N(["no trailing newline"]) |
37   "$builddir/t/helpdesc" 0 0], [0],
38 [no trailing newline
39 ])
40
41 AT_CLEANUP
42
43 AT_SETUP([help_print_desc (empty description)])
44 AT_KEYWORDS([help])
45
46 AT_SKIP_IF([test ! -x "$builddir/t/helpdesc"])
47
48 AT_CHECK(["$builddir/t/helpdesc" 0 0 0 20 </dev/null], [0], [
49
50 ])
51 AT_CHECK(["$builddir/t/helpdesc" 1 20 </dev/null], [0], [
52 ])
53
54 AT_CLEANUP
55
56 AT_SETUP([help_print_optstring])
57 AT_KEYWORDS([help])
58
59 AT_DATA([expout],
60 [[ --foo        6
61  -b, --bar      10
62  --baz=ARG      10
63  -B, --baz=ARG  14
64  --quux[=ARG]   13
65  -q, --quux[=ARG]       17
66  --hello-this-is-a-very-long-option
67         0
68  --hello-this-is-a-very-long-option     35
69  --not-long     11
70  --flagged      10
71 ]])
72
73 # Some very old printf implementations return 0 on success instead of the
74 # number of bytes written.  The help_print_optstring function is not fully
75 # functional in this case.  It should fallback to printing a newline and
76 # returning 0 so the overall --help output should be mostly acceptable.
77 #
78 # We verify that this indeed works properly by adjusting the expected
79 # output accordingly, but ...
80 AS_IF(["$builddir/t/printfchk" >/dev/null], [ancient_printf=false],
81 [[sed -n -e 's/ [0-9]*$//' -e '/^ *-/p' -e 's/^ *-.*/   0/p' expout >expout.tmp
82 mv -f expout.tmp expout
83 ancient_printf=:]])
84
85 AT_CHECK([m4_join([ ],
86   ["$builddir/t/helpopt"],
87   [--foo],
88   [--bar -b],
89   [--baz ARG],
90   [--baz -B ARG],
91   [--quux '@<:@ARG@:>@'],
92   [--quux -q '@<:@ARG@:>@'],
93   [--hello-this-is-a-very-long-option 20],
94   [--hello-this-is-a-very-long-option 50],
95   [--not-long 12],
96   [--flagged -f \&])], [0], [expout])
97
98 # ... we ultimately skip the test so there's an indication (other than an
99 # outright failure) that the function is not working completely.
100 AT_SKIP_IF([$ancient_printf])
101
102 AT_CLEANUP
103
104 AT_SETUP([help_print_optstring (getopt_long_only)])
105 AT_KEYWORDS([help])
106
107 AT_DATA([expout],
108 [[ -foo 5
109  -bar   5
110  -baz ARG       9
111  -baz ARG       9
112  -quux [ARG]    12
113  -quux [ARG]    12
114  -hello-this-is-a-very-long-option
115         0
116  -hello-this-is-a-very-long-option      34
117  -not-long      10
118  -flagged       9
119 ]])
120
121 # Some very old printf implementations return 0 on success instead of the
122 # number of bytes written.  The help_print_optstring function is not fully
123 # functional in this case.  It should fallback to printing a newline and
124 # returning 0 so the overall --help output should be mostly acceptable.
125 #
126 # We verify that this indeed works properly by adjusting the expected
127 # output accordingly, but ...
128 AS_IF(["$builddir/t/printfchk" >/dev/null], [ancient_printf=false],
129 [[sed -n -e 's/ [0-9]*$//' -e '/^ *-/p' -e 's/^ *-.*/   0/p' expout >expout.tmp
130 mv -f expout.tmp expout
131 ancient_printf=:]])
132
133 AT_CHECK([m4_join([ ],
134   ["$builddir/t/helpopt2"],
135   [--foo],
136   [--bar -b],
137   [--baz ARG],
138   [--baz -B ARG],
139   [--quux '@<:@ARG@:>@'],
140   [--quux -q '@<:@ARG@:>@'],
141   [--hello-this-is-a-very-long-option 20],
142   [--hello-this-is-a-very-long-option 50],
143   [--not-long 12],
144   [--flagged -f \&])], [0], [expout])
145
146 # ... we ultimately skip the test so there's an indication (other than an
147 # outright failure) that the function is not working completely.
148 AT_SKIP_IF([$ancient_printf])
149
150 AT_CLEANUP
151
152 AT_SETUP([help_print_optstring (NLS fullwidth/halfwidth)])
153 AT_KEYWORDS([help nls])
154
155 AT_SKIP_IF([test ! -x "$builddir/t/helpopt3"])
156 TEST_UTF8_LOCALE([locale_utf8])
157
158 # Avoid some deficient shell parsers barfing on UTF-8 sequences by
159 # generating them this way using octal escapes.
160 $AWK 'BEGIN {
161   zenkaku = "--\345\205\250\350\247\222";
162   hankaku = "--\357\276\212\357\276\235\357\275\266\357\275\270"
163
164   print zenkaku, hankaku >"args"
165
166   print " " zenkaku "\t" "7"
167   print " " hankaku "\t" "7"
168 }' >expout </dev/null
169
170 AT_CHECK([LC_ALL=$locale_utf8 xargs "$builddir/t/helpopt3" <args],
171   [0], [expout])
172
173 AT_CLEANUP
174
175 AT_BANNER([Miscellaneous functions])
176
177 TEST_TAP_SIMPLE([copyright_symbol], [copysym], [], [])