]> git.draconx.ca Git - dxcommon.git/blob - tests/functions.at
cfd5408ee604775f35a593f3e9362bdbd4b1adf8
[dxcommon.git] / tests / functions.at
1 dnl Copyright © 2015, 2021-2022 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
36 AT_SKIP_IF([test ! -x "$builddir/t/helpdesc"])
37
38 AT_DATA([test.txt],
39 [[this is the first line
40 this is the second line
41 this is the third line
42 and so on
43 ]])
44
45 sed -e '5,$s/^/     /' -e '6,$s/^/     /' \
46   -e '10,$s/^/                    /' \
47   -e '13s/^ *//' -e '14,$s/^/          /' \
48   test.txt test.txt test.txt test.txt >expout
49
50 AT_CHECK(["$builddir/t/helpdesc" 0 0 10 5 30 20 40 40 <test.txt],
51   [0], [expout])
52
53 AT_CLEANUP
54
55 AT_SETUP([help_print_optstring])
56
57 AT_SKIP_IF([test ! -x "$builddir/t/helpopt"])
58
59 AT_CHECK([m4_join([ ],
60   ["$builddir/t/helpopt"],
61   [--foo],
62   [--bar -b],
63   [--baz ARG],
64   [--baz -B ARG],
65   [--quux '@<:@ARG@:>@'],
66   [--quux -q '@<:@ARG@:>@'],
67   [--hello-this-is-a-very-long-option 20],
68   [--hello-this-is-a-very-long-option 50],
69   [--not-long 12],
70   [--flagged -f \&])], [0],
71 [[  --foo       7
72   -b, --bar     11
73   --baz=ARG     11
74   -B, --baz=ARG 15
75   --quux[=ARG]  14
76   -q, --quux[=ARG]      18
77   --hello-this-is-a-very-long-option
78         0
79   --hello-this-is-a-very-long-option    36
80   --not-long    12
81   --flagged     11
82 ]])
83
84 AT_CLEANUP
85
86 AT_SETUP([help_print_optstring (getopt_long_only)])
87
88 AT_SKIP_IF([test ! -x "$builddir/t/helpopt2"])
89
90 AT_CHECK([m4_join([ ],
91   ["$builddir/t/helpopt2"],
92   [--foo],
93   [--bar -b],
94   [--baz ARG],
95   [--baz -B ARG],
96   [--quux '@<:@ARG@:>@'],
97   [--quux -q '@<:@ARG@:>@'],
98   [--hello-this-is-a-very-long-option 20],
99   [--hello-this-is-a-very-long-option 50],
100   [--not-long 12],
101   [--flagged -f \&])], [0],
102 [[  -foo        6
103   -bar  6
104   -baz ARG      10
105   -baz ARG      10
106   -quux [ARG]   13
107   -quux [ARG]   13
108   -hello-this-is-a-very-long-option
109         0
110   -hello-this-is-a-very-long-option     35
111   -not-long     11
112   -flagged      10
113 ]])
114
115 AT_CLEANUP