]> git.draconx.ca Git - dxcommon.git/blob - tests/functions.at
help: Add a single-dash long option mode.
[dxcommon.git] / tests / functions.at
1 dnl Copyright © 2015, 2021 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])], [0],
70 [[  --foo       7
71   -b, --bar     11
72   --baz=ARG     11
73   -B, --baz=ARG 15
74   --quux[=ARG]  14
75   -q, --quux[=ARG]      18
76   --hello-this-is-a-very-long-option
77         0
78   --hello-this-is-a-very-long-option    36
79   --not-long    12
80 ]])
81
82 AT_CLEANUP
83
84 AT_SETUP([help_print_optstring (getopt_long_only)])
85
86 AT_SKIP_IF([test ! -x "$builddir/t/helpopt2"])
87
88 AT_CHECK([m4_join([ ],
89   ["$builddir/t/helpopt2"],
90   [--foo],
91   [--bar -b],
92   [--baz ARG],
93   [--baz -B ARG],
94   [--quux '@<:@ARG@:>@'],
95   [--quux -q '@<:@ARG@:>@'],
96   [--hello-this-is-a-very-long-option 20],
97   [--hello-this-is-a-very-long-option 50],
98   [--not-long 12])], [0],
99 [[  -foo        6
100   -bar  6
101   -baz ARG      10
102   -baz ARG      10
103   -quux [ARG]   13
104   -quux [ARG]   13
105   -hello-this-is-a-very-long-option
106         0
107   -hello-this-is-a-very-long-option     35
108   -not-long     11
109 ]])
110
111 AT_CLEANUP