]> git.draconx.ca Git - dxcommon.git/blob - tests/functions.at
d2006df045889efac3ee51c6d5112fc7240c35ef
[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 m4_divert_push([PREPARE_TESTS])dnl
8 test_run_tap () {
9   "$builddir/t/$1" > "$1.tap"
10   status=$?
11   cat "$1.tap"
12   prove -e cat "$1.tap"
13   return $status
14 }
15 m4_divert_pop([PREPARE_TESTS])
16
17 m4_define([TEST_TAP], [AT_CHECK([test_run_tap "$1"], [0], [ignore])])
18 m4_define([TEST_TAP_SIMPLE], [dnl
19 AT_SETUP([$1])
20 AT_KEYWORDS([$4])dnl
21 m4_n([$3])dnl
22 TEST_TAP([$2])
23 AT_CLEANUP])
24
25 AT_BANNER([Binary packing functions])
26
27 TEST_TAP_SIMPLE([signed unpacking], [packtests], [], [pack])
28 TEST_TAP_SIMPLE([unsigned unpacking], [packtestu], [], [pack])
29 TEST_TAP_SIMPLE([64-bit signed unpacking], [packtests64], [], [pack])
30 TEST_TAP_SIMPLE([64-bit unsigned unpacking], [packtestu64], [], [pack])
31
32 AT_BANNER([Help formatting functions])
33
34 AT_SETUP([help_print_desc])
35 AT_KEYWORDS([help])
36
37 AT_SKIP_IF([test ! -x "$builddir/t/helpdesc"])
38
39 AT_DATA([test.txt],
40 [[this is the first line
41 this is the second line
42 this is the third line
43 and so on
44 ]])
45
46 sed -e '5,$s/^/     /' -e '6,$s/^/     /' \
47   -e '10,$s/^/                    /' \
48   -e '13s/^ *//' -e '14,$s/^/          /' \
49   test.txt test.txt test.txt test.txt >expout
50
51 AT_CHECK(["$builddir/t/helpdesc" 0 0 10 5 30 20 40 40 <test.txt],
52   [0], [expout])
53
54 AT_CLEANUP
55
56 AT_SETUP([help_print_desc (empty description)])
57 AT_KEYWORDS([help])
58
59 AT_SKIP_IF([test ! -x "$builddir/t/helpdesc"])
60
61 AT_CHECK(["$builddir/t/helpdesc" 0 0 0 20 </dev/null])
62 AT_CHECK(["$builddir/t/helpdesc" 1 20 </dev/null], [0], [
63 ])
64
65 AT_CLEANUP
66
67 AT_SETUP([help_print_optstring])
68 AT_KEYWORDS([help])
69
70 AT_SKIP_IF([test ! -x "$builddir/t/helpopt"])
71
72 AT_CHECK([m4_join([ ],
73   ["$builddir/t/helpopt"],
74   [--foo],
75   [--bar -b],
76   [--baz ARG],
77   [--baz -B ARG],
78   [--quux '@<:@ARG@:>@'],
79   [--quux -q '@<:@ARG@:>@'],
80   [--hello-this-is-a-very-long-option 20],
81   [--hello-this-is-a-very-long-option 50],
82   [--not-long 12],
83   [--flagged -f \&])], [0],
84 [[  --foo       7
85   -b, --bar     11
86   --baz=ARG     11
87   -B, --baz=ARG 15
88   --quux[=ARG]  14
89   -q, --quux[=ARG]      18
90   --hello-this-is-a-very-long-option
91         0
92   --hello-this-is-a-very-long-option    36
93   --not-long    12
94   --flagged     11
95 ]])
96
97 AT_CLEANUP
98
99 AT_SETUP([help_print_optstring (getopt_long_only)])
100 AT_KEYWORDS([help])
101
102 AT_SKIP_IF([test ! -x "$builddir/t/helpopt2"])
103
104 AT_CHECK([m4_join([ ],
105   ["$builddir/t/helpopt2"],
106   [--foo],
107   [--bar -b],
108   [--baz ARG],
109   [--baz -B ARG],
110   [--quux '@<:@ARG@:>@'],
111   [--quux -q '@<:@ARG@:>@'],
112   [--hello-this-is-a-very-long-option 20],
113   [--hello-this-is-a-very-long-option 50],
114   [--not-long 12],
115   [--flagged -f \&])], [0],
116 [[  -foo        6
117   -bar  6
118   -baz ARG      10
119   -baz ARG      10
120   -quux [ARG]   13
121   -quux [ARG]   13
122   -hello-this-is-a-very-long-option
123         0
124   -hello-this-is-a-very-long-option     35
125   -not-long     11
126   -flagged      10
127 ]])
128
129 AT_CLEANUP