]> git.draconx.ca Git - dxcommon.git/blob - tests/functions.at
help_print_desc: Simplify implementation.
[dxcommon.git] / tests / functions.at
1 dnl Copyright © 2015, 2021-2023 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_SKIP_IF([test ! -x "$builddir/t/helpopt"])
60
61 AT_CHECK([m4_join([ ],
62   ["$builddir/t/helpopt"],
63   [--foo],
64   [--bar -b],
65   [--baz ARG],
66   [--baz -B ARG],
67   [--quux '@<:@ARG@:>@'],
68   [--quux -q '@<:@ARG@:>@'],
69   [--hello-this-is-a-very-long-option 20],
70   [--hello-this-is-a-very-long-option 50],
71   [--not-long 12],
72   [--flagged -f \&])], [0],
73 [[  --foo       7
74   -b, --bar     11
75   --baz=ARG     11
76   -B, --baz=ARG 15
77   --quux[=ARG]  14
78   -q, --quux[=ARG]      18
79   --hello-this-is-a-very-long-option
80         0
81   --hello-this-is-a-very-long-option    36
82   --not-long    12
83   --flagged     11
84 ]])
85
86 AT_CLEANUP
87
88 AT_SETUP([help_print_optstring (getopt_long_only)])
89 AT_KEYWORDS([help])
90
91 AT_SKIP_IF([test ! -x "$builddir/t/helpopt2"])
92
93 AT_CHECK([m4_join([ ],
94   ["$builddir/t/helpopt2"],
95   [--foo],
96   [--bar -b],
97   [--baz ARG],
98   [--baz -B ARG],
99   [--quux '@<:@ARG@:>@'],
100   [--quux -q '@<:@ARG@:>@'],
101   [--hello-this-is-a-very-long-option 20],
102   [--hello-this-is-a-very-long-option 50],
103   [--not-long 12],
104   [--flagged -f \&])], [0],
105 [[  -foo        6
106   -bar  6
107   -baz ARG      10
108   -baz ARG      10
109   -quux [ARG]   13
110   -quux [ARG]   13
111   -hello-this-is-a-very-long-option
112         0
113   -hello-this-is-a-very-long-option     35
114   -not-long     11
115   -flagged      10
116 ]])
117
118 AT_CLEANUP
119
120 AT_SETUP([help_print_optstring (NLS fullwidth/halfwidth)])
121 AT_KEYWORDS([help nls])
122
123 AT_SKIP_IF([test ! -x "$builddir/t/helpopt3"])
124 TEST_UTF8_LOCALE([locale_utf8])
125
126 # Avoid some deficient shell parsers barfing on UTF-8 sequences by
127 # generating them this way using octal escapes.
128 $AWK -f - >expout <<'EOF'
129 BEGIN {
130   zenkaku = "--\345\205\250\350\247\222";
131   hankaku = "--\357\276\212\357\276\235\357\275\266\357\275\270"
132
133   print zenkaku, hankaku >"args"
134
135   print "  " zenkaku "\t" "8"
136   print "  " hankaku "\t" "8"
137 }
138 EOF
139
140 AT_CHECK([LC_ALL=$locale_utf8 xargs "$builddir/t/helpopt3" <args],
141   [0], [expout])
142
143 AT_CLEANUP
144
145 AT_BANNER([Miscellaneous functions])
146
147 TEST_TAP_SIMPLE([copyright_symbol], [copysym], [], [])