aboutsummaryrefslogtreecommitdiff
path: root/tests/help2adoc.sh
blob: 393c6a989e693a79e15e0144351efc1e64d0db6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/sh -e
# This test very exactly matches the output,
# but help2adoc is more or less feature-complete already.
self=$(realpath "$0")
help2adoc=$(realpath "$(dirname "$0")/../tools/help2adoc.awk")

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

test_oneline_help() {
cat <<END
Usage: $self [--brightness [+-]BRIGHTNESS] [--input NAME] [--restart]
END
}

test_oneline_version() {
cat <<'END'
eizoctl 1.0
END
}

test_oneline_out() {
cat <<'END'
eizoctl(1)
==========
:doctype: manpage
:manmanual: eizoctl Manual
:mansource: eizoctl 1.0

Name
----
eizoctl - manual page for eizoctl 1.0

Synopsis
--------
*eizoctl* [**--brightness** [+-]__BRIGHTNESS__] [**--input** __NAME__] [**--restart**]
END
}

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

test_simple_help() {
cat <<'END'
Usage: elksmart-comm [OPTION]... [COMMAND...]
Usage: elksmart-comm
Transmit or receive infrared commands.

  -d, --debug                 elksmart-comm will run in debug mode
 -f, --frequency HZ          frequency (38000 Hz by default)
   -n, --nec                   use the NEC transmission format
  -h, --help                  display this help and exit
 -V, --version               output version information and exit
END
}

test_simple_version() {
cat <<'END'
elksmart-comm (usb-drivers) dev
END
}

test_simple_out() {
cat <<'END'
elksmart-comm(1)
================
:doctype: manpage
:manmanual: elksmart-comm Manual
:mansource: usb-drivers dev

Name
----
elksmart-comm - manual page for elksmart-comm dev

Synopsis
--------
*elksmart-comm* [__OPTION__]... [__COMMAND__...]

*elksmart-comm*


Description
-----------
Transmit or receive infrared commands.


*-d*, **--debug**::
	**elksmart-comm** will run in debug mode

*-f*, **--frequency** __HZ__::
	frequency (38000 Hz by default)

*-n*, **--nec**::
	use the NEC transmission format

*-h*, **--help**::
	display this help and exit

*-V*, **--version**::
	output version information and exit
END
}

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

test_wild_help() {
cat <<'END'
Usage:
 wild [option]… <command>… — Be wild
What's happening?
  -f, --frequency hz-2-foo  frequency to --foo at
      --foo=bar
  Foobar.
  Boo far.

 Subsection:
  --help
  --version
  Oh my.

Major section:
And now for something completely different.
  Very wild
END
}

test_wild_version() {
cat <<'END'
wild 1
Copies left and right.
END
}

test_wild_out() {
cat <<'END'
wild(1)
=======
:doctype: manpage
:manmanual: wild Manual
:mansource: wild 1

Name
----
wild - manual page for wild 1

Synopsis
--------
*wild* [__option__]... <__command__>...


Description
-----------
Be **wild**

What's happening?

*-f*, **--frequency** __hz-2-foo__::
	frequency to **--foo** at

*--foo*=__bar__::
	Foobar.
	Boo far.


Subsection
~~~~~~~~~~

*--help*::

*--version*::
	Oh my.


Major section
-------------
And now for something completely different.
  Very wild
END
}

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

run() {
	echo "-- help2adoc/$1"
	local selfquoted=$(echo "$self" | sed 's/\\/&&/g')
	local output=$(TEST=$1 awk -f "$help2adoc" -v Target="$selfquoted")
	local expect="$($1_out)"
	if [ "$output" = "$expect" ]
	then return
	fi

	echo "== Expected"
	sed 's/^/   /' <<-END
	$expect
	END
	echo "== Received"
	sed 's/^/   /' <<-END
	$output
	END
	exit 1
}

if [ -z "$TEST" ]
then
	run test_oneline
	run test_simple
	run test_wild
	echo "-- OK"
elif [ "$1" = "--help" ]
then ${TEST}_help
elif [ "$1" = "--version" ]
then ${TEST}_version
else
	echo "Wrong usage"
	exit 1
fi